Problem with Custom actions

class ActionWelcomeWithName(Action):

    def name(self) -> Text:
        return "action_welcome_with_name"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        # dispatcher.utter_message("Hello World!")
        import requests
        print("blavlcelalc;ala;l;")
        fb_access_token  = ""
        
        most_recent_state = tracker.current_state()
        sender_id = most_recent_state['sender_id']
        print("DEBUG: ", sender_id)
		
        fb_graph_api_request = requests.get('https://graph.facebook.com/v3.3/me?fields=first_name,last_name&access_token={}'.format(fb_access_token)).json()
		
        first_name = fb_graph_api_request['first_name']
		
        last_name = fb_graph_api_request['last_name']
		
	    
        return [SlotSet('name', first_name), SlotSet('surname', last_name)]

Hi all! I’m trying to do a chatbot on facebok messenger.So I want to send the user a welcome message containing his surname and name. However, while running the code, I get this error: Encountered an exception while running action ‘action_welcome_with_name’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.

I try to add an endpoint: http://localhost:5055/webhooks. But this didn’t solve the problem and I get now this error along side with the last one: Failed to run custom action ‘action_welcome_with_name’. Couldn’t connect to the server at ‘http://localhost:5055/webhooks’. Is the server running? Error: Cannot connect to host localhost:5055 ssl:None [Connection refused]

My guest is that it is the endpoint which is not properly set. But I’m wondering which endpoint from facebook I need to specify there in other for the action to take place ?

Can Anyone help please ? Quiet new to rasa.

Hi @Rogers_ntr, i would suggest testing your bot locally before trying to deploy it on facebook. It looks like in this case

Couldn’t connect to the server at ‘http://localhost:5055/webhooks’. Is the server running?

You’re not running your action server. You can run the action server with rasa run actions.

Did you connect your bot as described here Messaging and Voice Channels ? If so, then you can also send messages to the user by doing dispatcher.utter_message("Hello World!") instead of doing the web request.

Thanks all for your reply. I already solved the problem. It was not configuring the proper webhook plus The action server was not running.

Thanks anyway.

2020-01-27 15:26:51 DEBUG rasa.core.processor - Predicted next action ‘action_welcome_with_name’ with confidence 1.00. 2020-01-27 15:26:51 DEBUG rasa.core.actions.action - Calling action endpoint to run action ‘action_welcome_with_name’. 2020-01-27 15:26:52 ERROR rasa.core.processor - Encountered an exception while running action ‘action_welcome_with_name’. Bot will continue, but he actions events are lost. Please check the logs of your action server for more information. 2020-01-27 15:26:52 DEBUG rasa.core.processor - Failed to execute custom action. Traceback (most recent call last): File “c:\users\administrator\documents\gbl_x_rasa_core\rasa\core\actions\action.py”, line 451, in run json=json_body, method=“post”, timeout=DEFAULT_REQUEST_TIMEOUT File “C:\Users\Administrator\Anaconda3\envs\rasa\lib\asyncio\coroutines.py”, line 110, in next return self.gen.send(None) File “c:\users\administrator\documents\gbl_x_rasa_core\rasa\utils\endpoints.py”, line 148, in request resp.status, resp.reason, await resp.content.read() rasa.utils.endpoints.ClientResponseError: 500, Internal Server Error, body=‘b’\n

Internal Server Error

\n

\n The server encou tered an internal error and cannot complete\n your request.\n

\n’’

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File “c:\users\administrator\documents\gbl_x_rasa_core\rasa\core\processor.py”, line 502, in _run_action events = await action.run(output_channel, nlg, tracker, self.domain) File “C:\Users\Administrator\Anaconda3\envs\rasa\lib\asyncio\coroutines.py”, line 110, in next return self.gen.send(None) File “c:\users\administrator\documents\gbl_x_rasa_core\rasa\core\actions\action.py”, line 474, in run raise Exception(“Failed to execute custom action.”) from e Exception: Failed to execute custom action. 2020-01-27 15:26:52 DEBUG rasa.core.processor - Action ‘action_welcome_with_name’ ended with events ‘[]’ 2020-01-27 15:26:52 DEBUG rasa.core.processor - Current slot values: data: None name: None surname: None

I got this error

can you share yours domain and stories file for this action

Insted of returning firstname and lastname to slots is okay to use it in this way>

r = requests.get(
                'https://graph.facebook.com/{}?fields=first_name,last_name,profile_pic&access_token={}'.format(
                    sender_id, access_token)).json()
            first_name = r['first_name']
            last_name = r['last_name']

dispatcher.utter_message("Hey " + first_name + " " + last_name +"!  I’m Rick")