Search code examples
asp.net-core-mvcazure-web-app-servicebotsbotframeworkchatbot

I need to get and active users list or active connections who are in chat Bot Framework


I need active users or active connections list who are available to chat, who left from conversation I don't want to retrive those in below code, please help me out on this below is the code of getting all connections list.

        var activity = dc.Context.Activity;

        IList<ConnectionRequest> connectionRequests =
                    _messageRouter.RoutingDataManager.GetConnectionRequests();

        replyActivity = activity.CreateReply();

        if (connectionRequests.Count == 0)
        {
            replyActivity.Text = "No pending requests";
        }
        else
        {
            replyActivity.Attachments = CommandCardFactory.CreateMultipleConnectionRequestCards(
                connectionRequests, userService, activity.Recipient?.Name);
        }

Solution

  • The way bots built with the Bot Framework work is somewhat different that bots made for a specific service, like a Discord bot or a Slack bot. Since there are a multitude of different channels that you might offer your bot on, some of which don't have the concept of "online users" as such, there is no built-in functionality that gets all online users.

    Depending on the channel in which your bot is operating, the concept of "online users" could have different meanings. A Teams bot for example only connects to a new user one time, and persists the conversation, whereas a Direct Line bot does not.

    Bots developed with the Bot Framework SDK are inherently stateless, and as such you would need to define and implement your own method for identifying and contacting "online users".

    You could for example store the names and user IDs of users who connect to your bot for a period of time. If your users use AAD auth you could make use of Microsoft Graph APIs.

    Essentially, there is no standard way to do this, and you would need to define your own custom logic to fit the channel and features of your specific bot.