user8662086
user8662086

Reputation:

Bot Framework Directline Send Notification C#

I have build a bot using bot framework and integrated into my website through directline. I have also started with creating a admin portal, where admin can have a look at bot analytics.

The requirement i currently have is the admin should be able to find all the users who are currently have chat with the send and push a notification to all those users if needed , if any body has already implemented such scenario please guide me in a proper direction

Thanks.

Upvotes: 0

Views: 764

Answers (1)

Eric Dahlvang
Eric Dahlvang

Reputation: 8292

Proactive Messages is the terminology for 'push notifications' within the Bot Framework space. Some documentation can be found here: https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-proactive-messages?view=azure-bot-service-3.0

Conceptually, the bot developer persists a ConversationReference somewhere and that is later used to send a Proactive Message

Save conversationReference somewhere (memory cache, database, etc.):

var conversationReference = message.ToConversationReference();

Use that conversation reference to send the user a Proactive Message:

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

Upvotes: 1

Related Questions