botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Why do messages addressed to a user with conversation id not appear immediately to that user?

Open vaditya04 opened this issue 10 years ago • 11 comments

User1 is in an active conversation with a bot.

Let's say some instance of the bot sends a message to User1 with the active conversation id.

That message is not presented to user1 unless he messages the bot again, upon which both the bot's response and the sent message are printed to the user

(observed on webchat)

Edit:

Example: Bot sends "Testing message"

User sees nothing

User sends bot "Hello"

Response:

"Testing message"

"Hi! I'm a bot"

vaditya04 avatar Jun 23 '16 17:06 vaditya04

Are you using C# or node.js?

chrimc62 avatar Jun 23 '16 18:06 chrimc62

I'm using C#

vaditya04 avatar Jun 24 '16 03:06 vaditya04

@chrimc62 Another attempt at explaining:

User 1 talks to bot which messages User 2 on conversation Y, what happens is User 2 doesn't see anything. But when User 2 talks to the bot, both the User 1 message and the bot's response appear on screen for User 2 as a response. I've edited the question to explain it better.

vaditya04 avatar Jun 24 '16 03:06 vaditya04

What version of the SDK are you running?

chrimc62 avatar Jun 24 '16 18:06 chrimc62

@chrimc62 Bot Builder is v1.2.2 Bot connector is v1.1.0

vaditya04 avatar Jun 25 '16 09:06 vaditya04

@chrimc62 I've narrowed the issue down to the fact that the message sent to that conversationId is printed whenever the next context.Wait is called on the corresponding bot instance, and not before that

vaditya04 avatar Jun 25 '16 18:06 vaditya04

@chrimc62 Context.Wait suspends the bot, perhaps that is why it's not able to send the message to webchat?

vaditya04 avatar Jun 25 '16 19:06 vaditya04

@vaditya04 I think the phenomenon you're seeing is explained by this code:

https://github.com/Microsoft/BotBuilder/blob/develop/CSharp/Library/Dialogs/BotToUser.cs#L81

we save one message to return inline with the incoming http request to the bot. If you want to send messages immediately, I would use this other implementation:

https://github.com/Microsoft/BotBuilder/blob/develop/CSharp/Library/Dialogs/BotToUser.cs#L112

This is only an issue if your bot's code continues to execute for some unbounded amount of time instead of returning from the initial incoming http request.

willportnoy avatar Jun 27 '16 19:06 willportnoy

@willportnoy I'm sending my message through message.SendMessage method, not using PostAsync

vaditya04 avatar Jun 29 '16 09:06 vaditya04

Right, it looks like you're using the IConnectorClient to send the message, which will always send the message immediately.

However, the default implementation of IBotToUser will queue one message to allow returning a message inline with the initial http request.

You may also run into issues if the Message you send through the IConnectorClient wasn't initialized with code like this:

https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Dialogs/BotToUser.cs#L70

willportnoy avatar Jun 29 '16 16:06 willportnoy

I'm going to close this issue, but feel free to open a new issue for more discussion.

willportnoy avatar Jul 07 '16 19:07 willportnoy