Hi Mohammed,
Thanks for sharing your solution.
Can you also share how you are passing username (var x ) in the below javasrcipt ?
<script>
window.watsonAssistantChatOptions = {
integrationID: "xxxxxxxxxxxxxxx", // The ID of this integration.
region: "xx-xx", // The region your integration is hosted in.
serviceInstanceID: "xxxxxxxxxxxxxxxxx", // The ID of your service instance.
onLoad: function(instance) { instance.render(); }
};
setTimeout(function(){
const t=document.createElement('script');
t.src="
https://web-chat.global.assistant.watson.appdomain.cloud/loadWatsonAssistantChat.js
";
document.head.appendChild(t);
});
</script>
------------------------------
shubhendra vyas
------------------------------
Original Message:
Sent: Sun August 16, 2020 04:34 AM
From: Mohamed Gamaleldin Egila
Subject: Watson Assistant Web Chat reads username from the parent page cookies
Hello Christian,
Thanks fro your answer and for taking the time to reply.
Actually, I solved this issues days ago and was intending to post the answer here.
I almost did the same solution, but instead of using document.cookie I added a new function and 2 variables:
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
var user=getCookie("IBM_WAC_ANONYMOUS_USER_ID");
var x = sessionStorage.getItem("username");
I, actually used the sessionStorage as the variable I need was stored in sessionStorage.
Thanks,
------------------------------
Original Message:
Sent: Fri August 14, 2020 01:36 PM
From: CHRISTIAN Peterman
Subject: Watson Assistant Web Chat reads username from the parent page cookies
Hi Mohamed,
With Javascript you can do var x = document.cookie to get the cookie, then just parse x to get the name assuming there is one saved. You would need to use the preload event to pass in the name and save it as a context variable.
My colleague Morgan put together a blog on the topic: https://medium.com/@modlanglais/ibm-watson-assistant-how-do-i-determine-unique-users-3aef8d3a2b8e
I believe there is a code snippet in there ^^
As well - here are the docs on how to customize the WebChat : https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=
Hope this helps.
Kind Regards,
Christian
------------------------------
CHRISTIAN Peterman
Original Message:
Sent: Mon August 10, 2020 02:24 PM
From: Mohamed Gamaleldin Egila
Subject: Watson Assistant Web Chat reads username from the parent page cookies
I've a question please, I'm having a Watson Assistant Chatbot embedded in a Webpage as a Web Chat.
My question is that how to make the Watson Assistant retrieves username from Webpage cookies to be displayed in the Watson Chatbot. Like making the chatbot opens saying "Hi Adam", based on that "Adam" exists as username in the page cookies that the Watson Assistant is embedded into.
Is there any change. that can be made to the generated JavaScript in order to read these coookies?
I'm using a JavaSript like this:
<script>
window.watsonAssistantChatOptions = {
integrationID: "xxxxxxxxxxxxxxx", // The ID of this integration.
region: "xx-xx", // The region your integration is hosted in.
serviceInstanceID: "xxxxxxxxxxxxxxxxx", // The ID of your service instance.
onLoad: function(instance) { instance.render(); }
};
setTimeout(function(){
const t=document.createElement('script');
t.src="
https://web-chat.global.assistant.watson.appdomain.cloud/loadWatsonAssistantChat.js";
document.head.appendChild(t);
});
</script>
------------------------------
Any help is appreciated,
Thanks,
------------------------------
#WatsonAssistant