问题
How can I get the ConversationId
from the IDialogContext context
? I know that there is a ConverationData
property but that seems to just be a data bag that can hold anything.
Is the id in this bag? If so, what is the key to retrieve it?
public async Task General(IDialogContext context, LuisResult result)
{
//how can I access the conversationId here
}
回答1:
So I have found a way of doing it but I am not sure if it is the best way.
The context
object that is passed in has a data
field on it which contains the original message
object which in turn contains the ConversationId
. Unfortuantely this is private.
But the context
does have a CreateMessage
method which returns a Message
object which contains the ConversationId
and it is accessible.
var id = context.MakeMessage().ConversationId;
Like I said, I am not sure if this is the best way but it is the only way I have been able to achieve this. I'll leave this up in case someone has a better way.
回答2:
Have a look at this code:
var id = context.MakeMessage().Conversation.Id;
Id
is now property in Conversation
object. It works for me.
回答3:
With the last version of the framework you can get it from the DialogContext object easier:
var conversationId = context.Activity.Conversation.Id;
I used it and it worked on my bot.
来源:https://stackoverflow.com/questions/37251597/get-conversationid-from-context