简体   繁体   English

Watson Assistant如何区分不同用户

[英]How to Watson assistant differentiate between different users

I have created a chatbot using Watson assistant. 我已经使用Watson Assistant创建了一个聊天机器人。 I am using it through API calls. 我通过API调用使用它。

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. 然后我必须要做的是使Watson理解两个不同的人正在发送请求。

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. 与Watson Assistant建立连接时,您将获得一个对话ID,该ID随响应一起返回。

You can use that to determine if two different users are talking at the same time. 您可以使用它来确定两个不同的用户是否同时通话。


Update based on comment: 根据评论更新:

Watson Assistant is stateless. Watson Assistant是无状态的。 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. 如果您没有提供会话ID,或者无效的会话ID,则会生成一个新的会话ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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