2016-09-16 29 views
0

我正在嘗試wit.ai中的不同故事。以下是我想要報告丟失的信用卡的一種情況。當用戶說他失去了信用卡時,機器人必須分兩步詢問他的SSN,然後是母/姓,然後它必須阻止該卡。下面是應用程序鏈接: https://wit.ai/Nayana-Manchi/CreditCardApp/stories/f7d77d9e-e993-428f-a75e-2e86f0e73cb3wit.ai +與2個或更多對話獲得實體的故事

問題:

  1. 在entites的名單,我發現,只需要第二個輸入(在這種情況下,即母親的名字,SSN爲null)在實體列表當它調用行動。我在JavaScript代碼中添加了一些日誌來查找實體列表。 我是否也需要在這些場景中使用基於插槽的方法?

  2. 基於插槽的方法在這裏不適用,因爲用戶不知道什麼是安全問題。

  3. 僅當(有/沒有)選項存在時纔在動作選項卡中。請解釋它的用法。如果我在那裏設置所需的實體(在這種情況下:SSN和母名),bot會像循環一樣連續請求SSN。

代碼與快速入門示例類似,對讀取實體進行了一些更改。 Result in node-wit terminal with logged messages added in javascript

回答

0

您應該保存屬於同一會話的所有會話發送操作

send(request, response) { 
 
     const {sessionId, context, entities} = request; 
 
     const {text, quickreplies} = response; 
 
     const motherName = userSession[sessionId].fbid; 
 
     const motherName = firstEntityValue(entities, 'mother_name'); 
 
     const SSN = firstEntityValue(entities, 'SSN'); 
 

 
     // set context in user sessions to used in actions 
 
     // act as merge operation of old wit.ai api 
 
     if (motherName && SSN) { 
 
      sessions[sessionId].context.motherName = firstEntityValue(entities, 'mother_name'); 
 
      sessions[sessionId].context.SSN = firstEntityValue(entities, 'SSN'); 
 
     } 
 

 
     return new Promise(function (resolve, reject) { 
 
      console.log("Sending.. " ,text); 
 
      resolve(); 
 
     }); 
 
    },
要使用它的自定義操作

//to use saved entities from customAction 
 

 
     findCreditCard({sessionId, context, text, entities}) { 
 
     
 
     const SSN = sessions[sessionId].context.SSN; 
 
     const motherName = sessions[sessionId].context.motherName; 
 

 
     return new Promise(function (resolve, reject) { 
 
      // custom action code 
 
//if everything gets completed then set context.done=true 
 
if(completed) context.done=true 
 
      resolve(context); 
 
     }); 
 
    });

要重新運行你的行動停止,刪除conext

wit.runActions(
 
    sessionId, 
 
    text, // the user's message 
 
    sessions[sessionId].context // the user's current session state 
 
).then((context) => { 
 
    console.log('Wit Bot haS completed its action', context); 
 
// this will clear the session data 
 
    if (context['done']) { 
 
     console.log("clearing session data"); 
 
     delete sessions[sessionId]; 
 
    } 
 
    else { 
 
     console.log("updating session data"); 
 
     // Updating the user's current session state 
 
     sessions[sessionId].context = context; 
 
    } 
 
}).catch((err) => { 
 
     console.log('Oops! Got an error from Wit: ', err.stack || err); 
 
});

+0

非常感謝您的幫助。我會盡力解釋。 –

+0

這對我有很大的幫助。我保存會話中的實體併成功檢索它。非常感謝您的幫助。:) –

+0

不客氣......我在生產環境中使用redis來存儲session.if這可以幫助您,然後請評估它。 –