机器人框架直接发送通知 C#



我使用机器人框架构建了一个机器人,并通过直接线集成到我的网站中。我还开始创建一个管理门户,管理员可以在其中查看机器人分析。

我目前的要求是管理员应该能够找到当前与发送聊天的所有用户,并在需要时向所有这些用户推送通知,如果任何机构已经实现了这样的场景,请指导我朝着正确的方向前进

谢谢。

主动消息是机器人框架空间中"推送通知"的术语。 可以在此处找到一些文档:https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-proactive-messages?view=azure-bot-service-3.0

从概念上讲,机器人开发人员在某处保留对话引用,稍后用于发送主动消息

将对话引用保存在某处(内存缓存、数据库等(:

var conversationReference = message.ToConversationReference();

使用该对话引用向用户发送主动消息:

var message = JsonConvert.DeserializeObject<ConversationReference>(conversationReference).GetPostToBotMessage(); 
var client = new ConnectorClient(new Uri(message.ServiceUrl));
// Create a scope that can be used to work with state from bot framework.
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(CancellationToken.None);
// This is our dialog stack.
var task = scope.Resolve<IDialogTask>();
// Create the new dialog and add it to the stack.
var dialog = new WhateverDialog();
// interrupt the stack. This means that we're stopping whatever conversation that is currently happening with the user
// Then adding this stack to run and once it's finished, we will be back to the original conversation
task.Call(dialog.Void<object, IMessageActivity>(), null);
await task.PollAsync(CancellationToken.None);
// Flush the dialog stack back to its state store.
await botData.FlushAsync(CancellationToken.None);        
}

最新更新