- Notifications
You must be signed in to change notification settings - Fork194
Table rows cannot have empty strings #250
Description
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:
consttimetableCells=timetable.Trains.map((item)=>{return{cells:[item.Line,item.Destination,item.Car,item.Min],}})conv.ask(newTable({title:`Rail Timetable for${station}`,subtitle:'Timetable as of x date',image:newImage({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:newButton({title:'Button Title',url:'https://github.com/actions-on-google'})}))
The returned data fromtimetable looks like this and the array I'm generating from map followed the correct schema forrows, 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 cellscannot 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:
consttimetableCells=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 thedocumentation if it's indeed intended and not a bug.
