Crash on sending .suggestedActions with builder.Message()
Added task list based on below discussion.
- [x] Update Documentation
- [x] Place Feature request. Placed at #2798 on BotBuilder
Earlier similar issue: #10
Follow messages popsup in emulator:
[16:09:33] [err-client] Uncaught TypeError: Cannot read property 'length' of undefined /Applications/botframework-emulator.app/Contents/Resources/app/node_modules/rxjs/Subscriber.js 227 13 {}
Development environment:
- Run on localhost on
http://localhost:3978/api/messages - Bot Framework Emulator version 3.5.29
"botbuilder": "^3.8.3"- example: Add suggested actions to message on Bot Framework documentation
Code:
// LUIS intent declaration
const recognizer = new builder.LuisRecognizer(LuisRestFilterModelUrl);
const intents = new builder.IntentDialog({ 'recognizers': [recognizer] });
bot.dialog('/', intents);
intents.onBegin(
(session,args) => {
let msg = new builder.Message(session)
.text("Thank you. Short message.")
.suggestedActions([
builder.CardAction.imBack(session, "productId=1&color=green", "Green"),
builder.CardAction.imBack(session, "productId=1&color=blue", "Blue"),
builder.CardAction.imBack(session, "productId=1&color=red", "Red")
]);
session.send(msg);
}
);
Hi @ronak-itility, it seems your suggested actions payload isn't getting constructed correctly. Try this slight variation (based on https://github.com/Microsoft/BotBuilder/tree/master/Node/examples/feature-suggestedActions):
let msg = new builder.Message(session)
.text("Thank you. Short message.")
.suggestedActions(
builder.SuggestedActions.create(
session, [
builder.CardAction.imBack(session, "productId=1&color=green", "Green"),
builder.CardAction.imBack(session, "productId=1&color=blue", "Blue"),
builder.CardAction.imBack(session, "productId=1&color=red", "Red")
]
));
session.send(msg);
And it seems our documentation is incorrect on the page you referenced. We'll get that updated. Thank you for the report!
@eanders-MS can you elaborate on your solution, what difference it made internally in the bot operation and what change on response happened that emulator is able to handle it well. Also in the code base of bot, can you point out the code block that affected this behavior ? Thank you.
PS: Also though this works, earlier form is more intuitive, and i think thats how it should form the suggestedActions.
The suggestedActions field on the activity is expecting an object structured like the interface ISuggestedActions, rather than a simple array of CardActions. When the emulator (or more accurately, the WebChat control) tried to read the suggestedActions field, it didn't find the actions member and threw an exception.
PS: Also though this works, earlier form is more intuitive, and i think thats how it should form the suggestedActions.
I agree, and it seems reasonably straight forward to add support for this. I urge you to file a suggestion over at the BotBuilder repo.
Suggestion added at issue #2798 on BotBuilder
Issue appears resolved. Closing it out.
I thought updating the Bot documentation was part of resolving the issue ?
A pull request has been made to the docs and is working its way to production. Should be live in a day or two.
The live docs have been updated with the new code sample: https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-send-suggested-actions