Forwarding messages to Slack and vice versa for human hand-off

For future readers, this is the path I have taken so far:

  1. User types ‘talk to live agent’ or something similar.
  2. The custom action action_live_agent creates a live support chat in service now and sets the handoff_active to true. It also sets slots like live_chat_id (live chat id), live_chat_user (user_id to differentiate messages between agent and user), and live_chat_last_updated (timestamp of the last sent message to compare and only get the new messages later).
  3. The custom handoff policy HandoffPolicy with the highest priority checks handoff_active slot and predicts action action_live_agent_chat until handoff_active slot is set to false.
  4. action_live_agent_chat will post user messages to the live chat using live_chat_id. It will then do the following in order:
  • Check user message if message == "/restart" or message == '/end_chat'. If true, it will end the live chat by calling leave chat API and set slots handoff_active, live_chat_id, and live_chat_last_updated to None. HandoffPolicy will then stop predicting the custom action and bot will start handling responses. Ref. Screenshot 1.
  • If user message is not ‘/restart’ or ‘/end_chat’, the custom action will post the latest message to live agent chat thread and will retrieve the message thread.
  • It will loop through the message thread. If the message creator is not live_chat_user and message timestamp is greater than live_chat_last_updated, it will utter the messages to the end-user. After uttering the messages to the end-user, it will set live_chat_last_updated to the timestamp of the latest message in the thread. Ref. Screenshot 2.
  • It will then check if the received message contains the text has closed the support session (this is a part of the message that is sent once the live agent ends the chat session). If true, it will end the live chat by calling leave chat API and set slots handoff_active, live_chat_id, and live_chat_last_updated to None. Ref. Screenshot 3.
  • If any of the API calls (posting/retrieving messages) throws an error, it will end the live chat by calling leave chat API and set slots handoff_active, live_chat_id, and live_chat_last_updated to None. It will utter message with details like (chat summary, chat id, last updated). If there is an error in calling leave chat API, it will set slots handoff_active, live_chat_id, and live_chat_last_updated to None and utter generic message like “The chat session is closed/could not be located. Please try reconnecting to live agent if you still need help!”

Screenshot 1: User initiated live chat end:

Screenshot 2: Live agent conversation:

Screenshot 3: Live agent closed the chat session:

5 Likes