简体   繁体   中英

How to Watson assistant differentiate between different users

I have created a chatbot using Watson assistant. I am using it through API calls.

Suppose there are two different persons who want to use my chatbot at the same time. then what I have to do in order to make Watson understand that two different persons are sending the requests.

if there are any extra parameters which can be included to handle this problem? if yes, please mention.

 //var objDiv = document.getElementById("chatbotid"); //objDiv.scrollTop = objDiv.scrollHeight; document.querySelector("#input").addEventListener("keypress", function(e) { var key = e.which || e.keyCode; if (key === 13) { //Enter button var input = document.getElementById("input").value; //storing input value document.getElementById("input").value = ""; TempChatInput = document.getElementById("chatbot"); TempChatInput.innerHTML += "user: " + input + "<br/><br/>"; //document.getElementById("user").innerHTML = input; output(input); } }); function output(input) { //var xhr = new XMLHttpRequest(); var newData = "{\\"input\\": {\\"text\\":" + "\\"" + input + "\\"" + "}}"; //var input = $('input').val(); var dataText; $.ajax({ url: "https://gateway.watsonplatform.net/assistant/api/v1/workspaces/myWorkspaceID/message?version=2018-02-16", beforeSend: function(xhr) { //xhr.setRequestHeader("Authorization", "Basic" + btoa(username + ":" + password)); xhr.setRequestHeader("Authorization", "Basic " + btoa("my username" + ":" + "my password")); }, type: "POST", dataType: "json", contentType: "application/json", processData: false, //data: "{\\"input\\": {\\"text\\": \\"location\\"}}", data: newData, success: function(data) { dataText = data["output"]["text"]; //console.log(dataText); TempChat = document.getElementById("chatbot"); TempChat.innerHTML += "Chatbot: " + dataText + "<br/><br/>"; //document.getElementById("chatbot").innerHTML = dataText; //alert(dataText); var objDiv = document.getElementById("chatbotid"); objDiv.scrollTop = objDiv.scrollHeight; }, error: function() { alert("Cannot get data"); } }); //document.getElementById("chatbot").innerHTML = dataText; } 
 body { color: #421; font-weight: bold; font-size: 18px; background: #069597; background-image: url("girl.png"); background-repeat: repeat-y; } span { color: #104A70; padding: 1px; } ::-webkit-input-placeholder { color: #104A70; } #main { position: fixed; top: 10%; right: 60px; width: 400px; border: 0px solid #421; padding: 40px; } #main div { margin: 10px; } #input { border: 0; background: rgb(255, 255, 255); padding: 5px; border: 1px solid #421; color: #104A70; } #line { text-align: center; background: #3BB2B4; } #chatbotid { overflow: scroll; width: 400px; height: 400px; background: rgb(230, 230, 225); padding: 5px; border: 2px solid #104A70; } 
 <div id="line"> <hr/> <h1 style="color:rgb(255,255,255);"> Vawsum Help Desk</h1> <hr/> </div> <div id="main"> <!-- <div> <span id="user"></span></div> --> <!--I have deleted user from this line --> <div id="chatbotid"> <span id="chatbot"></span></div> <!--I have deleted chatbot from this line --> <div><input id="input" type="text" placeholder="say something..." autocomplete="off" /></div> </div> 

When you make a connection with Watson Assistant, you get a conversation ID that comes back with the response.

You can use that to determine if two different users are talking at the same time.


Update based on comment:

Watson Assistant is stateless. It has no memory of previous calls.

When you return the context object you received, it will continue on from where it last left off. If you don't supply the conversation ID, or an invalid conversation id it will generate a new one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM