I'm working on a Bot with the Bot Framework v4 in C#. What I want now is, that after sending an Adaptive Card to the user, with Actions, that I can update this card after the Action is fired. For example, that the button will disappear after the click.
here I have a Solution in NodeJS, but I'm not able to transfer it to C#. Can anybody help?
More Project details:
I have an Adaptive Card that looks like this:
This Card will be generated, after I searched with the MS Graph from a SharePoint Library.
The Main Goal is, that i can use the Refiners to update the Card with a new Card from JSON. The "OK" button is a Submit Action which can be catched in the OnMessageActivityAsync Method. The Input Values are in the Activity Value so can create a Filter Method. my Problem is, that I can't update the Card that is already send to the User.
Before I sended the first Card with the Results to the User I write the Activity into a State, so I can Access OnMessageActivityAsync Method, but I'm not sure if this is the right approach.
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
Logger.LogInformation("Running dialog with Message Activity.");
var txt = turnContext.Activity.Text;
dynamic val = turnContext.Activity.Value;
// Check if the activity came from a submit action
if (string.IsNullOrEmpty(txt) && val != null)
{
await turnContext.SendActivityAsync(MessageFactory.Text($"Refiner Language: {val.id_language}"));
await turnContext.SendActivityAsync(MessageFactory.Text($"Refiner MachType: {val.id_type}"));
var r = new StreamReader("Cards/helloCard2.json");
string json = r.ReadToEnd();
AdaptiveCard card = AdaptiveCard.FromJson(json).Card;
var docSearchState = await StateAccessor.GetAsync(turnContext);
Activity activity = docSearchState.Activity;
activity.Attachments = new List<Attachment>() {
new Attachment()
{
Name = "Card",
ContentType = AdaptiveCard.ContentType,
Content = card,
}
};
await turnContext.UpdateActivityAsync(activity);
}
This Code gives me the following Error Message:
fail: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter[0]
Exception caught : Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path 'DocumentSearchState.Activity.attachments.$values[0].content.body'.
Has anybody a good idea to solve this?