Search code examples
google-assistant-sdk

Getting Unsuccessful webhook call: Failed to translate JSON to ExecuteHttpResponse for table in @assistant/conversation


I am trying to show a table in my cloud function using the new @assistant/conversation with the array of data but when i test the action i am getting the error as below

Unsuccessful webhook call: Failed to translate JSON to ExecuteHttpResponse

But when i check the logs i am getting the row values like below

 {
  "responseJson": {
    "session": {
      "id": "ABwppHE5M8EGlWf3YmpUUGPQ5xxHh-cb2QYyF_YUarZbF_jXq-Ad2iKDtyI8XAyvWPp4hHnQockBWMZuQA",
      "params": {},
      "languageCode": ""
    },
    "prompt": {
      "override": false,
      "content": {
        "table": {
          "button": {},
          "columns": [
            "Date",
            "Time",
            "Place"
          ],
          "image": {},
          "rows": [
            "20-10-2020",
            "11:20",
            "Test"
          ],
          "subtitle": "",
          "title": ""
        }
      }
    }
  }
}

Here is the implementation of my adding table in the conv

const tempDatas = ['20-10-2020', '11:20', 'Test'];
  conv.add(
    new Table({
      dividers: true,
      columns: ['Date', 'Time', 'Place'],
      rows: tempDatas
    })
  );

I have used the same logic in google-actions plugin there it works fine.I have imported the Table like below

const { conversation, Table } = require('@assistant/conversation');

Solution

  • Fixed the issue. The structure provided by the new actions builder is little different with the old one

    New Structure:

    conv.add(new Table({
        'title': 'Table Title',
        'subtitle': 'Table Subtitle',
        'image': ASSISTANT_LOGO_IMAGE,
        'columns': [{
          'header': 'Column A',
        }, {
          'header': 'Column B',
        }, {
          'header': 'Column C',
        }],
        'rows': [{
          'cells': [{
            'text': 'A1',
          }, {
            'text': 'B1',
          }, {
            'text': 'C1',
          }],
        }, {
          'cells': [{
            'text': 'A2',
          }, {
            'text': 'B2',
          }, {
            'text': 'C2',
          }],
        }, {
          'cells': [{
            'text': 'A3',
          }, {
            'text': 'B3',
          }, {
            'text': 'C3',
          }],
        }],
      }));
    

    You can simplify it like below that is the solution for my above issue

    const tableRows = [];
    tablesRows.push({ 'cells': [{ 'text': moment(data.date).format('DD-MM-YYYY') }, { 'text': data.time }, { 'text': data.place }] });
    
    
    conv.add(new Table({
        'columns': [{
          'header': 'Date',
        }, {
          'header': 'Time',
        }, {
          'header': 'Place',
        }],
        'rows': tablesRows,
      }));
    
    

    For more info visit conversation components