Custome action with api - Rasa Open Source - Rasa Community Forum

Custome action with api

post by sunilskn on Jul 19, 2019

while executing I am getting error, I am not getting where is the problem

post by tyd on Jul 19, 2019

Hi @sunilskn! If you have not stood up your action server, you will want to do that. Make sure to run pip install rasa-sdk, if you have not already done this. Then, please make sure you have specified in endpoints.yml that your action server uses:

action_endpoint:
  url: "http://localhost:5055/webhook"

Finally, you can run rasa run actions in a separate window, while you are running rasa. You will find more information here and here. Please let me know if this did not solve your issue!

post by sunilskn on Jul 19, 2019

Thanks, I will try it

post by sunilskn on Jul 19, 2019

still I am facing the same problem

post by tyd on Jul 19, 2019

@sunilskn Can you share the code for your action?

post by sunilskn on Jul 19, 2019

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet

class ActionWeather(Action):
    def name(self):
        return 'action_weather'

def run(self, dispatcher, tracker, domain):
        from apixu.client import ApixuClient
        api_key = 'c114ca4223754c68bc583834191907' #your apixu key
        client = ApixuClient(api_key)

loc = tracker.get_slot('location')
        current = client.getcurrent(q=loc)

country = current['location']['country']
        city = current['location']['name']
        condition = current['current']['condition']['text']
        temperature_c = current['current']['temp_c']
        humidity = current['current']['humidity']
        wind_mph = current['current']['wind_mph']

response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph)

dispatcher.utter_message(response)

return [SlotSet('location', loc)]

post by sunilskn on Jul 19, 2019

when I run the custom action in the server I am getting error

post by tyd on Jul 19, 2019

@sunilskn The forums are public, so you might want to remove your api_key.

I figured out the issue. The ApixuClient has changed their method for getting the current weather. If you change current = client.getcurrent(q=loc) to current = client.current(q=loc), it works!

post by sunilskn on Jul 23, 2019

Thank you so much it is working now