Pass Account Id and Contact Id of Experience Cloud Site User to Messaging for Web Session
Sep 15, 2025
Show More Show Less
View Video Transcript
0:05
Hello everyone. In this video, we are
0:07
going to see how to pass account ID and
0:10
as well as contact ID of the experience
0:13
cloud user
0:16
whenever they initiate messaging for web
0:20
session. Let's say I'm an experience
0:22
cloud user. I go to the experience cloud
0:24
site and then I'm initiating the
0:27
messaging session so that I can chat
0:29
with an human agent to get some help or
0:32
it may be an agent force agent or
0:34
Einstein bot.
0:37
If you have a requirement where you
0:38
wanted to pass the account ID and the
0:41
contact ID of the user to the messaging
0:43
session uh object so that you can build
0:46
some uh uh flows
0:50
to do the business process from the
0:52
flow. If you have this requirement you
0:55
can make use of this video as a
0:56
reference.
0:59
The first step is we have to create
1:01
three custom fields. One is to get the
1:03
user ID. Next to get the account ID and
1:07
the last one is to get the contact ID.
1:09
So in the messaging session object
1:13
create three fields. One to get contact
1:16
ID, account ID and user ID.
1:22
Okay. So I have created three fields.
1:24
Next I have to configure
1:27
custom parameter and then I have to do
1:29
custom parameter mapping on the
1:31
messaging channel. So this is the
1:35
messaging channel which I created it
1:37
created for my messaging for web
1:40
implementation. Here I created a custom
1:43
parameter with the parameter name user
1:47
space id API name or and the channel
1:50
variable name is user ID and the data
1:52
type is
1:55
string maximum length 18.
1:58
Next I have done the parameter mappings
2:01
for this uh parameter custom parameter
2:03
which I have created and in the flow I
2:07
have created a an input variable with
2:10
the name user ID no space. So this is
2:13
the omni channel flow. Here I created
2:18
an input variable with the API name user
2:22
ID. There is no space or underscore
2:25
and it is very and it is case sensitive.
2:27
So make sure you are using the flow
2:29
variable name here. So the channel
2:32
mapping is done.
2:35
The messaging channel is active. Next in
2:38
the embedded service deployment
2:42
I enabled
2:46
pre-hat. I didn't add any pre-hat field
2:50
but I added hidden pre-hat field. So
2:52
here I have added that user ID
2:56
which we created as the custom
2:58
parameter.
3:00
So this is added here. Once it is saved,
3:04
make sure you publish the embedded
3:06
service deployment so that the latest
3:08
changes are applied.
3:11
Next, this is the omni channel flow
3:13
which is referred here in this omni
3:16
channel flow routing in the messaging
3:18
channel.
3:20
here first what I'm doing is I'm getting
3:23
the user ID using that I'm fetching the
3:27
user record next I'm updating the
3:29
messaging session with the user ID which
3:33
is passed from the custom parameter next
3:36
for the contact ID I'm passing it from
3:38
the user which is fetched from this get
3:42
records
3:44
and for the account ID same from the
3:47
user which is fetched from this get
3:49
records
3:51
I'm using the account ID from that user
3:54
record.
3:56
Next, I'm routing it to a que.
4:00
So here it updates three fields. Account
4:03
ID, contact ID and user ID. Now I have
4:07
to pass the user ID whenever the
4:09
messaging for web session is initiated.
4:12
So that the user ID will be passed and
4:14
then the omni channel flow will fetch
4:16
the user record. It will then update the
4:19
messaging session record with the user
4:22
ID and from the user ID I was able to
4:25
get the user record. So from the user
4:28
record I will be able to get the account
4:29
and contact ids. So those values will be
4:32
update updated on the messaging session.
4:36
Okay. In order to pass the user ID,
4:40
first go to security and private uh and
4:43
privacy
4:45
and uh in the content security policy
4:48
CSP, make sure you are setting the value
4:52
as relaxed CSP permit access to inline
4:56
scripts and allowed hosts. Once this is
4:58
done, go to
5:02
advanced, click edit head markup and
5:06
here you have to add this script.
5:11
You can get the code snippet from this
5:15
uh blog post.
5:17
So here what I'm doing is I'm adding an
5:20
event listener for embedded messaging
5:22
ready. This event will be fired whenever
5:24
the messaging for web session is
5:26
initiated. So as an end user if I click
5:29
this chat icon I should be able to
5:32
initiate messaging for web session. So
5:35
this event will be fired when I do that.
5:37
So whenever this is fired I'm getting
5:40
the user ID using this uh expression
5:45
from the object type current user id.
5:47
I'm able to get the user ID using a
5:49
simple console.log statement. I'm making
5:52
sure whether the user ID is passed or
5:54
not. Next using embedded service
5:57
bootstrap. Prechart API dot set hidden
5:59
pre-chart fields method. I am passing
6:01
the user ID. So this is the
6:07
custom parameter value I am passing.
6:10
Once it is passed, it will pass that
6:13
value to the flow user ID variable and
6:17
the flow will do the rest.
6:21
Let's test it. So
6:27
let me log into my experience cloud as
6:30
an experience cloud site user.
6:35
So now itself uh
6:38
it would have fired and this is the user
6:40
ID which will be passed.
6:44
I don't have any messaging sessions as
6:46
of now. So now I'm going to
6:50
initiate
6:53
messaging for web session.
6:57
Let's see.
7:00
I'm able to see the contact ID, user ID,
7:02
and account ID. Let's go to the record.
7:07
This is the record. So, I'm able to see
7:10
this is the user ID that was passed. The
7:13
flow updated fetched the user record and
7:16
then updated contact ID, account ID and
7:19
also it populated the user ID from the
7:22
past uh user ID value.
7:30
Please check the video description. In
7:32
the video description, I have shared my
7:34
blog post. From the blog post, you
7:36
should be able to get the JavaScript
7:38
code which was referenced in this video
7:40
for your reference.
7:48
I hope it was helpful.
7:56
Thank you for watching.
#Internet Software