![](/img/trans.png)
[英]Node.js, How to get JSON elemet from some url which i have to enter username and password in it?
[英]How receive username in watson from outside the dialog Node.js
我正在使用IBM的webApplication和Node.js創建一個聊天機器人 。
聊天機器人將遷移到需要登錄的Intranet中的“博客”。 因此,我想在聊天開始之前將用戶名作為上下文傳遞給Watson,從網站獲取它。
通過代碼在json上輸入新的上下文。
"context": {
"conversation_id": "8a433bbf-8e27-42ba-bdac-9341f5b16fcf",
"system": {
"dialog_stack": [
{
"dialog_node": "root"
}
],
"dialog_turn_counter": 1,
"dialog_request_counter": 1,
"_node_output_map": {
"node_1_1528906594423": [
0
],
"node_14_1527085355836": [
0,
0
]
},
"branch_exited": true,
"branch_exited_reason": "completed"
},
"timezone": "America/Sao_Paulo",
"nome_bot": "Malu"
"username": variable
}
所以最后,對話開始為:
用戶以John身份登錄。
沃森:“您好,$ username。” / “你好約翰。”
解決了! 在“ public / script.js”中,代碼稱為.json,因此我們需要在此處進行更改!
// Calling server and get the watson output
const getWatsonMessageAndInsertTemplate = async (text = '') => {
const uri = 'https://localhost/conversation/';
const response = await (await fetch(uri, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text,
context,
}),
})).json();
因此,如果我們將從數據庫獲取用戶名的變量添加到上下文中,並將其放在上下文“用戶名”中,則結果是預期的!
...
context: { 'username': variable },
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.