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

context.MakeMessage is not filling in the Id of the To/From ChannelAccounts

Open ejadib opened this issue 10 years ago • 6 comments

Is this expected? If you generate a ResumptionCookie out of a message created with context.MakeMessage() once you resume the conversation using Conversation.ResumeAsync(resumptionCookie, resumptionCookie.GetMessage()) it fails with the following message:

Error> An error has occurred. 'botId' cannot be null. Microsoft.Rest.ValidationException at Microsoft.Bot.Connector.Bots.d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Connector.BotsExtensions.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.Extensions.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Conversation.d__51.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Conversation.<ResumeAsync>d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at AzureBot.Controllers.OAuthCallbackController.<OAuthCallback>d__0.MoveNext() in D:\Projects\DX\AzureBot\AzureBot\Controllers\OAuthCallbackController.cs:line 31 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()

ejadib avatar May 25 '16 11:05 ejadib

ResumptionCookie should be created out of the incoming message. context.MakeMessage() creates a reply message for the the incoming message that have a reversed To/From field. I highly recommend using the following constructor of ResumptionCookie to make sure that you are setting the right fields: public ResumptionCookie(string userId, string botId, string conversationId, string channelId, string language = "en")

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

@msft-shahins Thanks. Right, let's keep the ResumptionCookie out of the game for now. I was using that as an example to show the exception.

Let's say that I need the user id for something (the botId is something I can get from the Web.config). I'm on the "ResumeAfter" method of a PromptConfirm dialog that was launched as part of the ResumeAfter of a FormDialog. So I don't have the incoming message at this point.

Is there a way to get the userId without having to store it manually in one of the data bags? And is it expected to not have the userId/botId in the reply message created with the context?

This is the flow.

FormDialog ----> ResumeAfterFormDialog ----------> PromptConfirmDialog -------------- -> ResumeAfterPromptDialog ===> how to get the userId here?

Thanks, Ez.

ejadib avatar May 25 '16 18:05 ejadib

There are couple of ways to pass any information to your dialogs; examples can be passing data through the constructor of your custom dialog or passing it through the contextual stores. For example in your case, you can keep the user Id as a member variable in the class implementing the ResumeAfterPromptDialog and consume it in that method.

context.MakeMessage() will return a message that acts as a reply to the incoming message. if incoming message have the right To/From (which will if it comes from connector or emulator), you should have the user Id in the To.Id, also the bot Id will be in From.Id.

msft-shahins avatar May 25 '16 19:05 msft-shahins

@msft-shahins thanks. I might go with storing the user id as a member variable.

While the incoming message has the userId and the botId, the message returned by the context.MakeMessage() never contains the ids (I tried creating the reply message right in the MessageReceived message without other dialogs/resumeAfter methods involved.

The name, channelId and the address are there but the id is null (for both the bot and the user). I decompiled the connector library and it seems it's expected. The extension method code thet create the reply message is never setting the ids in the channel accounts used for the To/From.

ejadib avatar May 25 '16 20:05 ejadib

@ejadib thanks for pointing that out. We will look into that.

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

@msft-shahins I just found #237 is related to this. It seems @willportnoy already fixed this.

ejadib avatar May 26 '16 10:05 ejadib