Created
April 1, 2019 04:16
-
-
Save itsromiljain/5df7f01c8c3586cadcd5056621608368 to your computer and use it in GitHub Desktop.
Action file to define Custom Actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from rasa_core_sdk import Action | |
| import requests | |
| import json | |
| class ActionGetNewst(Action): | |
| def name(self): | |
| return 'action_get_news' | |
| def run(self, dispatcher, tracker, domain): | |
| category = tracker.get_slot('category') | |
| print(category) | |
| url = 'https://api.nytimes.com/svc/news/v3/content/all/{category}.json'.format(category=category) | |
| params = {'api-key': "YwFABCbVPDGGaM7aNgXuPdlPt2DuEK6I", 'limit': 5} | |
| response = requests.get(url, params).text | |
| json_data = json.loads(response)['results'] | |
| i = 0 | |
| for results in json_data: | |
| i = i+1 | |
| message = str(i) + "." + results['abstract'] | |
| dispatcher.utter_message(message) | |
| return[] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment