DialogFlow,如果语句在应用程序意图中进行了转换

问题描述 投票:0回答:1

我想在dialogflow中运行此代码,基本上我想使用if条件例如。如果我的意图是“完成”,请回复[文本回复] =>“现在再添加2个并说得到它”它切换到我的另一个意图,即“正确”,因此响应应该是“ you no。is 1”,并结束转换。相似点如果我的意图是“完成”,请回复[文本回复] =>“现在再添加4个并说得到它”,然后它切换到我的另一个意图,即“正确”,因此响应应该是“ you no。is 2”并结束转换。

然后继续。

只需看下面的SSenter image description hereenter image description here

'use strict';

// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

var numr=0;
app.intent('done',(conv,output)=>{
  if(conv.ask ==='Now add 2 more, and say got it'){
    numr=1;
    return numr;
  }
  else{
    numr=2;
    return numr;
  }   
});

app.intent('Alright',(conv)=>{
  conv.close('your number is '+ numr);
});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
if-statement dialogflow actions-on-google dialogflow-fulfillment
1个回答
0
投票

您的代码存在许多问题,很难准确地了解您在做什么。但是,有几件事要注意。我假设您在这里使用JavaScript。

  1. 您在使用else时遇到语法错误。 else语句后应有一个执行块。您似乎正在遵循条件。也许您正在尝试使用else if

  2. conv.ask是一个函数。然后,您要为其分配一个字符串,该字符串将作为函数被删除。我认为这不是您要在这里执行的操作。

  3. 在“完成” Intent的Intent处理程序中,您没有使用conv.ask()函数将任何内容发送回用户,因为您只是将其作为函数删除了。

  4. 设置全局变量并不保证在Intent Handler调用之间将保留其值。如果要在对话过程中保存值,则应使用Contextconv.data或其他方式。

© www.soinside.com 2019 - 2024. All rights reserved.