0

I have created an intent in Dialogflow web interface. It auto detected a parameter called given-name, which lists it as $given-name in the web interface. I am trying to address $given-name in the fulfillment inline editor provided by the web interface, but I am not having any success.

I've tried changing the parameter name to camel case, and also alternatively to using an underscore to replace the hyphen but neither seemed to work.

Here is the code snippet from the dialogflow fulfillment inline editor:

'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});

// Can't address given-name, intentionally used an underscore 
app.intent('run demo', (conv, {given_name}) => {
conv.close('Hi ' + given_name +'! This is the demo you asked me to run!');
});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

I want to know the correct way to address the given name parameter in the code section app.intent('run demo', (conv ...);

4

1 回答 1

2

解决方案

我找到的一个解决方案是这段代码:

app.intent('run demo', (conv, params) => {
    conv.close('Hi ' + params['given-name'] +'! This is the demo you asked me to run!');
});

解释

(conv, params) => {...}ofapp.intent('run demo',...实际上是一个匿名的回调函数(又名匿名回调函数)。conv和是传递给回调函数的params参数/参数。该函数的定义似乎在 API 的这个页面上:Callable。它统计可以传入的参数/参数可以是conv, params, argument, status.

最后的想法

google 上的操作的 API 文档有所帮助:google api 参考链接上的操作

于 2019-01-01T19:49:57.687 回答