dialogflow / dialogflow-fulfillment-nodejs

Dialogflow agent fulfillment library supporting v1&v2, 8 platforms, and text, card, image, suggestion, custom responses
Apache License 2.0
598 stars 281 forks source link

Sending custom payloads when requestSource is null #235

Open uusimaeki opened 5 years ago

uusimaeki commented 5 years ago

I am using my own platform for publishing chatbots. I am able to use fullfilment for sending simple messages like agent.add('message'), but when I try to send customPayloads I am having problems. Problem is that platform-field is required, but my agent.requestSource field is null.

Here is my fullfilment code:

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

  function test_intent(agent) {
    agent.add('This message works'); // THIS WORKS
    agent.add('Source: '+ agent.requestSource); // THIS GIVES: "Source: null"
    agent.add(new Payload(agent.ACTIONS_ON_GOOGLE, { 
      "action" : {
       "buttons": {
         "title": "title",
         "buttons": [
           {
             "text": "text 1",
             "value": "value 1"
           },
           {
             "text": "text 2",
             "value": "value 2"
           }
         ]
       }
     } 
    })); // THIS DOES NOT WORK
  }

  let intentMap = new Map();
  intentMap.set('0_Test_intent', test_intent);
  agent.handleRequest(intentMap);
});

How should I define platform for payload?

uusimaeki commented 5 years ago

Any comments?

gpjyothish commented 3 years ago

Can you please refer to this one: https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/267 Maybe this will help.