Handing off to Human agent

want to create an action that interact with slack through webhook.

A reliable way of accomplishing without switching the frontend for routing messages (which is a good way of going about it) would be defining your own policy in addition to a custom action to facilitate the communication. Give the policy the highest priority in your configuration and let it predict the action when a certain slot is triggered like handoff_active.

After you are done talking with the human agent you can unset the slot to finish the story and optionally predict some follow-up actions like feedback and whatnot.

how to connect with slack and getback response?

@Tobias_Wochinger Could you explain in brief or steps , how to perform handoff through slack or rocketchat live?

Hey @Tobias_Wochinger!

Do you have any tips on forwarding the messages to a human?

I have posted my implementation based on the suggestion from @chkoss in the following thread.

Hello @Mappi Thanks for your suggestion , i thinks thats really a good one but can your help me the custom policy how and what ? i am not getting what kind of policy will help me to hand over the human , please exaplain or guide me through this . Thanks

@nchauras would you please provide a working code to test it and customize it?

Apologize for the delayed response. I have not been working on Rasa for a while now. Please let me know what code you need. You can reach out to me or we can work on a shared repo.

The complete code of handoff. When an user requests handoff, or bot failed to assist the customer, i want to transfer to human agent (support): Whatsapp API is not working anymore on groups, i dont want any other messenger. The only solution i have is to have chat web portal, flow will be like that: bot->customer->web portal. Can u assist me to send/receive messages from chatbot<=>web portal via webhook or anyn possible solution? You can reach anytime on my whatsapp +961 79 138 607 or Skype paolo_1st

The handoff is working now using Rasa database: chatbot<=>customer<=>support web portal.

I am sending the message from support to chatbot using API POST request: http://192.168.214.166:5005/webhooks/rest/webhook { “sender”: “0b83b3494194403a94cc103059123a0c”, “message”: “Hi Client, kifak? ma3ak Charbel min proactive.” }

In Rasa database, there is field “type_name”: bot, user… One question is how to update this field using the above API?

Hi @paolo_1st , were you able to completely hand off from bot to a human assistant without changing the chatbox messenger? I am new and I would like to explore this solution. Thanks

yes it’s working, but when human sends greetings or any known intent, the conversation is not paused anymore. i m checking it. You can add this class to custom action, add “action_handoff” under domain file…:

class ActionTalkToHuman(Action): def name(self): return “action_handoff”

def run(self, dispatcher, tracker, domain):
    text =conversation_id=last_msg_time=new_msg_time=last_msg=new_msg=""
    conversation_id=tracker.sender_id
    text = get_text_from_lang(
        tracker,
        ['We are transferring you to a human agent...',
        'Nous vous transférons vers un agent humain ...',
        'نقوم بتحويلك إلى وكيل بشري ...',
        'Մենք ձեզ տեղափոխում ենք մարդկային գործակալ ...'])
    dispatcher.utter_message(text)
    db = Database_Connection(db_info = db0)
    last_msg = db.Select("select data from events where sender_id='"+conversation_id+"' order by id desc limit 0,1")
    if(len(last_msg)>0):
        x=y=""
        x=str(last_msg[0]).split(",")
        if(len(x)>0):
            if x[1]!="":
                y=x[1].split(":")
                if(len(y)>0):
                    last_msg_time=y[1]
                    while new_msg!="/unpause" and new_msg!="/end_chat" and new_msg_time>last_msg_time:
                        nm=""
                        nm = db.Select("select data from events where sender_id='"+conversation_id+"' order by id desc limit 0,1")
                        if(len(nm)>0):
                            x=y=""
                            x=str(last_msg[0]).split(",")
                            if(len(x)>0):
                                if x[1]!="":
                                    y=x[1].split(":")
                                    if(len(y)>0):
                                        new_msg_time=y[1]
                                        if new_msg_time>last_msg_time:
                                            #dispatcher.utter_message("Human agent: {}".format(message))
                                            dispatcher.utter_message("Human agent is talking")
                        time.sleep(10)  
    return [ConversationPaused()]

i am reading messages from databases. On the other side, i built a web portal for human messages, communicating with Rasa database.

updated version:

class ActionTalkToHuman(Action): def name(self): return “action_handoff”

def run(self, dispatcher, tracker, domain):
    text =conversation_id=last_msg_time=new_msg_time=last_msg=new_msg=""
    tracker._paused = True
    conversation_id=tracker.sender_id
    text = get_text_from_lang(
        tracker,
        ['You have been transferred to a human agent.',
        'Vous avez été transféré à un agent humain.',
        'لقد تم نقلك إلى وكيل بشري.',
        'Դուք տեղափոխվել եք մարդկային գործակալ:'])
    dispatcher.utter_message(text)
    db = Database_Connection(db_info = db0)
    last_msg = db.Select("select data from events where sender_id='"+conversation_id+"' order by id desc limit 0,1")
    if(len(last_msg)>0):
        x=y=""
        x=str(last_msg[0]).split(",")
        if(len(x)>0):
            if x[1]!="":
                y=x[1].split(":")
                if(len(y)>0):
                    last_msg_time=y[1]
                    while new_msg!="/unpause" and new_msg!="/end_chat" and new_msg_time>last_msg_time:
                        nm=""
                        nm = db.Select("select data from events where sender_id='"+conversation_id+"' order by id desc limit 0,1")
                        if(len(nm)>0):
                            x=y=""
                            x=str(last_msg[0]).split(",")
                            if(len(x)>0):
                                if x[1]!="":
                                    y=x[1].split(":")
                                    if(len(y)>0):
                                        new_msg_time=y[1]
                                        if new_msg_time>last_msg_time:
                                            #dispatcher.utter_message("Human agent: {}".format(message))
                                            dispatcher.utter_message("Human agent is talking")
                        time.sleep(10)  
    return [ConversationPaused()]

Hi @paolo_1st , many thanks for sharing that. Just to be sure the steps to follow: Documentation says that I need to name my class and using same name in the return string “action_classname” of the name method. As far as I understood you name your class as ‘TalkToHuman’, but in the ‘name’ method you’re using a different name into the string “action_handoff”. Since the same string, you need to define it into the domains.yml file. I think it should be clear if you align both names into your class just like: " Class ActionHandoff … def name(self): return “action_Handoff" so that into the domains file you’ll write under section actions: - action_Handoff. If I am wrong , please tell me if the following steps are correct:

  1. Cut&Paste all you class "ActionTalkToHuman(Action) " that you named “action_handoff” , into the actions.py file
  2. I go to domains.yml file and under "actions " sections I add: - action_handoff Is that correct?
  1. is " get_text_from_lang" a built-in method in RASA or I need to define it myself?
  2. what chatbox widget (front-end) are you using? I would like to use RASA chatbot with a chatbox widget for some web pages. Thanks again
  1. yes

  2. intents:

  • trigger_handoff
  • human_handoff
  • handoff

actions:

  • action_handoff
  1. sorry, it’s custom action, u can replace it by: dispatcher.utter_message(msg)

where msg=any message you want to display to the user.

  1. In local mode, i m using Rasa X. For customers, i will use chatbox widget. For handoff between clients and support, i developed my own web app to communicate with Rasa database.

All is working fine.

Can you please give a code snippet

Can you please give a code snippet @paolo_1st

@ralex:

  1. right
  2. right
  3. you can ignore it and use dispatcher.utter_message(…)
  4. chatroom widget, u can find it on github

to vivek22122014 and Ayantika1: i already shared the code above.