# Handing off to human on Slack

**URL:** <https://forum.rasa.com/t/handing-off-to-human-on-slack/26203>\
**Category:** Rasa Open Source\
**Created:** [March 17, 2020, 1:13pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203 "2020-03-17T13:13:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mia.le0711](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mia.le0711/32/11297_2.png) [@mia.le0711](https://forum.rasa.com/u/mia.le0711)\
**Post date:** [March 17, 2020, 1:13pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/1 "2020-03-17T13:13:14Z")

</div>

Hi everyone!

I saw this documentation about [Handing off to a human agent](https://rasa.com/docs/rasa/dialogue-elements/guiding-users/#handing-off-to-a-human), however it is not very clear. I wonder if anyone knows how to custom this action so that it sends a Slack message to a “live agent”, in this case, me?

Thanks in advance!

BR,

Mia

---

<div class="post-metadata">

**Author:** ![nbeuchat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nbeuchat/32/13688_2.png) [@nbeuchat](https://forum.rasa.com/u/nbeuchat)\
**Post date:** [March 17, 2020, 2:33pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/2 "2020-03-17T14:33:41Z")

</div>

Hi @mia.le0711! I actually implemented something like that last week 🙂

I created a custom action that:

- dispatch a message to the user that it is struggling and will handover to a human
- sends a message in a Slack channel with some information about the issue
- pause the bot by returning the `ConversationPaused()` event

On Slack, you need to create an App and get your credentials. I gave it permission to post in any channel but that’s up to you.

Using the Slack v1 API (it will be different if you use v2), I did something like:

```auto
response = client_slack.api_call(
    "chat.postMessage", 
    channel="#support", 
    text=f"@botsupport user {tracker.sender_id}" is struggling! Please take over", 
    link_names=1 
)

```

Note that the `link_ǹames` is here because I am tagging a group of users in the text with `@botsupport` (this does not work with direct mention of a user, only groups)

Finally, as mentioned in the doc you linked, I added a trigger on a specific intent to trigger this handover action. I also do something like that if the bot struggles several time in a row.

Hope this helps!! Nicolas

---

<div class="post-metadata">

**Author:** ![mia.le0711](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mia.le0711/32/11297_2.png) [@mia.le0711](https://forum.rasa.com/u/mia.le0711)\
**Post date:** [March 17, 2020, 4:10pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/3 "2020-03-17T16:10:28Z")

</div>

Hi Nicolas!

Thank you so much for your answer, after taking a look at some other documents, I made it to work! One small problem though, I cannot get the User ID who needed help 😔😔 As I understqand, tracker.sender\_id will help? However it cannot seem to work for me. Can you help me with this? 😇

Again, I really appreciate your help!

---

<div class="post-metadata">

**Author:** ![mia.le0711](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mia.le0711/32/11297_2.png) [@mia.le0711](https://forum.rasa.com/u/mia.le0711)\
**Post date:** [March 17, 2020, 4:23pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/4 "2020-03-17T16:23:03Z")

</div>

@nbeuchat I made it work, hehe… But now it is in UserID and not Username:speak\_no\_evil: Do you know how to turn it into name instead? 😊

---

<div class="post-metadata">

**Author:** ![nbeuchat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nbeuchat/32/13688_2.png) [@nbeuchat](https://forum.rasa.com/u/nbeuchat)\
**Post date:** [March 17, 2020, 8:31pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/5 "2020-03-17T20:31:05Z")

</div>

Great you could make it work! How do you normally know the name of the user in your conversation? We do that through slots so in your action, you can simply do something like:

`tracjer.get_slot("user_name")` or whatever slot you stored your name in!

---

<div class="post-metadata">

**Author:** ![mia.le0711](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mia.le0711/32/11297_2.png) [@mia.le0711](https://forum.rasa.com/u/mia.le0711)\
**Post date:** [March 17, 2020, 8:41pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/6 "2020-03-17T20:41:23Z")

</div>

My chatbot is an educational one (FAQ) so it does not ask for names during conversation. I have been googling around for a solution to “translate” Slack ID to Slack username. But haven’t found any 😖

I guess I will have to think of the other way haha. Thank you so much again for your kind help. 😇

---

<div class="post-metadata">

**Author:** ![nbeuchat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nbeuchat/32/13688_2.png) [@nbeuchat](https://forum.rasa.com/u/nbeuchat)\
**Post date:** [March 17, 2020, 10:33pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/7 "2020-03-17T22:33:06Z")

</div>

Got it! No idea how to do that, maybe open another question in this forum to get more attention on that specific issue?

Cheers Nicolas

---

<div class="post-metadata">

**Author:** ![mia.le0711](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mia.le0711/32/11297_2.png) [@mia.le0711](https://forum.rasa.com/u/mia.le0711)\
**Post date:** [March 18, 2020, 7:45am UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/8 "2020-03-18T07:45:15Z")

</div>

I figured it out, even though it’s a bit too manual hehe but considering the small team I have now, I think it’s fine. I made a dictionary with user ID and Username, then assign the value to the user ID in the message sent. I type here so that if others have the same problem they can have a solution right away! 🙂

Thanks again @nbeuchat 😊

---

<div class="post-metadata">

**Author:** ![k1m](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/k1m/32/8518_2.png) [@k1m](https://forum.rasa.com/u/k1m)\
**Post date:** [April 14, 2020, 2:18pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/9 "2020-04-14T14:18:18Z")

</div>

This sound like a great solution to do human handoff.

Now it will just pause the conversation and send a message to slack, so that’s why i’m asking if @nbeuchat or @mia.le0711 created a feature to:

1. Receive users messages to slack after conversation is paused
2. Send a message to user from slack

And i guess the conversation will end when human sends a keyword from slack and then bot continues?

---

<div class="post-metadata">

**Author:** ![mia.le0711](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mia.le0711/32/11297_2.png) [@mia.le0711](https://forum.rasa.com/u/mia.le0711)\
**Post date:** [April 14, 2020, 2:23pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/10 "2020-04-14T14:23:05Z")

</div>

Hi Kim,

I’m sorry I don’t quite understand your question. Can you please specify a bit more? 🙂

---

<div class="post-metadata">

**Author:** ![KhalidBentaleb](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/khalidbentaleb/32/7629_2.png) [@KhalidBentaleb](https://forum.rasa.com/u/KhalidBentaleb)\
**Post date:** [April 20, 2020, 5:34pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/12 "2020-04-20T17:34:46Z")

</div>

hey @mia.le0711 and @nbeuchat

can you show me your custom actions and how it sends a slack message to a human ?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![nbeuchat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nbeuchat/32/13688_2.png) [@nbeuchat](https://forum.rasa.com/u/nbeuchat)\
**Post date:** [April 20, 2020, 5:44pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/13 "2020-04-20T17:44:37Z")

</div>

Hey @KhalidBentaleb, sure, have a look! I simplified it a bit as we have quite some code specific to our use case just to generate the right message for our customer support team.

I am using the slack client 1.3 (`slackclient~=1.3`) as I had issues with version 2. `link_names` is set to `1` so as to have the mention with `@customersupport` work (only works with groups, not individual users).

```auto
class ActionHandoverToSupport(Action):
    def name(self):
        return "action_handover_to_support"

    def run(
        self,
        dispatcher,
        tracker,
        domain,
        reason: Text = None,
    ):
        events = []
        text = f"@customersupport Help needed for user {tracker.sender_id}"
        response = client_slack.api_call(
            "chat.postMessage", channel=SLACK_SUPPORT_CHANNEL, text=text, link_names=1
        )

        if response.get("ok"):
            dispatcher.utter_message(template="utter_handover_to_support")
            events.append(ConversationPaused())
        else:
            dispatcher.utter_message(
                template="utter_technical_issue",
                extra_message="I could not send a message to my humans 😢",
            )

        return events

```

Hope that helps!! Nicolas

---

<div class="post-metadata">

**Author:** ![KhalidBentaleb](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/khalidbentaleb/32/7629_2.png) [@KhalidBentaleb](https://forum.rasa.com/u/KhalidBentaleb)\
**Post date:** [April 20, 2020, 6:09pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/14 "2020-04-20T18:09:14Z")

</div>

Hey @nbeuchat

Thank you so much for your answer, I didn’t understand the working mechanism handoff to human because I had some errors. and Tell me if I’ll add another codes

---

<div class="post-metadata">

**Author:** ![nbeuchat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nbeuchat/32/13688_2.png) [@nbeuchat](https://forum.rasa.com/u/nbeuchat)\
**Post date:** [April 21, 2020, 7:24am UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/15 "2020-04-21T07:24:50Z")

</div>

Great, hopefully this helps! Let me know if you have any other issue in implementing this 🙂

---

<div class="post-metadata">

**Author:** ![KhalidBentaleb](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/khalidbentaleb/32/7629_2.png) [@KhalidBentaleb](https://forum.rasa.com/u/KhalidBentaleb)\
**Post date:** [April 21, 2020, 12:35pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/16 "2020-04-21T12:35:05Z")

</div>

hii @nbeuchat

always I get this message

 ![35](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/a/a59d6aa81b393e287120b413e2c45e1946416aba.png)

---

<div class="post-metadata">

**Author:** ![nbeuchat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nbeuchat/32/13688_2.png) [@nbeuchat](https://forum.rasa.com/u/nbeuchat)\
**Post date:** [April 21, 2020, 12:55pm UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/17 "2020-04-21T12:55:37Z")

</div>

Can you share your logs? Try to set a breakpoint within the action to see where it fails. And what response do you get from slack

---

<div class="post-metadata">

**Author:** ![KhalidBentaleb](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/khalidbentaleb/32/7629_2.png) [@KhalidBentaleb](https://forum.rasa.com/u/KhalidBentaleb)\
**Post date:** [April 22, 2020, 7:47am UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/19 "2020-04-22T07:47:00Z")

</div>

hey @nbeuchat, Still not working if you have any idea ?

---

<div class="post-metadata">

**Author:** ![nbeuchat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nbeuchat/32/13688_2.png) [@nbeuchat](https://forum.rasa.com/u/nbeuchat)\
**Post date:** [April 22, 2020, 7:52am UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/20 "2020-04-22T07:52:45Z")

</div>

Could you share the logs of the action server itself? These are the logs for the core server. Your action is correctly called but it’s probably failing when trying to send a message to slack.

Also, can you try to send a message to slack from a normal python console (ie: outside of the action server), that way you can check if you are able to send any message at all.

> I can’t create channel bot for groups.

Not sure I understand, what do you mean? Also, the channel name is not the one you see on slack (for us, it looks something like `CRNK58KX3`, you can see it in the URL)

---

<div class="post-metadata">

**Author:** ![KhalidBentaleb](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/khalidbentaleb/32/7629_2.png) [@KhalidBentaleb](https://forum.rasa.com/u/KhalidBentaleb)\
**Post date:** [April 22, 2020, 10:14am UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/21 "2020-04-22T10:14:31Z")

</div>

thank you @nbeuchat, now I can send a message to slack but I don’t get any responses from slack channel

 ![23](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/2/297be3ff76f233800140d6361e9139377ea6fb34.png) ![51](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/2/209a131e6b782ad360adcd65d97e1b856e952f08.png)

---

<div class="post-metadata">

**Author:** ![nbeuchat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nbeuchat/32/13688_2.png) [@nbeuchat](https://forum.rasa.com/u/nbeuchat)\
**Post date:** [April 22, 2020, 10:22am UTC](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203/22 "2020-04-22T10:22:53Z")

</div>

Sounds like some async issue. Is your `run` function async? You might need to put an `await` as well. What version of the slack client are you using in the action server?

[Next page](https://forum.rasa.com/t/handing-off-to-human-on-slack/26203.md?page=2)
