TurnContext.SendActivitiesAsync changes the activities' ID
See original GitHub issueVersion
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:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
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
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.