我正在创建一个事件系统,其中聊天机器人可用于触发外部系统上的作业。一旦外部系统收到作业,它就会运行它需要运行的内容,然后通知azure中保存的队列作业已经完成。
接下来,我有一个查看此队列的功能应用程序。收到新信息(包含ID,ConversationReferenceObject和作业响应)后,它会通过ProactiveMessage通知机器人:
var conversationReference = JsonConvert.DeserializeObject<ConversationReference>(subscription.ConversationReference);
MicrosoftAppCredentials.TrustServiceUrl(conversationReference.ServiceUrl);
var client = new ConnectorClient(new Uri(conversationReference.ServiceUrl), new MicrosoftAppCredentials(appId, appPassword));
var result = conversationReference.GetPostToBotMessage().CreateReply($@"[ProactiveMessage] Your job response: {response.data}");
client.Conversations.ReplyToActivity((Activity)result);
现在,我不希望将此回复发布到机器人活动,而是希望聊天机器人拦截[ProactiveMessage]
,然后仅在对话框当前未处于活动状态时才响应用户 - 通常只是正确管理对话流程。 / p>
现在,我想知道client.Conversations
是否有不同的功能,我可以发布到聊天机器人而不是回复当前的对话?我有点卡住了。
答案 0 :(得分:1)
如果要检查最初发送邮件的用户的当前对话框堆栈,可以使用以下内容:
var fromConversation = conversationReference.GetPostToBotMessage();
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, fromConversation))
{
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(default(CancellationToken));
var stack = scope.Resolve<IDialogTask>();
if (stack.Frames != null && stack.Frames.Count > 0)
{
var lastFrame = stack.Frames[stack.Frames.Count - 1];
var frameValue = lastFrame.Target.GetType().GetFields()[0].GetValue(lastFrame.Target);
if (frameValue is NodeRootDialog) //<-- only reply if user is in NodeRootDialog
{
var reply = fromConversation.CreateReply("used converation reference to reply");
var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
}