BotFramework-Emulator icon indicating copy to clipboard operation
BotFramework-Emulator copied to clipboard

Crash on sending .suggestedActions with builder.Message()

Open ronak-itility opened this issue 9 years ago • 9 comments

Added task list based on below discussion.


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);
      }
      );

ronak-itility avatar May 17 '17 14:05 ronak-itility

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);

eanders-ms avatar May 17 '17 20:05 eanders-ms

And it seems our documentation is incorrect on the page you referenced. We'll get that updated. Thank you for the report!

eanders-ms avatar May 17 '17 20:05 eanders-ms

@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.

ronak-itility avatar May 18 '17 07:05 ronak-itility

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.

eanders-ms avatar May 18 '17 16:05 eanders-ms

Suggestion added at issue #2798 on BotBuilder

ronak-itility avatar May 18 '17 19:05 ronak-itility

Issue appears resolved. Closing it out.

eanders-ms avatar May 18 '17 20:05 eanders-ms

I thought updating the Bot documentation was part of resolving the issue ?

ronak-itility avatar May 19 '17 06:05 ronak-itility

A pull request has been made to the docs and is working its way to production. Should be live in a day or two.

eanders-ms avatar May 19 '17 16:05 eanders-ms

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

eanders-ms avatar May 22 '17 17:05 eanders-ms