Botbuilder-dotnet: TurnContext.UpdateActivity does not apply a conversation reference

Created on 8 Aug 2019  路  11Comments  路  Source: microsoft/botbuilder-dotnet

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]

4.6 P1 bug

All 11 comments

Same here :(

Some problem here

Some problem here

This has worked for me on Teams C# code:

Send card first time:

```c#
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:

```c#
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

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

I was trying to update the activity on bot framework emulator, but when i do it on Teams it works perfectly

@v-kydela, Thanks! Can you submit a PR for C#?

(and for JS!)

@cleemullins - I've just assigned myself. Expect it done today!

This also applies to delete, and also needs parity.

@Virtual-Josh - I don't see how this applies to delete. DeleteActivityAsync has two overloads and one of them does call GetConversationReference and the other takes a conversation reference as a parameter.

The .NET fix is done. I plan on finishing the Node fix tomorrow and making simultaneous pull requests in each repo.

I have submitted PR's for .NET and Node. I just examined the Python and Java source code and found that the problem exists in them as well, so I will attempt to fix those too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sgellock picture sgellock  路  4Comments

tiagodenoronha picture tiagodenoronha  路  6Comments

brandonh-msft picture brandonh-msft  路  4Comments

brandonh-msft picture brandonh-msft  路  6Comments

cmayomsft picture cmayomsft  路  6Comments