The conversation page in the Teams Dev Docs lists a scenario that I am trying to implement:
Updating messages
Rather than have your messages be static snapshots of data, your bot can dynamically update messages inline after sending them. You can use dynamic message updates for scenarios such as poll updates, modifying available actions after a button press, or any other asynchronous state change.
In my code, I create a message and attach an Adaptive card.
var cardReply = activity.CreateReply();
cardReply.AddAdaptiveCard(card);
If I reply to the user using PostAsync
, then I do not get the ResponseResourceId
that I need to update the reply.
// PostAsync return Task, no ResourceResponse
await context.PostAsync(cardReply);
// OnDataItemInput is called when Action.Submit is triggered
context.Wait(this.OnDataItemInput);
If instead, I reply to the activity, then the continuation delegate (context.Wait
) is not called. The continuation that is executed is the previous dialog on the stack.
// OnDataItemInput is never called
context.Wait(this.OnDataItemInput);
ConnectorClient connector =
new ConnectorClient(new Uri(activity.ServiceUrl));
var cardReplyResource = await connector
.Conversations
.ReplyToActivityAsync(cardReply);
How do I send an AdaptiveCard
with input items and have the bot wait for the Action.Submit
response?
The activity message generated by the user pressing the Submit button, received by your bot, will have a replyToId
field -- that's the ID of the message you want to update.
If you need a way to distinguish these activity messages from others, you can give the Action.Submit button an id
or use its data
field - the value
object of the activity will tell you that.