Table rows cannot have empty strings
See original GitHub issueI 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:
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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
I can no longer reproduce this. A cell with an empty string will render without throwing an exception.
I’ve filed a bug internally about updating the documentation.