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

await client.Messages.SendMessageAsync(reply) in OAuthCallback doesn't actually send message

Open whatsdis opened this issue 10 years ago • 9 comments

await client.Messages.SendMessageAsync(reply); doesn't seem to send message to the user saying they are logged in. I'm running on the bot emulator.

From OAuthCallbackController.cs

        `// Resume the conversation to SimpleFacebookAuthDialog
        var reply = await Conversation.ResumeAsync(Constants.botId, userId, conversationId, msg, connectorType: connectorType);

        // Remove the pending message because login flow is complete
        IBotData dataBag = new JObjectBotData(reply);
        PendingMessage pending;
        if (dataBag.PerUserInConversationData.TryGetValue("pendingMessage", out pending))
        {
            dataBag.PerUserInConversationData.RemoveValue("pendingMessage");
            var pendingMessage = pending.GetMessage();
            reply.To = pendingMessage.From;
            reply.From = pendingMessage.To;

            // Send the login success asynchronously to user
            var client = Conversation.ResumeContainer.Resolve<IConnectorClient>(TypedParameter.From(connectorType));
            await client.Messages.SendMessageAsync(reply);

            return Request.CreateResponse("You are now logged in! Continue talking to the bot.");
        }`

whatsdis avatar May 08 '16 04:05 whatsdis

@msft-shahins how do you direct the IConnectorClient to point to the bot emulator when resuming from an oauth callback?

willportnoy avatar May 09 '16 18:05 willportnoy

if the bot is running on localhost (your oauth callback url is configured to be forwarded to the localhost), everything should work automatically; since pending message will have the channel id of the emulator. The emulator will not receive the proactive messages from bot, if your bot is not running on the localhost (emulator is listening for incoming messages on localhost:9000).

msft-shahins avatar May 09 '16 20:05 msft-shahins

weird it works when I publish the bot but not on the localhost emulator

whatsdis avatar May 09 '16 23:05 whatsdis

It seems this is still not working (using the ResumptionCookie approach)

ejadib avatar May 13 '16 03:05 ejadib

if you are driving the bot using the emulator you should make sure that your bot is running on localhost and your oauth callback is set to localhost. That is the only way to get the proactive messages from your bot on emulator. I recommend debugging the bot and see if the SendMessageAsync(...) call in OAuthCallbackController completes successfully.

msft-shahins avatar May 13 '16 17:05 msft-shahins

Thanks @msft-shahins Yes, it's not working in Localhost and also it's not working when hosted in Azure.

When running in localhost my oauth callback is set to localhost too.

ejadib avatar May 13 '16 17:05 ejadib

@ejadib can you debug the bot and make sure that IConnectorClient.BaseUri is set to http://localhost:9000/. Port 9000 is the port that emulator is listening on.

msft-shahins avatar May 13 '16 17:05 msft-shahins

@msft-shahins my bad. It's working as expected in both localhost and in Azure. I got confused because the message that was being posted was exactly equals to the message from next dialog in my continuation chain.

ejadib avatar May 13 '16 18:05 ejadib

a while ago everything was working fine on azure but now it is not throwing the message like it does in localhost. when I test it in localhost it correctly returns the message but this doesn't happen in azure.

is there some sort of breaking change that was introduced or is there some sort of caching going on?

a month ago I didn't have any sort of problem like this and all of sudden since the recent release of 1.1 and 1.2 I find either my bot breaks or there's inconsistencies between my azure and localhost emulator behavior.

whatsdis avatar Jun 03 '16 01:06 whatsdis