Get ConversationId from Context

孤街醉人 提交于 2020-01-16 07:05:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!