How to send a message to user when the conversation ended with agent and control is returned to the bot

Hi @Subrahmanyam ,

I have live chat integrated with my bot. However when the live agent closes the chat. I am trying to send the message to user that “live agent has closed the chat and the user can start chatting with the bot” .

Added sdk.sendusermessage at livechat.js.

When the live agent closes the chat. Close chat event is happening twice.
Please find the below screenshot

image

As a result i am getting the message twice in the bot .

image

Please assist

Regards
Arul

Hi @arulvelug, When the agent conversation is closed, LiveChat Inc is sending two events to bot kit, both of which have the event type as ‘chat_closed’.

// displaying the event payload as received at the bot from LiveChat.js file
else if (event.type===“chat_closed”){
console.log(“chat_Closed”,event);
image

These events will differ on the user_ type visitor/ agent. You could possibly apply the condition to display the message to the end user based on either of these. Please refer to below configuration.

 else if (event.type==="chat_closed" && event.user_type==='agent'){
                    console.log("chat_Closed",event);
                    delete userResponseDataMap[visitorId];
                    delete _map[visitorId];
					data.message="You conversation with the agent ended. You can continue chatting with the bot";
					sdk.sendUserMessage(data);	
                    sdk.clearAgentSession(data);
                }

image

@Subrahmanyam : Thanks for the update. it worked :slight_smile:

1 Like