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.SendActivitiesAsync changes the activities' ID

See original GitHub issue

Version

master

Describe the bug

On this line, we can see where the turn context modifies the ID of each outgoing activity:

activity.Id = responses[index].Id;

While outgoing activities are necessarily modified when a conversation reference is applied, modifying the ID based on the resource response creates strange behavior when the activity is saved and used again, like when it’s a retry prompt. The Emulator for example will not display an activity if the ID is the same as an activity already in the conversation history. Several customers are running into issues because of this: https://github.com/microsoft/BotFramework-Emulator/issues/1684 https://stackoverflow.com/questions/58082537/why-does-the-retry-prompt-only-show-once

The turn context in the Node SDK does not modify an outgoing activity’s ID.

Expected behavior

There is reason to think that simply sending an activity shouldn’t modify it at all, even by applying the conversation reference. That is to say, the necessary modifications should be done on a copy of the activity that gets passed to SendActivityAsync for example. However, changing this now could be breaking behavior if some bots expect the activity to be modified. Also, an easy workaround is to send an activity through the adapter or the connector, so bot developers have a choice about whether they want outgoing activities to be modified automatically.

The ID in particular may be a special case for a few reasons. Not only is this modification causing the issues we see in Emulator, but the behavior is inconsistent between repos. Even if we don’t want to change this ID-modifying behavior in the .NET SDK, we should still make sure the different SDK’s work the same way.

[bug]

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
EricDahlvangcommented, Nov 22, 2019

It would likely break existing tests and bots if we were to change the behavior of setting the activity.id to resourceresponse.id. However, to bring things more inline with the spec we are now ensuring the outgoing activity does not have an .id

ref: A2031: Clients and bots SHOULD NOT include an id field in activities they generate.

javascript

dotnet

Finally, the emulator will also no longer respect ids sent to it: emulator

0reactions
EricDahlvangcommented, Nov 26, 2019

I don’t know, since i didn’t write it. But I’m sure whoever did, did so on purpose.

The bug is fixed and the sdk is no longer sending ids for messages. Setting the id of the outgoing activity is by design, so closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TurnContext.SendActivityAsync Method
If the activity is successfully sent, the task result contains a ResourceResponse object containing the ID that the receiving channel assigned to the...
Read more >
Implement custom storage for your bot - Bot Service
The custom SendActivitiesAsync method shouldn't send the activities to the use, but add the activities to a list. Your dialog code won't need ......
Read more >
Bot throws "Operation returned an invalid status code ...
using the TurnContext await command.TurnContext.SendActivitiesAsync(activities); activities argument is of type IMessageActivity[] .
Read more >
How do I return a Typing activity from my v4 Bot
Type = ActivityTypes.Typing; await turnContext.SendActivityAsync(act2);. all of these result in a BadGateway error. Can someone guide me on ...
Read more >
Changing the service url for a direct line activity that is sent to ...
TurnContext.SendActivities calls BotAdapter.SendActivitiesAsync , and if you're using a BotFrameworkAdapter then that in turn calls Conversations.
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