For future readers, this is the path I have taken so far:
- User types ‘talk to live agent’ or something similar.
- The custom action
action_live_agent
creates a live support chat in service now and sets thehandoff_active
to true. It also sets slots likelive_chat_id
(live chat id),live_chat_user
(user_id to differentiate messages between agent and user), andlive_chat_last_updated
(timestamp of the last sent message to compare and only get the new messages later). - The custom handoff policy
HandoffPolicy
with the highest priority checkshandoff_active
slot and predicts actionaction_live_agent_chat
untilhandoff_active
slot is set to false. -
action_live_agent_chat
will post user messages to the live chat usinglive_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 slotshandoff_active
,live_chat_id
, andlive_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 thanlive_chat_last_updated
, it will utter the messages to the end-user. After uttering the messages to the end-user, it will setlive_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 slotshandoff_active
,live_chat_id
, andlive_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
, andlive_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 slotshandoff_active
,live_chat_id
, andlive_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: