watsonx Assistant

 View Only
  • 1.  Watson Assistant Web Chat reads username from the parent page cookies

    Posted Mon August 10, 2020 02:28 PM
    Edited by System Fri January 20, 2023 04:13 PM


    ------------------------------
    Any help is appreciated,
    Thanks,
    Mohamed Gamaleldin Egila
    ------------------------------
    #WatsonAssistant


  • 2.  RE: Watson Assistant Web Chat reads username from the parent page cookies
    Best Answer

    Posted Fri August 14, 2020 01:43 PM
    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
    ------------------------------



  • 3.  RE: Watson Assistant Web Chat reads username from the parent page cookies

    Posted Sun August 16, 2020 04:34 AM
    Edited by System Fri January 20, 2023 04:38 PM
    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,



    ------------------------------

    ------------------------------



  • 4.  RE: Watson Assistant Web Chat reads username from the parent page cookies

    Posted Wed October 14, 2020 09:13 AM
    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
    ------------------------------



  • 5.  RE: Watson Assistant Web Chat reads username from the parent page cookies

    Posted Tue July 06, 2021 09:45 AM
    I have the same question as the last person who messaged on here last year. How did you pass these variables?



    ------------------------------
    Vincent Rathod
    ------------------------------



  • 6.  RE: Watson Assistant Web Chat reads username from the parent page cookies

    Posted Wed July 07, 2021 05:54 AM

    To set additonal info you should choose on of the following options:

    1. plain context variables - Watson Assistant web chat documentation

    2. if you have enabled security on your web chat, pls use `user_payload` - https://cloud.ibm.com/docs/assistant-data?topic=assistant-data-dialog-integrations



    ------------------------------
    DAVID AMID
    ------------------------------