Search code examples
node.jsbotframeworkmicrosoft-teams

How check member status on MSTEAMS


For a purpose of checking member status (online or offline) on MSTeams, I want to get member status by email.

I have approached Bot Builder Microsoft Teams Extensions and write a sample code to get into my idea:

var teams = require("botbuilder-teams");

bot.dialog('FetchMemberInfo', function (session) {
    var memberEmail = '[email protected]';

    var connector = new teams.TeamsChatConnector({
        appId: process.env.MICROSOFT_APP_ID,
        appPassword: process.env.MICROSOFT_APP_PASSWORD
    });

    connector.fetchMemberInfo(session.message.address.serviceUrl, memberEmail, function (err, result) {
        if (err) {
            session.endDialog('There is some error');
        }
        else {
            var memberStatus = result.member.status;
            session.endDialog('%s', JSON.stringify(result));
        }
    });
});

I only have member's email and want to get member status. So, what place in my sample code need to be updated to get member information which include member status? I also welcome any other suggestion if there is.


Solution

  • Actually, we can get user status (online/offline) via Skype4Business API. Here is an example code:

    var authContext = {
        id: botSetting.identifier,
        username: botSetting.username,
        password: botSetting.password,
        domain: botSetting.domain,
        _links: {},
        /*1 seconds*/
        messageInterval: 1000 * botSetting.messageInterval,
        /*30 seconds*/
        messageTimeout: 1000 * botSetting.messageTimeout,
        /*3 minutes, unit in second*/
        statusUpdateInterval: 1000 * botSetting.statusUpdateInterval,
        AppId: null,
        AppPath: null,
        EndPointId: botSetting.endpointId,
        Culture: botSetting.culture,
        UserAgent: botSetting.userAgent,
        /* default timeout to wait for user to accept message is 5 minutes */
        acceptMessageInvitationTimeout: botSetting.acceptMessageInvitationTimeout * 1000,
        logUnhandleEvent: botSetting.logUnhandleEvent,
        RootAppUrl: null,
        /*default is 30 seconds, unit in second*/
        statusAwarenessInterval: (CONFIG.PROACTIVE_MESSAGE_INTERVAL_IN_SECONDS || 30) * SECOND_TO_MILLISECONDS, //30 seconds
        remindProcessProactiveMsgInterval: 1000 * 60 * CONFIG.PROACTIVE_MESSAGE_REMIND_IN_MINUTES,
        proactive_interval: process.env.PROACTIVE_UPDATE_INTERVAL_IN_MINUTES || 2
    };
        
    function getUserAvailibility(receiver){
        var url = authContext._embedded.people._links.self.href;
        var requestResourceUrl = stringFormat("{0}{1}/{2}/presence", authContext.BaseUri, 
                                               url, receiver);
        console.log("SkypeForBusinessBot getUserAvailibility " + receiver +
                    " with url: " + requestResourceUrl);
        return $q.nfcall(request.get, requestResourceUrl, {
            headers: authContext.headers, json: true });
        }
    

    Note: receiver is user's email