How can i integrate zomato api with my bot through actions.py file

rasa-core

(Srinivasan.S) #1

hi i am ajay, currently i am creating restaurant bot and i am using zomato api key to fetch the restaurant details, but i don’t know how to integrate the zomato api key in my actions.py file. when i try to run the bot in terminal it shows,

Failed to run custom action ‘action_search_restaurants’. Couldn’t connect to the server at ‘http://localhost:5055/webhook’. Is the server running? Error: HTTPConnectionPool(host=‘localhost’, port=5055): Max retries exceeded with url: /webhook (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x0000019DAD4ABB70>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it’,)) ERROR rasa_core.processor - Encountered an exception while running action ‘action_search_restaurants’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code. ERROR rasa_core.processor - Failed to execute custom action.

“Failed to establish a new connection: %s” % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000019DAD4ABB70>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it

and this is actions.py file

import logging

import requests

import json

from rasa_core_sdk import Action

from rasa_core_sdk.forms import FormAction

logger = logging.getLogger(name)

from rasa_core_sdk.events import SlotSet

from zomathon import ZomatoAPI

import pyzomato

Key = ‘ZomatoAPI-key’

url = (“https://developers.zomato.com/api/v2.1/search?entity_id=1&entity_type=city&q=new%20delhi&count=4&lat=34&lon=45&radius=56&sort=cost&order=asc”)

class ActionSearchRestaurants(Action):

if __name__ == '__main__':  
    r = requests.get(url, headers={'user-key':"ZomatoAPI-key"})
    data = r.json()
    print (data)

def name(self):
    return 'action_search_restaurants'

def run(self, dispatcher, tracker, domain):    
    dispatcher.utter_message("i want a italian restaurant") 
    zomato_api = ZomatoAPI("ZomatoAPI-key")
    z = zomato_api.search(tracker.get_slot("cuisine"))
    return[SlotSet("matches",z)]

(Srikar Vuppalanchi) #2

Can you check if your actions server is running? Also, can you check if the API is fetching data by using postman or something similar?