问题
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:
- 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").
- Using a CardAction instead, as per this dated sample.
- 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