Automatically End Salesforce Enhanced Chat Sessions with Opt Out Keywords
Sep 22, 2025
Show More Show Less
View Video Transcript
0:05
Hello everyone. In this video, we are
0:07
going to see how to automatically end
0:11
messaging session conversation when the
0:14
opt out keywords are used. For example,
0:19
if I use end or stop keyword in the chat
0:24
conversation,
0:25
it should opt me out because in the
0:28
messaging channel I would have set end,
0:32
stop, cancel as opt out keywords.
0:36
But it says that it is opted out but it
0:40
is not automatically ending the
0:42
messaging session conversation.
0:45
So we are going to see how to achieve
0:48
that. First let's look at an issue.
0:53
I'm going to test my messaging for web.
0:56
Now it is called as enhanced chat. I'm
1:00
initiating
1:01
messaging session conversation.
1:05
Insurance agent joined. So this
1:08
insurance agent is my agent force agent.
1:12
If I go to my
1:15
messaging settings,
1:23
if I look at the opt out keywords, I'm
1:27
using cancel, stop all, stop,
1:28
unsubscribe, end quit. So if I use any
1:31
of this keyword, it should opt me out
1:34
and then I shouldn't be able to further
1:37
continue the messaging session
1:38
conversation. But let's see the
1:40
behavior. So here I'm going to say stop.
1:47
It says that you have opted out of
1:50
receiving messages from us. So we won't
1:53
contact you again but it is trying to
1:56
transfer the
1:59
conversation. It is still trying to uh
2:02
respond back to the agent uh sorry the
2:05
end user and then it is giving a bad
2:07
user experience. Let's see how to
2:09
overcome this issue.
2:15
The solution for this issue is
2:18
first we have to make use of on embedded
2:21
message sent event. This event will be
2:24
fired whenever a message is sent by the
2:26
end user or by the chatbot or by the
2:30
agent force agent. So we have to find
2:33
out whether this event is fired. Then we
2:36
have to find out whether it was sent by
2:38
the end user or not. If it is sent to
2:41
sent by the end user then we can make
2:44
use of embedded service bootstrap dot
2:47
user verification API dot clear session
2:51
method so that it will clear the session
2:53
and then it will end the conversation
3:02
in order to test it.
3:10
Let's test it
3:14
from my GitHub account. So here I'm
3:17
going to initiate
3:20
enhanced chat messaging session and
3:23
agent force agent is joined. Here I'm
3:25
going to say stop.
3:31
It says it is opted out. The agent left
3:34
and then it is it is alerting me saying
3:36
that you have opted out of chat. If I
3:39
click okay, it will clear the session.
3:40
So the session is cleared. In order to
3:43
achieve it,
3:47
I'm making use of window.adde
3:48
eventlister for on embedded message sent
3:52
event. Here I'm checking whether the
3:55
role is end user
3:58
and then I'm checking whether the user
4:01
entered end or stop. So here I have
4:06
hardcoded only two opt out keywords but
4:09
you have to hardcode all the keywords
4:11
that are configured in this opt out
4:13
keywords.
4:14
So if you do any changes here, you have
4:16
to go and update
4:19
this constant uh in the JavaScript so
4:22
that whenever the end users send any opt
4:25
out keywords, it will end the
4:30
chat and it will clear the session
4:33
using window. Method I am send I'm
4:37
alerting the user saying that you have
4:39
opted out of chat.
4:47
Please check the video description. In
4:49
the video description, I have shared my
4:51
blog post. From the blog post, you
4:53
should be able to get the sample
4:55
JavaScript code that was used in my
4:57
website for your reference.
5:02
You have to use this JavaScript code
5:05
snippet
5:06
in your embedded service uh deployment
5:08
code snippet. It should be used after
5:13
embedded
5:15
sorry embedded service bootstrap.
5:17
Settings.language.
5:19
After that I am using this enable user
5:22
input for conversation with bot. So that
5:25
multiple inputs will not be sent to the
5:28
agent force agent only uh only one at a
5:31
time it will be sent. So that I'm making
5:33
use of streaming streaming messages so
5:35
that the messages will be streamed. It
5:37
will displayed and then the end user
5:38
will be able to respond back.
5:46
I hope it was helpful.
5:55
Thank you for watching.
#Business & Productivity Software
#Business Operations
#Internet Software
