question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TurnContext.UpdateActivity does not apply a conversation reference

See original GitHub issue

Version

Latest

Describe the bug

TurnContext.SendActivitiesAsync uses Activity.GetConversationReference and Activity.ApplyConversationReference to ensure that outgoing activities have all the information the adapter and the connector client need in order to send the activities. This allows TurnContext.SendActivityAsync to work with activities that were generated using MessageFactory rather than just activities that were generated using Activity.CreateReply (which I have been advised to not use anymore). However, TurnContext.UpdateActivityAsync does not apply a conversation reference to its activity, so in order to update an activity using MessageFactory you have to set the new activity’s Conversation property manually. This is unintuitive.

To Reproduce

Steps to reproduce the behavior:

  1. Generate a new activity using a static method from the MessageFactory class
  2. Set the new activity’s Id property using a saved resource response ID
  3. Use the new activity as the argument in TurnContext.UpdateActivityAsync
  4. See null reference exception

Expected behavior

TurnContext.UpdateActivityAsync should use the available conversation information just like TurnContext.SendActivityAsync.

Screenshots

Exception

Additional context

I am happy to submit a PR for this myself if I am assigned to it.

[bug]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
v-kydelacommented, Aug 20, 2019

I have noticed that in the Node.js SDK, you must not only set the updated activity’s conversation property but also its serviceUrl property

1reaction
josecarvajalregocommented, Sep 12, 2019

Some problem here

This has worked for me on Teams C# code:

Send card first time:

IMessageActivity originActivity = MessageFactory.Attachment(_actionsCard.CreateAdaptiveCardActions("jose"));
userProfile.ConversationId = turnContext.Activity.Conversation.Id;
var response = await turnContext.SendActivityAsync(originActivity, cancellationToken);
userProfile.PreviousActivityId = response.Id;

Update card:

IMessageActivity responseActivity = MessageFactory.Attachment(_logTimeCard.CreateLogTimeCard2("2"));
responseActivity.Id = userProfile.PreviousActivityId;
responseActivity.Conversation = turnContext.Activity.Conversation;
await turnContext.UpdateActivityAsync(responseActivity, cancellationToken);

Let me know if you need further assistance

Read more comments on GitHub >

github_iconTop Results From Across the Web

TurnContext updateActivity method not working with MS ...
I have used this stackoverflow post as a reference while creating the application. Unfortunately it does not work for me.
Read more >
TurnContext class
This activity, updated with the delivery information. Remarks. Call the getConversationReference method on an incoming activity to get a conversation reference ...
Read more >
ActivityHandler.OnConversationUpdateActivityAsync Method
Invoked when a conversation update activity is received from the channel when the base behavior of OnTurnAsync(ITurnContext, CancellationToken) is used.
Read more >
Untitled
Turncontext Microsoft Bot Framework Chatbot Afour Tech WebThis method returns a reference to the turn ... UpdateActivity does not apply a conversation …...
Read more >
botbuilder@4.20.0
To copy the reference from any incoming activity in the conversation, use the [TurnContext.getConversationReference](xref:botbuilder-core.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found