Botframework 如何使用主动通道对话框在通道中启动新线程?
我的机器人可以在频道中创建一个新线程,如。现在我想在这个新线程中启动一个主动对话。我正在后续的Botframework 如何使用主动通道对话框在通道中启动新线程?,botframework,Botframework,我的机器人可以在频道中创建一个新线程,如。现在我想在这个新线程中启动一个主动对话。我正在后续的ContinueConversationAsync回调中启动该对话框。对话框似乎已启动,但一旦提示用户,用户的回复将不由对话框处理,而是由Main对话框处理 如果使用用户发送的活动启动对话框,则该对话框将正确处理提示。只有主动对话似乎在新创建的通道中不起作用 这是我的密码 var conversationParameters = new ConversationParameters { IsGr
ContinueConversationAsync
回调中启动该对话框。对话框似乎已启动,但一旦提示用户,用户的回复将不由对话框处理,而是由Main对话框处理
如果使用用户发送的活动启动对话框,则该对话框将正确处理提示。只有主动对话似乎在新创建的通道中不起作用
这是我的密码
var conversationParameters = new ConversationParameters
{
IsGroup = true,
ChannelData = new TeamsChannelData
{
Channel = new ChannelInfo(teamsChannelId)
},
Activity = (Activity)message
};
ConversationReference newConversationReference = null;
await adapter.CreateConversationAsync(
teamsChannelId,
serviceUrl,
credentials,
conversationParameters,
(t, c) =>
{
newConversationReference = t.Activity.GetConversationReference();
return Task.CompletedTask;
}, cancellationToken);
await adapter.ContinueConversationAsync(
_appId,
newConversationReference,
async (t, c) =>
{
var dialogStateAccessor = this.conversationState.CreateProperty<DialogState>(nameof(DialogState));
var dialogState = await dialogStateAccessor.GetAsync(t, () => new DialogState());
var dialogSet = new DialogSet(dialogStateAccessor);
dialogSet.Add(dialog);
var dialogContext = await dialogSet.CreateContextAsync(t, cancellationToken);
await dialogContext.BeginDialogAsync(dialog.Id, options, cancellationToken);
await conversationState.SaveChangesAsync(t, false, cancellationToken);
},
cancellationToken);
var conversationParameters=新的conversationParameters
{
IsGroup=true,
ChannelData=新团队SchannelData
{
频道=新频道信息(teamsChannelId)
},
活动=(活动)消息
};
ConversationReference newConversationReference=null;
等待适配器。CreateConversationAsync(
teamsChannelId,
serviceUrl,
资格证书
会话参数,
(t,c)=>
{
newConversationReference=t.Activity.GetConversationReference();
返回Task.CompletedTask;
},取消令牌);
等待适配器。ContinueConversationAsync(
_阿皮德,
newConversationReference,
异步(t,c)=>
{
var dialogStateAccessor=this.conversationState.CreateProperty(nameof(DialogState));
var dialogState=await dialogStateAccessor.GetAsync(t,()=>newdialogstate());
var dialogSet=新的dialogSet(dialogStateAccessor);
添加(对话框);
var dialogContext=await dialogSet.CreateContextAsync(t,cancellationToken);
wait dialogContext.BeginDialogAsync(dialog.Id,options,cancellationToken);
等待conversationState.saveChangesSync(t,false,cancellationToken);
},
取消令牌);
有什么想法吗?我的问题是,我从新创建的channel post的回调中获取了
ConversationReference
,并尝试在ContinueConverationAsync()
中使用它。然而,仅凭会话参考是不够的。因此,我将我原来的ConversationReference
与新的ConversationReference
合并使用。现在它就像一个符咒
这是我的更新代码:
ConversationReference newConversationReference = null;
await adapter.CreateConversationAsync(
conversationChannelId,
serviceUrl,
credentials,
conversationParameters,
(t, c) =>
{
newConversationReference = t.Activity.GetConversationReference();
return Task.CompletedTask;
}, cancellationToken);
if (dialog != null)
{
// Proactive channel dialogs dont seem to work with the newConversationReference: responses to the dialog are handled by the MainDialog.
// So I just create a new ConversationReference from the topic subscription and the new conversation. That works.
var newNewConversationReference = new ConversationReference
{
ActivityId = newConversationReference.ActivityId,
Bot = conversationReference.Bot,
ChannelId = conversationReference.ChannelId,
ServiceUrl = conversationReference.ServiceUrl,
User = conversationReference.User,
Conversation = new ConversationAccount
{
Id = newConversationReference.Conversation.Id,
AadObjectId = conversationReference.Conversation.AadObjectId,
ConversationType = conversationReference.Conversation.ConversationType,
IsGroup = conversationReference.Conversation.IsGroup,
Name = conversationReference.Conversation.Name,
Properties = conversationReference.Conversation.Properties,
TenantId = conversationReference.Conversation.TenantId,
Role = conversationReference.Conversation.Role,
},
};
await adapter.ContinueConversationAsync(
_appId,
newNewConversationReference,
async (t, c) =>
{
var dialogStateAccessor = this.conversationState.CreateProperty<DialogState>(nameof(DialogState));
var dialogState = await dialogStateAccessor.GetAsync(t, () => new DialogState());
var dialogSet = new DialogSet(dialogStateAccessor);
dialogSet.Add(dialog);
var dialogContext = await dialogSet.CreateContextAsync(t, cancellationToken);
await dialogContext.BeginDialogAsync(dialog.Id, options, cancellationToken);
await conversationState.SaveChangesAsync(t, false, cancellationToken);
},
cancellationToken);
}
ConversationReference newConversationReference=null;
等待适配器。CreateConversationAsync(
会话信道ID,
serviceUrl,
资格证书
会话参数,
(t,c)=>
{
newConversationReference=t.Activity.GetConversationReference();
返回Task.CompletedTask;
},取消令牌);
如果(对话框!=null)
{
//主动通道对话框似乎不适用于newConversationReference:对对话框的响应由MainDialog处理。
//所以我只是从主题订阅和新对话中创建了一个新的对话引用。这很有效。
var newConversationReference=新的ConversationReference
{
ActivityId=newConversationReference.ActivityId,
Bot=conversationReference.Bot,
ChannelId=conversationReference.ChannelId,
ServiceUrl=conversationReference.ServiceUrl,
User=conversationReference.User,
会话=新会话帐户
{
Id=newConversationReference.Conversation.Id,
AadObjectId=conversationReference.Conversation.AadObjectId,
ConversationType=conversationReference.Conversation.ConversationType,
IsGroup=conversationReference.Conversation.IsGroup,
Name=conversationReference.Conversation.Name,
属性=conversationReference.Conversation.Properties,
TenantId=conversationReference.Conversation.TenantId,
Role=conversationReference.Conversation.Role,
},
};
等待适配器。ContinueConversationAsync(
_阿皮德,
NewConversationReference,
异步(t,c)=>
{
var dialogStateAccessor=this.conversationState.CreateProperty(nameof(DialogState));
var dialogState=await dialogStateAccessor.GetAsync(t,()=>newdialogstate());
var dialogSet=新的dialogSet(dialogStateAccessor);
添加(对话框);
var dialogContext=await dialogSet.CreateContextAsync(t,cancellationToken);
wait dialogContext.BeginDialogAsync(dialog.Id,options,cancellationToken);
等待conversationState.saveChangesSync(t,false,cancellationToken);
},
取消令牌);
}
请包括启动main对话框的代码以及main对话框的实际代码。我相信现在发生的情况是,在OnMessageAsync
中,所有消息都被路由到main对话框
,而不是当前活动的对话框。你可能需要一些东西,比如我在我的项目中很早就遇到了你描述的问题。为了让主动对话发挥作用,我必须创建一个对话框集,其中包含我所有的对话框。只有这样,用户才能响应到正确的对话框。