簡體   English   中英

如何在 Google Dialogflow 中使用參數修改上下文

[英]How to use Parameters to modify Context in Google Dialogflow

我們正在運行一個實驗,我需要根據參與者的 ID 操作對話流響應。 我的想法是有一種方法可以根據參數值設置輸出上下文。

例如,我們有一個詢問參與者 ID 的提示。 這匹配具有“participantID”參數的意圖。 現在我想做的是將輸出上下文設置為“participantID”參數的值。 然后我可以將輸入上下文設置為特定的“參與者 ID”。

在意圖上設置的任何參數都將保留在輸出上下文中,並可在此類上下文的生命周期內在后續的后續意圖中恢復。

通過 Dialogflow UI,您可以在初始響應中將它們引用為$<parameter-name>
例如,假設您的參數名稱是id ,則響應可以是: Welcome player $id,...

對於后驗后續意圖中上下文中的值,請使用#<context-name>.<parameter-name>
例如,在具有參數answer和輸入上下文id-followup的第二個后續操作中, Your answer has been $answer, if you are not player #id-followup.id please let me know your actual id

如果您需要使用 Fulfillment Webhook,我推薦一種類似於此處所示結構的結構,即如下結構:

//The user inputs a participant ID (name of the parameter is id)
function answers(agent){
    const id = agent.parameters.id;
    agent.add(`So your id is ${id}`);
    agent.add(`Any extra questions...`);
    agent.setContext({
      name: 'question',
      lifespan: 5,  // Amount of follow-up intents this context will be kept
      parameters: {'cid': id},
    });
}
// Next functions that use the participant id as input context
function answers2(agent){
    // Get the context and from it extract the id value
    const cont = agent.getContext('question');
    const particular_id = cont.parameters.cid;
    // The rest of your code

您可能會發現一些有用的文檔包括輸入和輸出上下文參數參考、...

根據您使用的 dialogflow-fulfillment 版本,我在這里談論的是 0.6.1。 設置上下文的語法是:

 agent.context.set({
    name: "ctx_name",
    lifespan: 5,
    parameters: {'cid': id},
  });

暫無
暫無

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

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