Skip to content

Instantly share code, notes, and snippets.

@itsromiljain
Created April 1, 2019 04:16
Show Gist options
  • Select an option

  • Save itsromiljain/5df7f01c8c3586cadcd5056621608368 to your computer and use it in GitHub Desktop.

Select an option

Save itsromiljain/5df7f01c8c3586cadcd5056621608368 to your computer and use it in GitHub Desktop.
Action file to define Custom Actions
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