【问题标题】:How do I end my custom action on assistant?如何结束我对助手的自定义操作?
【发布时间】:2020-09-17 10:39:52
【问题描述】:

我有一个非常简单的操作,它只是给了我一些状态,然后我想结束它,没有对话,没有别的,只是获取状态并结束它。现在我正在这样做:

agent.add(message1);
agent.add(message2);
agent.end('done');

我也尝试过(正如您将在下面的代码中看到的那样,只是在做agent.end(completeMessage);,但助手一直在等我做更多事情,我的行动并没有结束。

我制作了一个完全简单的示例来演示,test intent 是具有end() 调用的示例:

代码:

'use strict';

const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
const { Card, Suggestion } = require('dialogflow-fulfillment');

const fetch = require("node-fetch");

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

  function welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }
  function testIntent(agent) {
    agent.end('done');
  }

 intent name
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('test intent', testIntent);
  agent.handleRequest(intentMap);
});

当我致电test intent 时,任何人都知道如何让我的行动完全结束?

【问题讨论】:

  • 您能清楚地知道您使用的是哪个库吗? (显示 require 和 package.json 文件)
  • 我只是在使用他们的 DialogFlow 内联编辑器,不知道他们的 package.json 长什么样?但我已经添加了要求行。
  • 我应该提一下,我几天前才开始执行此操作,所以我假设它使用的是内联编辑器的最新默认值。
  • 您能否更新问题以准确说明在调用 end 时发生了什么?有什么记录吗?你能告诉 Intent Handler 的其余部分发生这种情况吗?
  • 要添加我的代码,希望这能解释问题。基本上,一旦我使用 Google Home 设备给testIntent 打电话,它就会坐在那里等待更多,并且每隔一段时间就会说对不起,我听不懂或类似的话,最终它放弃了。我听说done,所以end 方法有效。

标签: dialogflow-es actions-on-google


【解决方案1】:

如果您将 dialogflow-fulfillment 库与 Actions on Google 一起使用,则只能有两个简单的响应(文本或 SSML 字符串)。由于您的代码在设置了两条消息后调用agent.end(),因此可能会被忽略。

相反,您可以将其称为

agent.add(message1);
agent.end(message2);

agent 的文档适用于 WebhookClient 对象。如果你想跳过这个库,还有webhook response JSON 文档。

【讨论】:

  • 感谢您提供的链接,这确实很有帮助,但是在第二条消息上执行 end 并没有帮助。这可能是因为我是从一个返回promise 的函数中执行此操作的。基本上我做了所有这些async 并在意图调用我的函数时返回promise。它似乎有效,但它只是坐在那里等我说更多的话。
  • 改成一行agent.end(message1 +" and "+ message2) 还是不行。
  • 您的示例代码没有显示 Promise。这应该有效,所以我现在不知道发生了什么,也没有时间尝试和重现。
  • 我想我忘了提,一旦我认为这是promise 的问题,我只是做了一个超级简单的例子,它所做的只是调用agent.end("done"),但即便如此不会结束我的行动。
猜你喜欢
  • 2015-02-06
  • 2022-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多