Forum Discussion
Error when trying to update adaptive card
To update the existing card on button selection, you can use ReplyToId of incoming activity.
To update existing card on a button selection, pass a new Activity object with updated card and ReplyToId as activity ID to the UpdateActivityAsync method of the TurnContext class. See TurnContextClass.
var activity = MessageFactory.Attachment(card.ToAttachment());
activity.Id = turnContext.Activity.ReplyToId;
await turnContext.UpdateActivityAsync(activity, cancellationToken);
Ref Doc: Update and delete messages sent from your bot - Teams | Microsoft Docs
Nivedipa-MSFT What if I want to update the adaptive card at some scheduled time? If I store ReplyToId or message id. How I can update a card or message in a particular channel at some point in time?
What are the details I should store and How I can update the card later? And Is there a way to batch update the messages and how to reply to the message and update this message also later?
It will be helpful if you can send the documents required.
- AyeshaKulsumSJSep 09, 2022Brass Contributorconst {BotFrameworkAdapter, TurnContext, TeamsInfo, CardFactory, MessageFactory} = require('botbuilder');const properties = {'membersAdded': [{ 'id': '28:17a' }], 'type': 'conversationUpdate', 'timestamp': '2022-08-11T10:54:30.482Z', 'id': 'f:ce9c82ab7a6feabc', 'channelId': 'msteams', 'serviceUrl': 'https://smba.trafficmanager.net/in/', 'from': { 'id': '29:1YqsjLwgg-0A_V8tL5P3hIw', 'aadObjectId': 'a0858f3e-d57759' }, 'conversation': {'isGroup': true, 'conversationType': 'channel', 'tenantId': '3272b84e1', 'id': '19:PZppMpIo1@thread.tacv2'}, 'recipient': { 'id': '28:17720bfc7ba', 'name': 'bot 1' }, 'channelData': {'team': { 'aadGroupId': '9ffd4120579', 'name': 'Ayesha Testing', 'id': '19:PZp9pIo1@thread.tacv2' }, 'eventType': 'teamMemberAdded', 'tenant': { 'id': '3284e1' }, 'settings': { 'selectedChannel': { 'id': '19:PZ1@thread.tacv2' } }}};const BotConnector = require('botframework-connector');const adapter = new BotFrameworkAdapter({appId: '',appPassword: ''});BotConnector.MicrosoftAppCredentials.trustServiceUrl(properties.serviceUrl);const context = new TurnContext(adapter, properties);var message1 = await context.sendActivity('Hi');console.log(message1);var reference = TurnContext.getReplyConversationReference(context.activity, message1);console.log(reference);I am sending message as above and storing details required. Then later at some scheduled timed I have to update message to some other message as below. But it is not working as expected.const newActivity = MessageFactory.attachment({'type': 'AdaptiveCard','$schema': 'http://adaptivecards.io/schemas/adaptive-card.json','version': '1.5','body': [{'type': 'TextBlock','text': 'Nobody has replied to this poll yet','wrap': true}]});BotConnector.MicrosoftAppCredentials.trustServiceUrl(properties.serviceUrl);const newcontext = new TurnContext(adapter, properties);newActivity.id = reference.activityId;console.log(newcontext);newcontext.updateActivity(newActivity);Logs -(node:19905) UnhandledPromiseRejectionWarning: Error: ContentType of an attachment is not set
at new RestError (/Users/ayeshakulsumsj/Documents/project/app/app-v1/node_modules/@azure/ms-rest-js/dist/msRest.node.js:1403:28)
at /Users/ayeshakulsumsj/Documents/project/app/app-v1/node_modules/@azure/ms-rest-js/dist/msRest.node.js:2528:37
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19905) UnhandledPromiseRejectionWarning:- AyeshaKulsumSJSep 11, 2022Brass Contributor
AyeshaKulsumSJ Issue is fixed