New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table rows cannot have empty strings #250

Open
JamesIves opened this Issue Nov 26, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@JamesIves
Copy link

JamesIves commented Nov 26, 2018

I ran into this the other day and it took a really long time to figure out, I'm not really sure if this is a bug or not but figured I'd bring this to your attention.

Failed to parse Dialogflow response into AppResponse

In my case I was generating a table with some data from an API endpoint like so:

const timetableCells = timetable.Trains.map((item) => {
  return {
    cells: [item.Line, item.Destination, item.Car, item.Min],
  }
})

conv.ask(new Table({
  title: `Rail Timetable for ${station}`,
  subtitle: 'Timetable as of x date',
  image: new Image({
    url: 'http://google.com/image.png',
    alt: 'Logo'
  }),
  columns: [
    {
      header: 'Line',
      align: 'LEADING'
    },
    {
      header: 'Destination',
      align: 'LEADING'
    },
    {
      header: 'Car',
      align: 'LEADING'
    },
    {
      header: 'Arrival',
      align: 'LEADING'
    },
  ],
  rows: timetableCells,
  buttons: new Button({
    title: 'Button Title',
    url: 'https://github.com/actions-on-google'
  })
}))

The returned data from timetable looks like this and the array I'm generating from map followed the correct schema for rows, as far as I could tell there should have been no issues as the generated JSON was valid.

{"Trains":[{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"9"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"18"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"36"},{"Car":"8","Destination":"Shady Gr","DestinationCode":"A15","DestinationName":"Shady Grove","Group":"2","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":""}]}

timetableCells:

screen shot 2018-11-26 at 8 29 13 am

DialogFlow kept throwing a JSON parsing error and I couldn't seem to figure out what the issue was, it was obvious to me that the data length needed to match the headers, but what wasn't obvious was that data in row cells cannot be empty strings. Sometimes the API endpoint returns empty strings for some data that isn't available yet. I resolved the issue with the following:

const timetableCells = timetable.Trains.map((item) => {
  return {
    cells: [item.Line || "N/A", item.Destination || "N/A", item.Car || "TBD", item.Min || "TDB"],
  }
})

I spent quite a long time debugging this, and I think this would be a good addition to the documentation if it's indeed intended and not a bug.

@JamesIves

This comment has been minimized.

Copy link

JamesIves commented Nov 26, 2018

I tried to address this within this repo but I guess the error isn't being thrown here after looking into the code. I'll gladly post this in the right repository if pointed in the right direction.

@Fleker

This comment has been minimized.

Copy link
Member

Fleker commented Nov 27, 2018

The error probably happens on the Google Assistant side after it processes your webhook response.

@JamesIves

This comment has been minimized.

Copy link

JamesIves commented Nov 27, 2018

Is there a correct repo or team at Google I can inform of this issue? I’ll happily fix it myself and PR it if the parser is open source!

@Fleker

This comment has been minimized.

Copy link
Member

Fleker commented Nov 27, 2018

The server-side parts of the Google Assistant are not open source. Any fixes would need to be done on the side of the developer to validate the input before it is returned (plus adding a note in the documentation).

@JamesIves

This comment has been minimized.

Copy link

JamesIves commented Dec 1, 2018

Where can I file the bug report?

@Fleker

This comment has been minimized.

Copy link
Member

Fleker commented Dec 3, 2018

I've filed a bug internally about updating the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment