# Problem with Custom actions

**URL:** <https://forum.rasa.com/t/problem-with-custom-actions/10201>\
**Category:** Rasa Open Source\
**Created:** [May 23, 2019, 2:39am UTC](https://forum.rasa.com/t/problem-with-custom-actions/10201 "2019-05-23T02:39:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rogers\_ntr](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rogers_ntr/32/3067_2.png) [@Rogers\_ntr](https://forum.rasa.com/u/Rogers_ntr)\
**Post date:** [May 23, 2019, 2:39am UTC](https://forum.rasa.com/t/problem-with-custom-actions/10201/1 "2019-05-23T02:39:45Z")

</div>

```
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](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](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.

---

<div class="post-metadata">

**Author:** ![erohmensing](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/erohmensing/32/1789_2.png) [@erohmensing](https://forum.rasa.com/u/erohmensing)\
**Post date:** [June 18, 2019, 10:38pm UTC](https://forum.rasa.com/t/problem-with-custom-actions/10201/2 "2019-06-18T22:38:32Z")

</div>

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’](http://localhost:5055/webhooks%E2%80%99). Is the server running?_

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

---

<div class="post-metadata">

**Author:** ![Tobias\_Wochinger](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/tobias_wochinger/32/4580_2.png) [@Tobias\_Wochinger](https://forum.rasa.com/u/Tobias_Wochinger)\
**Post date:** [June 18, 2019, 11:05pm UTC](https://forum.rasa.com/t/problem-with-custom-actions/10201/3 "2019-06-18T23:05:20Z")

</div>

Did you connect your bot as described here [Messaging and Voice Channels](https://rasa.com/docs/rasa/user-guide/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.

---

<div class="post-metadata">

**Author:** ![Rogers\_ntr](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rogers_ntr/32/3067_2.png) [@Rogers\_ntr](https://forum.rasa.com/u/Rogers_ntr)\
**Post date:** [June 19, 2019, 12:47am UTC](https://forum.rasa.com/t/problem-with-custom-actions/10201/4 "2019-06-19T00:47:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rishier827](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rishier827/32/6957_2.png) [@rishier827](https://forum.rasa.com/u/rishier827)\
**Post date:** [January 27, 2020, 9:58am UTC](https://forum.rasa.com/t/problem-with-custom-actions/10201/5 "2020-01-27T09:58:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rishier827](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rishier827/32/6957_2.png) [@rishier827](https://forum.rasa.com/u/rishier827)\
**Post date:** [January 27, 2020, 11:51am UTC](https://forum.rasa.com/t/problem-with-custom-actions/10201/6 "2020-01-27T11:51:49Z")

</div>

can you share yours domain and stories file for this action

---

<div class="post-metadata">

**Author:** ![rishier827](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rishier827/32/6957_2.png) [@rishier827](https://forum.rasa.com/u/rishier827)\
**Post date:** [January 29, 2020, 5:59am UTC](https://forum.rasa.com/t/problem-with-custom-actions/10201/7 "2020-01-29T05:59:03Z")

</div>

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")
```
