suggested actions disappear after click in directline

丶灬走出姿态 提交于 2021-01-05 13:00:14

问题


I have configured directline channel to Microsoft bot framework v4 with node js. I have suggested actions in welcome message. when I clicked any suggested action it disappear in UI but its response receiving to bot.

var msg =  MessageFactory.suggestedActions(
        CardFactory.actions([
                        {
                            type: 'messageBack',
                            title: 'xyz',
                            value: 'xyzDialog'
                        }]),'please select choice');

  await    context.sendActivity(msg);

could you please guide me how can I make it appear clicked suggested action to end user?

Thanks in advance.


回答1:


As per the documentation here:

Unlike buttons that appear within rich cards (which remain visible and accessible to the user even after being tapped), buttons that appear within the suggested actions pane will disappear after the user makes a selection. This prevents the user from tapping stale buttons within a conversation and simplifies bot development (since you will not need to account for that scenario).

So in short, you cannot achieve your desired outcome with suggested actions. You have a couple of options:

  1. Handle the suggest action in your bot code and send a reply back to the user thanking them for their input (and potentially repeating their input back to them "thank you for selecting X").
  2. Using a CardAction instead, as per this dated sample.
  3. Use an adaptive card (the new way), there is a sample available here, along with a detailed guide.

The downside of the last two approaches is that users will be able to repeatedly click on these buttons so your bot must handle multiple submissions in the backend.




回答2:


For information on Suggest action using button.

    var msg = MessageFactory.suggestedActions(['x', 'y', 'z'], 'please select choice?');
    await turnContext.sendActivity(msg);

also suggestedActions need IEnumerable<CardAction> see MessageFactory.SuggestedActions Method the code will be

var msg = MessageFactory.SuggestedActions(
       new CardAction[]
       {
           new CardAction(title: "x", type: ActionTypes.ImBack, value: "x"),
           new CardAction( title: "y", type: ActionTypes.ImBack, value: "y"),
           new CardAction(title: "z", type: ActionTypes.ImBack, value: "z")
       }, text: "please select choice");

   // Send the activity as a reply to the user.
   await context.SendActivity(msg);


来源:https://stackoverflow.com/questions/60595804/suggested-actions-disappear-after-click-in-directline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!