簡體   English   中英

Watson Assistant如何區分不同用戶

[英]How to Watson assistant differentiate between different users

我已經使用Watson Assistant創建了一個聊天機器人。 我通過API調用使用它。

假設有兩個不同的人想同時使用我的聊天機器人。 然后我必須要做的是使Watson理解兩個不同的人正在發送請求。

是否可以包含任何額外的參數來解決此問題? 如果是,請提及。

 //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> 

與Watson Assistant建立連接時,您將獲得一個對話ID,該ID隨響應一起返回。

您可以使用它來確定兩個不同的用戶是否同時通話。


根據評論更新:

Watson Assistant是無狀態的。 它不存儲先前的呼叫。

當您返回收到的上下文對象時,它將從上次中斷的地方繼續。 如果您沒有提供會話ID,或者無效的會話ID,則會生成一個新的會話ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM