-
-
Notifications
You must be signed in to change notification settings - Fork 5
6. API Connectivity
Abhishek Kumar Srivastava edited this page Dec 18, 2023
·
1 revision
To integrate any logical operations in rasa, we need to use Actions.py file
Here we are using open Api's https://apisetu.gov.in/directory/api/cowin/
- Create a new file main.py and paste below code, i was making a Get call here using Lattitude and Longitude values passed by the user in Bot.
import requests
def Dose_Availability_Lon_Lat(Lattitude,Longitude):
api="https://cdn-api.co-vin.in/api/v2/appointment/centers/public/findByLatLong?lat={}&long={}".format(Lattitude,Longitude)
return main_task(api)
def main_task(api):
response=requests.get(api)
data=response.json()['centers']
output="*"*30
# print(data)
for area in data:
output+=" Hospital Name:" + area['name'] + "*"*30 +"\n"
output+='''\
pincode: {}
state_name: {}
district_name : {}
block_name : {}
'''.format(area['pincode'],area['state_name'],area['district_name',
area['block_name'])
output+="*"*30
return output
User input Values are stored using Slots.
with Domain.yml you can able to see Slots as Longitude and Lattitude
slots:
lattitude:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
longitude:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
and the connection between slots and the actions.py was done in stories.yml and rules.yml
- rule: Activate location form
steps:
- intent: location
- action: slot_location_form
- active_loop: slot_location_form
- rule: Submit location form
condition:
# Condition that form is active.
- active_loop: slot_location_form
steps:
# Form is deactivated
- action: slot_location_form
- active_loop: null
- slot_was_set:
- requested_slot: null
# The actions we want to run when the form is submitted.
- action: action_location_submit
after connecting all the things you need to train the Bot again
rasa train
to run actions.py you need to run actions command in seperate terminal
rasa run actions