简体   繁体   English

Dialogflow Fulfillment Webhook - 请求有效负载始终为空

[英]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.

相关问题 Dialogflow webhook 实现参数无法访问 - Dialogflow webhook fulfillment parameter not accessible Dialogflow-履行请求的有效负载-如何使用在请求有效负载中收到的用户ID注册用户 - Dialogflow - Fulfillment request pay load - How to register the user with user id received in request payload 如何制作多语言Dialogflow Webhook /实现? - How to make a multiple language Dialogflow webhook/fulfillment? Dialogflow webhook 实现参数在 post API 中不起作用 - Dialogflow webhook fulfillment parameter is not working in post API 如何使用 nodejs 在 Dialogflow 中处理 webhook 实现 - How to handle webhook fulfillment in Dialogflow using nodejs 如何使用Node.js或Python在对话框流实现中使用custom_payload - How to use custom_payload in dialogflow fulfillment using nodejs or python 如何在环境Dialogflow->实现中发出http请求? - How do I make a http request in the environment Dialogflow -> Fulfillment? 使用Dialogflow实现的简单HTTP get API请求 - Simple HTTP get request to API using Dialogflow fulfillment Dialogflow NodeJs V2-Webhook方法调用在完成回调之前结束 - Dialogflow NodeJs Fulfillment V2 - webhook method call ends before completing callback 如何在不使用 webhook 客户端的情况下设置 dialogflow fulfillment response json 上下文? - How to set dialogflow fulfillment response json context without using webhook client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM