[英]Dialogflow Fulfillment Webhook - Request Payload is always blank
I have tried automated Fulfillment Webhook and Coded in Node in the inline editor, but I can't seem to get the PAYLOAD populated.我已经在内联编辑器中尝试了自动化的 Fulfillment Webhook 和 Coded in Node,但我似乎无法填充 PAYLOAD。 I successfully connect to my API, but it is looking for the orderNumber in the PAYLOAD which is empty?我成功连接到我的 API,但它正在寻找 PAYLOAD 中为空的 orderNumber? What is needed to get the Payload to contain my parameters?需要什么才能让有效负载包含我的参数?
Intent Image Intent Pic 1意图图片意图图片1
Intent Pic 2 Intent Pic 2意向图 2意向图 2
Below info from the Diagnostic Info以下来自诊断信息的信息
{
"responseId": "7b8c877b-fc06-405a-8428-1959493f870d-a14fa99c",
"queryResult": {
"queryText": "10620054",
"parameters": {
"orderNumber": "10620054"
},
"allRequiredParamsPresent": true,
"outputContexts": [
{
"name": "projects/rrd-order-bot-cxniiq/agent/sessions/199d2c42-4d42-15b6-6329-b116a51991e9/contexts/order",
"lifespanCount": 5,
"parameters": {
"orderNumber": "10620054",
"orderNumber.original": "10620054"
}
},
{
"name": "projects/rrd-order-bot-cxniiq/agent/sessions/199d2c42-4d42-15b6-6329-b116a51991e9/contexts/status",
"lifespanCount": 5,
"parameters": {
"orderNumber": "10620054",
"orderNumber.original": "10620054"
}
},
{
"name": "projects/rrd-order-bot-cxniiq/agent/sessions/199d2c42-4d42-15b6-6329-b116a51991e9/contexts/status",
"lifespanCount": 5,
"parameters": {
"orderNumber": "10620054",
"orderNumber.original": "10620054"
}
}
],
"intent": {
"name": "projects/rrd-order-bot-cxniiq/agent/intents/9a5f61e5-e2cc-44c9-8cb3-53a5d43ec0fc",
"displayName": "Order information"
},
"intentDetectionConfidence": 0.01,
"languageCode": "en"
},
"originalDetectIntentRequest": {
"payload": {}
},
"session": "projects/rrd-order-bot-cxniiq/agent/sessions/199d2c42-4d42-15b6-6329-b116a51991e9"
}
Below is the Inline editor code I have tried in addition to the automatic Webhook.下面是除了自动 Webhook 之外我尝试过的内联编辑器代码。
// 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 {Card, Suggestion} = require('dialogflow-fulfillment');
//var querystring = require('querystring');
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 orderHandler(agent) {
const order = agent.parameters.orderNumber;
const https = require('https');
const querystring = require('querystring');
const parameters = {orderNumber: order};
const post_data = querystring.stringify(parameters);
const options = {
hostname: 'xxxxxxxxxxxx', (removed for question)
port: 443,
path: '/RRD_OrderStatusWeb/v1/getRRDOrderStatus',
method: 'POST'
};
const request = https.request(options, (response)=>{
let chunks_of_data = [];
response.on('data', (fragments) => {
chunks_of_data.push(fragments);
});
response.on('end', () => {
let response_body = Buffer.concat(chunks_of_data);
console.log(response_body.toString());
});
response.on('error', (error) => {
console.log(error);
});
});
request.on('error', (error) => {
console.log('Error Code: ' + error.code);
console.log('Error Message: ' + error.message);
});
request.write(post_data);
request.end();
//agent.add('intent called: ' + order);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('Order information', orderHandler);
agent.handleRequest(intentMap);
});
Correct options for my JASON API call are here.我的 JASON API 调用的正确选项在这里。 Currently only chunking response lengths here...目前这里只分块响应长度......
// 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 {Card, Suggestion} = 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(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function orderHandler(agent) {
const order = agent.parameters.orderNumber;
const https = require('https');
// const querystring = require('JSON');
// const parameters = {orderNumber: order};
var auth = "Basic " + new Buffer("userid here" + ":" + "password here").toString("base64");
const post_data = JSON.stringify({
orderNumber: order
});
const options = {
hostname: 'host url here',
port: 443,
path: 'path here',
method: 'POST',
headers: {
'Authorization': auth,
'Content-Type': 'application/json',
'Content-Length': post_data.length
}
};
const request = https.request(options, (response)=>{
var chunks = '';
response.on("data", function (chunk) {
console.log(chunk.length);
chunks += chunk;
});
response.on("end", function () {
const object = JSON.parse(chunks);
console.log(object.length);
console.log(Buffer.byteLength(chunks, 'utf8') / 1024 + " kbytes");
});
});
request.on('error', (error) => {
console.log('Error Code: ' + error.code);
console.log('Error Message: ' + error.message);
});
//agent.add('request data ' + request + post_data);
request.write(post_data);
request.end();
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('Order information', orderHandler);
agent.handleRequest(intentMap);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.