Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to trigger welcome messages in 1:1 conversations with BOt #97

Open
rjgmail88 opened this issue Feb 28, 2018 · 12 comments
Open

Failed to trigger welcome messages in 1:1 conversations with BOt #97

rjgmail88 opened this issue Feb 28, 2018 · 12 comments

Comments

@rjgmail88
Copy link

I'm trying to send a welcome message to a user when bot is added to MS teams for 1:1 chat. In this scenario user will be simply pasting BOT_Id in search bar on MS teams and bot should be visible for chat. As mentioned in following document I grabbed a code and modified for teamsAddMembers eventType but it does not work. In my case user has to wake up the bot by typing some command.

https://docs.microsoft.com/en-us/microsoftteams/platform/scenarios/bots-personal-conversations#best-practice-welcome-messages-in-11-conversations

https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-notifications#nodejs

bot.on('conversationUpdate', (msg) => {
    var members = msg.membersAdded;
    if (!members) {
        var members = msg.teamsAddMembers
    }
    // Loop through all members that were just added to the team
    for (var i = 0; i < members.length; i++) {

        // See if the member added was our bot
        if (members[i].id.includes(connector.settings.appId)) {
            var botmessage = new builder.Message()
                .address(msg.address)
                .text('Hello ! Welcome to CAL MS Teams Bot');

            bot.send(botmessage, function (err) { });
        }
    }
});
@Wajeed-msft
Copy link
Contributor

Please create and sideload app package into Microsoft Teams.
add for you
You would get conversationUpdate when you install the bot for personal scope. This is how user is going to start using your bot. User will not be using bot Id for searching the bot.

Please try and let me.

@billbliss
Copy link
Contributor

@rjgmail88
Copy link
Author

Thanks @billbliss and @Wajeed-msft , I will try those steps and let you know how it goes. I was following this document which says user BotID or create a deeplink
https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-test

@rjgmail88
Copy link
Author

@Wajeed-msft , in the document you pointed says

For bots designed only for 1:1 contexts, see Adding a bot for 1:1 chat only for an alternate way to access for testing purposes.

If I create an App then I need to upload it teams to use it. I my use case we are going to roll this in our Org for 10000+ people so I though 1:1 (personal scope) is best approach. What do you suggest.

@billbliss
Copy link
Contributor

Most likely, yes, because we don't yet have a way of adding "enterprise apps" (including bots) to our app store.

You can, however, create a URL to launch a conversation with your bot which will, in effect, install it for the user as a side-effect. The deep link is in the form:

https://teams.microsoft.com/l/chat/0/0?users=28:<botID> (you can see it in the Bot Framework portal for your bot, for example)

@rjgmail88
Copy link
Author

Thanks for the response. So you do recommend using a deep link for enterprise bots ? And going back to my original question about welcome messages in 1:1 chat, I guess I'am still unclear weather its possible.
https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-notifications
there is not eventType mentioned .

@billbliss
Copy link
Contributor

A deep link is a good solution, except I should add the caveat that the deep link approach I suggested won't work unless app sideloading is turned on for your tenant (because it's a form of sideloading).

For example Microsoft has sideloading turned on, but a lot of larger companies do not.

Also I took a closer look at your code as well as some sample code of ours and found your problem. You're confusing teamMemberAdded (not teamsMemberAdded), the event, with the event payload that tells you who was added (membersAdded). Also when a bot is added to a conversation it's always by itself - it's never added along with anyone else so there's no need to iterate through a collection - it's always the first item in the collection.

As such, starting with your original code, the following should work:

bot.on('conversationUpdate', (msg) => {
    if (msg.membersAdded && msg.membersAdded[0] && msg.membersAdded[0].id.endsWith(connector.settings.appId)) {
        var botmessage = new builder.Message()
            .address(msg.address)
            .text('Hello ! Welcome to CAL MS Teams Bot');

        bot.send(botmessage, function (err) { });
        }
});

I changed the logic from includes() to endsWith() which is a minor optimization. BTW in the future we will be adding an installation event so you don't have to rely on members added. User IDs/Bot IDs should be opaque; the fact that we make you know that the user ID is 28: is unfortunate.

@rjgmail88
Copy link
Author

I tried the deep link approach for couple of other users and it does work for us. I'm able to pull a specific user info from our tanant.

connector.fetchMembers((session.message.address).serviceUrl, conversationId, (err, result) => {
        if (err) {
            session.endDialog('There is some error to get user from MS teams.');
        }
        else {
             session.endDialog('%s', JSON.stringify(result));
       }
}

I would try out your code and see how it goes. Just to confirm it will only trigger when a BOT is added in teams for the very first time by a user right ? So for testing I really need to create a fresh BOT and try I believe because, I already have a bot in my teams added by deep link.

@billbliss
Copy link
Contributor

Yes the inability to reset the initial state is a problem. We are working on that now on fact. You can use a different botid / secret to test though.

@rjgmail88
Copy link
Author

@billbliss , I did create a new bot and copied your code in my bot services. This time it run through the code because following flag was true as you described earlier.

msg.membersAdded[0].id.endsWith(connector.settings.appId)

However, when I added a bot by copying BotId in teams nothing happened. User had to type something to wake the bot up. After first message from user it went through the code you mentioned.

Is it expected ?

@jotrick
Copy link

jotrick commented Mar 5, 2018

Yes, the flow of typing a guid into the search box and pulling up that bot does not actually create a conversation with that bot, so the member added event is not triggered yet. (It would be like searching for a new person, seeing the blank place a chat could be started, and then clicking away - that chat was never created so it is not placed in the left rail as a chat) There are very specific flows that can trigger a member added event so the bot can say hi first, but they revolve around the store. Although I have not tested this in quite awhile, it is possible sideloading a manifest with that bot, personally from the store, may trigger the event.

@rjgmail88
Copy link
Author

@jotrick , I am actually using a deep link teams.microsoft.com/l/chat/0/0?users=28:{botID}
is it same a guid into the search box method ?
I guess manifest.json configuration and all come when I convert my BOT into an artifact (using gulp) and load it as an app in MS teams for a specific team/channel.

I have a bot with multiple channels Cortana , skype and MS teams. I need to make it BOT available for all the users at my workplace. There are about 10k people. So I thought best way to roll this out is by emailing them a deepLink. Once they click and login with AAD account they will have this BOT in chat option. I think this is better than creating an app, uploading it to a store and asking everyone to go upload that app in teams of MS teams. In fact, some of the teams in the office are not even using teams from MS team they just use chat option for 1:1.

What do you think about this approach. ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants