简体   繁体   English

Dialogflow:在给定的上下文中强制某些意图无效

[英]Dialogflow: Forcing certain intents to be invalid given context

I want to make knock knock jokes using dialogflow, but I found that I can trigger one knock knock joke from the context of another.我想使用对话流制作敲门笑话,但我发现我可以从另一个上下文中触发一个敲门笑话。 For example I have the following intents:例如,我有以下意图:

  • knockknock: training phrase (knock knock joke), response (knock knock) knockknock:训练短语(敲敲笑话),响应(敲敲)
    • whosethere: trainging phrase (who dat), response (annie, orange) whothere:训练短语(who dat),响应(annie,orange)
      • punchline-annie: training phrase (annie who), response (annie thing you can do I can do better) Punkline-annie:训练短语(annie who),响应(annie thing you can do I can do better)
      • punchline-orange: training phrase (orange who), response (orange you glad...)妙语-橙色:训练短语(橙色谁),响应(橙色你高兴...)

If the bot responds with annie, I can respond with orange who and get the orange punchline to the joke.如果机器人用 annie 响应,我可以用 orange who 响应,并得到这个笑话的橙色妙语。 How can I prevent this from happening?我怎样才能防止这种情况发生? I only want the orange punchline to be able to be called when the response from the whosethere intent was orange.我只希望能够在其意图的响应为橙色时调用橙色妙语。

I think you need to look into how to send a responsive via fulfilment/webhook and how contexts work.我认为您需要研究如何通过 fulfillment/webhook 发送响应以及上下文如何工作。 In your whosthere intent, you could send a response via fulfilment and set the context appropriately.在您的 whosthere 意图中,您可以通过履行发送响应并适当地设置上下文。 Eg: if you answer with "annie", set an annie specific context (eg punchline-annie-context) and set punchline-annie-context as an input context for the punchline-annie intent.例如:如果您回答“annie”,请设置 annie 特定上下文(例如,punchline-annie-context)并将punchline-annie-context 设置为punchline-annie 意图的输入上下文。 This way you ensure that punchline-annie can only be activated, if the whosthere response was "annie".这样,您可以确保只有 whosthere 的响应是“annie”时才能激活妙语安妮。

Thank you @andreas030241 for the information.谢谢@andreas030241 提供的信息。 I figured out how to get the logic to work by learning how to use fulfillment.通过学习如何使用履行,我弄清楚了如何让逻辑发挥作用。 I set the response of the knockknock-whosethere intent inside the inline editor, and created an associated context name, that I then used as the input context for whichever punchline intent I wanted to be valid.我在内联编辑器中设置了 knockknock-whosethere 意图的响应,并创建了一个关联的上下文名称,然后我将其用作我想要有效的任何妙语意图的输入上下文。 The example code is below.示例代码如下。 Much appreciation!非常感谢!

  function punchline(agent) {
    var names = [`Annie`,`Orange`,`Lena`,`Quiche`,`Wa`,`A little old lady`];
    var context_names = ['annie-punchline','orange-punchline','lena-punchline','quiche-punchline','wa-punchline','alittleoldlady-punchline'];
    var number = Math.floor(Math.random() * names.length);
    agent.add(names[number]);
    agent.setContext({
        name: context_names[number],
        lifespan: 1,
        });
  }

  let intentMap = new Map();
  intentMap.set('knockknock-whosethere', punchline);
  agent.handleRequest(intentMap);

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

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