首页 文章

Bot框架Directline发送通知C#

提问于
浏览
0

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

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

谢谢 .

1 回答

  • 1

    Proactive Messages 是Bot框架空间中'push notifications'的术语 . 有些文档可以在这里找到:https://docs.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-proactive-messages?view=azure-bot-service-3.0

    从概念上讲,僵尸开发人员在某处坚持了一个 ConversationReference ,后来用于发送 Proactive Message

    在某处保存conversationReference(内存缓存,数据库等):

    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);        
        }
    

相关问题