SOLVED

How to send dm even if the user has not installed the app in personal scope.

Copper Contributor

I am trying to build a bot which will have a few message extension to submit data and then I will make a request to my custom backend. I want to save the data and want to send dm to the user.

I am planning to expose a route from my botbuilder restify server (built by teams toolkit) to send a dm to the user (from bot's account) because I could not find a way to send a dm without bot framework.

The only problem is when I am trying to send a dm I am getting an error saying "Bot is not installed in user's personal scope", which is true because the app is only installed in a team.

How can I tackle this problem? Basically I am building a feedback bot for companies so I want to proactively send dm message to all the employees and admins. What are different ways to do this thing.

Feel free to ask about any other information if you need, thanks!

14 Replies
best response confirmed by themashcodee2 (Copper Contributor)
Solution
Hello @themashcodee2- Thanks for raising your query.

For a user to receive proactive messages, install the app for the user or make the user a part of a team in which the app is installed.

You can also, proactively install your app using Graph.
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-m...

You can refer this sample as well: https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/graph-proactive-installation/...

Please refer this documentation: https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-m...
Thanks Chetan! These documentations really helped me a lot.

I tried the notification bot sample from vscode teams toolkit extension and it is able to send a dm to a user without requiring the user to install the app so it solved my problem.

Please let me know if notification bot process is wrong for my use case.

Actually, it depends on your requirement, but this is one of the correct approaches.

Please share your valuable feedback via Microsoft Teams Developer Feedback link.

Oh Okay.

One last question, is there a way I can create a group chat and also invite the bot into it at the time so that I can send a message to that group chat later?

Thanks, I shared the feedback via link.

@themashcodee2 - Yes, you can create a group chat in Microsoft Teams and invite a bot to it.  Once the group chat is created, you can send messages to it, and the bot will be able to receive and respond to them.

@Prasad_Das-MSFTbut actually I am getting these errors when
1. creating a group chat with bot included in the members
2. inviting the bot later

btw I have these permission in my token

"https://graph.microsoft.com/Channel.ReadBasic.All https://graph.microsoft.com/Channel.Create https://graph.microsoft.com/Group.Read.All https://graph.microsoft.com/User.ReadBasic.All https://graph.microsoft.com/Organization.Read.All https://graph.microsoft.com/Chat.ReadWrite.All";

what api/way you would suggest to create a group chat with bot and then what would be the best ways to send message in that group chat?

Actually this "To send chatMessage in a channel or a chat using Graph API, you can follow this:" sends message as the user and not as the bot.

Also, I am able to create a group chat but I am not able to create a group chat when bot is included.

Let me know if you need any other information from me, thanks!
So basically I was planning to create a group chat and invite/install the bot into it or create the group chat with bot initially only. Then I will be able to see that group chat through notification bot bot.getPagedInstallation() where bot = BotBuilderCloudAdapter.NotificationBot and then just send the message.

Although I was not able to see the group chat bot.findAllChannels(), I thought It also returns group chat along with public channels.

Further, when I am trying to get TeamsAppInstallation.ReadWriteSelfForChat permission through "https://login.microsoftonline.com/${tenant_id}/v2.0/adminconsent?client_id=${client_id}&scope=${scop...}" then I am getting error that TeamsAppInstallation.ReadWriteSelfForChat is invalid resource for permission or something like that.
This was my another idea to solve my problem that first create a group chat and then install the bot dynamically and then I will be able to see the group chat reference through notification bot bot.getPagedInstallation() and then I will send a message to the group chat.

@themashcodee2 - This API (Send chatMessage in a channel or a chat - Microsoft Graph v1.0 | Microsoft Learn), only works with delegated permissions. Delegated permissions should be used when you want the application to perform certain actions on behalf of a user. For example, allow application to access directory data as signed in user.

Application permissions are only supported for migration.

Use the proactive messaging capabilities of the Bot Framework. With proactive messaging, you can send messages to users who have previously interacted with your bot. However, this requires user consent, and you cannot send messages to users who haven't interacted with the bot before.
1 best response

Accepted Solutions
best response confirmed by themashcodee2 (Copper Contributor)
Solution
Hello @themashcodee2- Thanks for raising your query.

For a user to receive proactive messages, install the app for the user or make the user a part of a team in which the app is installed.

You can also, proactively install your app using Graph.
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-m...

You can refer this sample as well: https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/graph-proactive-installation/...

Please refer this documentation: https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-m...

View solution in original post