Anand Shaw
Anand Shaw

Reputation: 229

dialogflow webhook fulfilment code fails

I am trying to integrate Alexa with Dialogflow and using dialogflow to fulfil intent request. For static intent response i am able to get response correctly but when i am trying to integrate webhook for fullfillment, i am getting below exception dialogflow :

TypeError: Cannot read property 'source' of undefined at V2Agent.processRequest_ (/user_code/node_modules/dialogflow-fulfillment/src/v2-agent.js:108:86) at new WebhookClient (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:193:17) at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:26:18) at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47) at /var/tmp/worker/worker.js:684:7 at /var/tmp/worker/worker.js:668:9 at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickDomainCallback (internal/process/next_tick.js:128:9)

Below is the code i am using for the fulfillment webhook :

'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 orcacall () {
      response.setHeader('Content-Type','application/json');
      response.send(JSON.stringify({'speech':'myMessage','displayText':'myMessage','data':[],'contextOut':[]}));


  }
let intentMap = new Map();
  intentMap.set('Orca', orcacall);
  agent.handleRequest(intentMap);
});

Upvotes: 2

Views: 1279

Answers (2)

iCPSoni
iCPSoni

Reputation: 136

May be it's too late to post

Your orcacall() function needs an argument agent So Change it to

console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

  function orcacall (agent) { //Here agent is added
      response.setHeader('Content-Type','application/json');

This argument is useful in using parameters and also posting the responses.

Upvotes: 0

Ali Nem
Ali Nem

Reputation: 5530

Sorry, only after posting my answer I found out that you've already got your answer from the comments.

Your orcaCall function needs an agent argument. Change it to this:

function orcacall (agent) {
  response.setHeader('Content-Type','application/json');
  response.send(JSON.stringify({'speech':'myMessage','displayText':'myMessage','data':[],'contextOut':[]}));  }

Upvotes: 1

Related Questions