I have a serverless app where I want to run my logic from the chatbot request coming from Facebook Messenger. When I run the intent function for test_handler I get the correct response back. But after I added another handler for skillRatio I seem to be getting the error in the title i.e
Error: Platform can NOT be empty at new Payload
. My code is as below.
const serverless = require('serverless-http');
const bodyParser = require('body-parser');
const express = require('express');
const app = express();
app.use(bodyParser.json({ strict: false }));
const {WebhookClient, Payload, Image, Card, Suggestion} = require('dialogflow-fulfillment');
const request = require('request');
app.get('/', function (req, res) {
  res.send('Hello World !!!\n');
  console.log("Testing express lambda\n");
})
app.post('/', function (req, res) {
    const agent = new WebhookClient({request: req, response: res});
    function test_handler(agent) {
      agent.add(`Welcome to my agent on AWS Lambda!`);
      agent.add(new Image("https://image-charts.com/chart?chs=700x190&chd=t:60,40&cht=p3&chl=Hello%7CWorld&chf=ps0-0,lg,45,ffeb3b,0.2,f44336,1|ps0-1,lg,45,8bc34a,0.2,009688,1"))
    }
    function skillRatio(agent) {
      agent.add(`Let me just have a look and I'll gather the data. *Processing Chart Data....Mmmm Pie*. 
        Here we go! Here is the data on your $Skills.original request.`);
      //agent.add(`Feel free to save or share :)`);
      //agent.add(new Image("https://image-charts.com/chart?chs=700x190&chd=t:60,40&cht=p3&chl=Hello%7CWorld&chf=ps0-0,lg,45,ffeb3b,0.2,f44336,1|ps0-1,lg,45,8bc34a,0.2,009688,1"))
    }
    // Run the proper function handler based on the matched Dialogflow intent name
    let intentMap = new Map();
    intentMap.set('super-test', test_handler);
    //intentMap.set('skill-ratio', skillRatio);
    if (agent.requestSource === agent.FACEBOOK) {
      intentMap.set('super-test', test_handler);
      intentMap.set('skill-ratio', skillRatio);
    } else {
    }
    agent.handleRequest(intentMap);
})
module.exports.handler = serverless(app);
Dialogflow Images:
I am trying to run the code on Messenger. Any help would be hugely appreciated as I am so stuck trying to get my head around this.




