等待代理商回复几秒钟 [英] Wait some seconds before agent's reply

查看:60
本文介绍了等待代理商回复几秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Google上的Actions创建一个非常简单的Dialogflow应用。

I'm trying to build a very simple Dialogflow app for Actions on google.

我的想法是一个非常简单的计时器,但是每X秒代理会告诉用户还剩X秒。

What I had in mind was a very simple timer, but every X seconds the agent will tell the user "X seconds left".

我正在使用dialogflow的实现部分。我试图做的是一个简单的 setTimeout,其中包含另一个agent.add,但是在部署它时Dialogflow似乎忽略了它:

I'm using the Fulfillment section on dialogflow. What I've tried to do was a simple "setTimeout" that include another agent.add but this seems to be ignored by Dialogflow when I deploy it:

function startTimer(agent)
  {
    agent.add("Timer started! 20 seconds from now.");

       setTimeout(function(){ 
        agent.add("10 seconds left!");
    }, 10000);  

    agent.add("Time out.");
}

    let intentMap = new Map();
    intentMap.set('timer', startTimer);
    agent.handleRequest(intentMap);

助手的响应是一个简单的计时器已开始和超时,没有X秒剩下的。启动意图后,有什么方法可以添加回复?

The response from assistant is a simple "Timer started" and "Time out", without the X seconds remaining. Is there any way to add a reply when an intent is started? Thanks!

编辑|谢谢!按照建议,我已经尝试过使用SSML,但是当助手说到标签时,标签就会显示在屏幕上。

EDIT | as suggested, I have tried with SSML, but the tags are displayed on the screen when they get said by the assistant.


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

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });

  function startTimer(agent)
  {
    agent.add("Something to say");
    agent.add(`<speak><seq><media begin="30s"><speak>30 seconds</speak></media><media begin="30s"><speak>1 minute</speak></media></seq></speak>`);
    agent.add(new Suggestion(`Quit`));
  }

    let intentMap = new Map();
    intentMap.set('timer-go', startTimer);
    agent.handleRequest(intentMap);
});


推荐答案

无法启动操作对话,履行代码(您的功能)必须在10秒内返回,否则Google助手会在超时警告的情况下关闭操作。

It's not possible to an Action start a conversation, the fulfillment code (your function) must return within 10 seconds, or the Google Assistant will close the Action with a time-out warning.

您的setTimeout为无法运行,因为此代码正在云中运行,并且实际上将其发送回助手,您必须发送响应,而您只是向其中添加项目,而不返回对象。

And your setTimeout is not working because this code is running in the cloud, and to actually send it back to the Assistant, you must send the response, and you are only adding items to it, but not returning the object.

此页面结束履行功能可在DialogFlow / Google助手上使用。

This page from DialogFlow documentation explains how the back-end fulfillment works on DialogFlow / Google Assistant.

这篇关于等待代理商回复几秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆