1

Below is the complete code which i am running to show the table in google assistant.

'use strict';
const {Table} = require('actions-on-google');
process.env.DEBUG = 'dialogflow:debug'; 

exports.dialogflowFirebaseFulfillment = 
          functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });

function showTable(){
   const conv = agent.conv();
   agent.add("this is sample table");
   agent.add(new Table({
   dividers: true,
   columns: ['header 1', 'header 2', 'header 3'],
   rows: [
      ['row 1 item 1', 'row 1 item 2', 'row 1 item 3'],
      ['row 2 item 1', 'row 2 item 2', 'row 2 item 3'],
   ],
   }));
 }
 let intentMap = new Map();
 intentMap.set('TableView',showTable); //TableView is my intent name
 agent.handleRequest(intentMap);
});

While running the above code its showing me an below error

TypeError: Table is not a constructor
    at showTable (/user_code/index.js:74:15)
    at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:303:44)
    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:102:9)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
    at /var/tmp/worker/worker.js:735:7
    at /var/tmp/worker/worker.js:718:11
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)
Alok Soni
  • 55
  • 1
  • 8
  • I'm confused. If that is the complete code, where are you importing `WebhookClient`? Can you also include the package.json you're using? – Prisoner Feb 07 '19 at 02:33
  • actually i imported webhookClient and also added in package.json but here i have not put that code, i meant for logic code only. – Alok Soni Feb 07 '19 at 10:54
  • btw its working. only issue was i was using Dialogflow fulfillment library instead of the Actions on Google library and funtion i was using of actions-on-google. – Alok Soni Feb 07 '19 at 10:56
  • I suggest adding an answer that shows what you did so others can learn from it. – Prisoner Feb 07 '19 at 11:14

2 Answers2

0

The most likely cause of this is that you didn't import the Table object with a line such as

const {Table} = require('actions-on-google');
Prisoner
  • 49,922
  • 7
  • 53
  • 105
0

I faced this issue and one probable reason might be the incorrect version of actions-on-google in the package.json file.Usually we used to copy the package.json from existing samples to our new project.So old ones has the version of 2.0.0-alpha.4. Since Table cards are added after that version,the dialogflow throws error.You may use the version- 2.6.0.This worked for me.

Below is my index.js file.

'use strict';
const {dialogflow,Table} = require('actions-on-google');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion,List,Image} = require('dialogflow-fulfillment');

const app= dialogflow({debug:true});

app.intent('Table View Sample',(conv) =>{
  
  conv.ask('This is a simple table example.');
conv.ask(new Table({
  dividers: true,
  columns: ['header 1', 'header 2', 'header 3'],
  rows: [
    ['row 1 item 1', 'row 1 item 2', 'row 1 item 3'],
    ['row 2 item 1', 'row 2 item 2', 'row 2 item 3'],
  ],
}));
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

Below is my package.json file.

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "~6.0"
  },
  "scripts": {
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "2.6.0",
    "firebase-admin": "^4.2.1",
    "firebase-functions": "^0.5.7",
    "dialogflow": "^0.1.0",
    "dialogflow-fulfillment": "0.3.0-beta.3"
  }
}

Hope this helps someone!

Thanks.

vasanth kumar
  • 235
  • 1
  • 3
  • 13