Я пробовал автоматизировать Fulfillment Webhook и Coded in Node во встроенном редакторе, но мне не удается заполнить PAYLOAD. Я успешно подключился к своему API, но он ищет orderNumber в PAYLOAD, который пуст? Что нужно для того, чтобы полезная нагрузка содержала мои параметры?
Intent Image Intent Pi c 1
Intent Pi c 2 Intent Pi c 2
Ниже информация из Диагностики c Информация
{
"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"
}
Ниже приведен код встроенного редактора, который я пробовал в дополнение к автомату c 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);
});