I have a rasa bot which is trying to extract data out of an API using a custom action. I had a simple custom action working where there was only one API link which it extracted data from and used the entity to filter and find the correct data I wanted extracted from that API.
Here is what it looks like:
class ActionCorona(Action):
def name(self) -> Text:
return "action_covid"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
response = requests.get("https://api.apify.com/v2/key-value-stores/tVaYRsPHLjNdNBu7S/records/LATEST?disableRedirect=true").json()
entities = tracker.latest_message['entities']
print("Last Message now ", entities)
state = None
for e in entities:
if e['entity'] == "country":
country = e['value']
message = "Please enter a valid country"
for data in response:
if data["country"] == country.title():
print(data)
message = country.title() + " Infected: "+ str(data["infected"]) + " Recovered: " + str(data["recovered"]) + " Dead: " + str(data["deceased"])
print(message)
dispatcher.utter_message(message)
return []
What I want to do now is that I am trying to use a different API Link where the link filters by the country, so for example if the link is (EXAMPLE LINK, IT IS NOT REAL):
api.covidtracker.com/api/country-filter/Germany
If you were to change Germany to another country then it would show the api with the data for that country only. So I want to know is there some line of code I can add to replace that section of the URL to place into the custom action?