在创建 [此处] https://dialogflow.com/docs/reference/fulfillment-library/rich-responses#new_payloadplatform_payload中记录的有效负载对象的构造函数时,需要platform
和payload
参数。
new Payload(platform, payload)
该platform
参数是 WebhookClient 对象的一个属性,应该这样定义(agent.SLACK、agent.TELEGRAM 等)假设 webhookClient 已实例化并存储在agent
例子:
agent.add(new Payload(agent.ACTIONS_ON_GOOGLE, {/*your Google payload here*/});
agent.add(new Payload(agent.SLACK, {/*your Slack payload here*/});
agent.add(new Payload(agent.TELEGRAM, {/*your telegram payload here*/});
参考:https ://blog.dialogflow.com/post/fulfillment-library-beta/ 。
对于我在问题中概述的用例,这是我的完整解决方案:
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Text, Card, Image, Suggestion, Payload} = require('dialogflow-fulfillment');
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(new Payload(agent.TELEGRAM, {
"text": "Please click on button below to share your number",
"reply_markup": {
"one_time_keyboard": true,
"resize_keyboard": true,
"keyboard": [
[
{
"text": "Share my phone number",
"callback_data": "phone",
"request_contact": true
}
],
[
{
"text": "Cancel",
"callback_data": "Cancel"
}
]
]
}
}));
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
agent.handleRequest(intentMap);
});