Posting to a teams channel from a logic app or flow which includes an banner alert / activity feed item - microsoft-graph-api

I have a logic app which posts a channel chat message to teams automatically when a new item is created in SharePoint. This I have working but our client requires that all the team members receive a banner alert and activity feed which I am having a lot of difficulty with.
What I've already tried...
Using a Incoming web hook on the teams channel - this was a very simple way to post from the logic app but the incoming webhook don't seem to support mentions.
Using the msft graph api - The /team/channel/message endpoint can post messages and user mentions but the this endpoint doesnt support channel or team mentions. It also appears that the graph API needs to use delegated permissions to post messages in teams. I'm using application permissions as this is a logic app. The logic app HTTP post connector doesnt offer the "connect as username#tenant.com" some of the other connectors use.
Using the flowbot post message - Like the above channel and team mentions are supported here so the post is added to the channel but with no notification to the team members
Using a notification only bot - I thought I nearly had it with this one. Microsoft's node bot sample number 57 looked like it can do most of what I want, it iterates through the users in the team and messages them this a customisable alert message...
https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/57.teams-conversation-bot
However I can't see how this bot can be triggered from my logic app as it seems to require an existing conversation context or an #mention from within teams to start communicating with users.
What I'm considering trying next
Iterating users within the logic app - Next I plan to try and get team membership from the graph API and iterate the members in the Logic App, posting a message to each user separately. I had hoped to utilise the group #mention feature as a simpler way so I'd be grateful if anyone had any thoughts on other ways of doing this, or maybe there's something wrong with what I've already tried that you could give me some expertise on.
Thanks in advance ;)
Andy

You're on the right track with the Bot, but you're wanting to send something called a "Pro-active" message. You need the bot registered in the channel in order to get access to a few key properties (conversation id, service url, etc.), but you can use those to send a message from -outside- your bot (e.g. in an Azure Function). You might be able to do this directly from a Logic App, but I haven't tested that specifically.
To find out more, see my answer at Programmatically sending a message to a bot in Microsoft Teams but I've also got a recent blog post that you might find interesting for background on this at How Bots Actually Work.
Hope that helps

You can use Graph to post a message in 1:1 chat as long as you have the chat it. You can find the answer in this post Send message to personal Chat via Graph API
You can also call Graph API from Logic Apps. (https://techcommunity.microsoft.com/t5/integrations-on-azure-blog/calling-graph-api-from-azure-logic-apps-using-delegated/ba-p/1997666#:~:text=Calling%20Graph%20API%20from%20Azure%20Logic%20Apps%20using,Manage%20-%3E%20Certificates%20%26%20secrets%20More%20items...%20)

Related

Missing Permissions for Microsoft Graph Add Chat message

I am trying to use Microsoft.Graph to send add a message to a chat. I have successfully found my team and created a channel for the messages to go into but when I try to actually send the message, I get a Forbidden error message. This is covered by the ticket:
Microsoft Graph API for Teams: Send Channel/ Chat messages and I am getting the same problem that #Koelier originaly got.
The reason that this is not fixed is that following the answer does not fix my problem. Indeed, the ChannelMessage.ReadWrite.All does not appear in my list. I am looking for the app to run as a service, in the background so the Application Permissions is the method I need to use.
I note that I am not alone in this as #johnnycardy notes that he has had exactly the same problem as me. Furthermore, I linked to the document referenced by #nastassiar and it did not reference the ChannelMessage.ReadWrite.All at all. I can assume it did once but not anymore.
Any guidance would be gratefully received.
Just checked the permissions to perform the same using graph explorer and the below are the ones that I had to add.
ChannelMessage.Send - Allows the app to send channel messages in Microsoft Teams, on your behalf.
Chat.ReadWrite - Allows an app to read and write your 1 on 1 or group chat messages in Microsoft Teams, on your behalf.
ChatMessage.Send - Allows an app to send one-to-one and group chat messages in Microsoft Teams, on your behalf.
Group.ReadWrite.All - Allows the app to create groups and read all group properties and memberships on your behalf. Additionally allows the app to manage your groups and to update group content for groups you are a member of.
enter image description here

Teams bot, which approach to go for?

My use case requires me to integrate teams with an app. Whenever a message is sent from that app, a private channel will be created and the message will be sent to teams. I've been reading the documentation and it has only confused me further. Do I need to use graph or bot? Can I do this using only graphs or only bot?
It's possible to send a message using Graph API - see here for more: https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=http
HOWEVER, there are two ways to authenticate with Graph, either via an "application" permission (kind of like background service), or via "delegation", which means your app would work on behalf of a user. For this specific Graph endpoint, Microsoft mentions in the page that Application permissions are only allowed for "migration" (e.g. if you were building a tool to migrate from, say, slack to Teams). That means that you would have to use "delegation" which means the message would appear to come from a specific user.
As an example, instead of the message coming from "ABC Application", it would appear to come from "Syed Muhammad Ibrahim". If that's ok, then you can use Graph. If not, you would need to go the Bot route.

MS Graph API Teams: Application access to Channel Messages

I am looking at Teams Channel Create Chat Message method (currently only available in beta).
We have an application which manages groups of users and would like to integrate with MS Teams - create a Team, add Channels and send messages to the channel - all without a user. For this I have followed "Get access without a user".
However I notice that for this and other message level functions (list messages) Application permission is "Not Supported" and for our use case Delegated permissions is not really an option (similar to this).
Does anyone know why these are only available for Delegated Permission? is there a plan to enable this or is will this always not be "Not supported" for Application Access?
I appreciate that giving an Application full access to all messages may be something that Admins would not be keen on, but being able to post and retrieve messages from channels the application has created seems (to me) to be reasonable (perhaps the permissions model isn't that fine grained yet).
This is possibly an overlap of Unable to “List channel messages” on Azure AD Graph API Beta - the OPs answer contains an unanswered similar question.
We aren't currently sharing road map externally of when these types of things are being updated.
What we do ask is that you request these on our UserVoice channel so that we can track the demand and prioritize accordingly. If you can go here and add this request I'd appreciate this and I'll let the PM who owns this know https://developer.microsoft.com/en-us/graph/support

How to make your bot user reply with a simple help message using slack bot

I have created a slack bot and I want to send a general static help message to users when they send a direct message to my bot:
Should I subscribe to Events API? Or do I need to do this in another way? I couldn't find a clear answer for this.
There are two ways to do make your bot user reply to direct messages:
Events API
Real Time Messaging API
In my opinion the Events API approach is easier to implement since it does not require using WebSockets.
The basic approach with the Events API is:
You need an endpoint that can receive event requests from Slack and
react to it, e.g. by sending a direct message back to a user.
Subscribe to message.im event for your bot user
Note that a bot user already has all the required scopes for this with the bot scope.
In addition I would recommend to subscribe to app.mention for your bot user. Then it can also react to mentions in other channels.
Btw. that message you posted looks a lot like a review comment from the Slack team for a new app submission. I got a similar one for my last app and I solved it with the approach above. In general it looks like if you want to have a bot user in your app it needs to be able to respond to help request from users.

What OAuth Scopes are required for a listen & reply Slack Bot using the Slack Events API?

I am trying to make a bot that will listen to all public & private channels, and IMs for a team, and will reply when it sees certain trigger words. This will be a "Slack App", installable to your team using the "Add to Slack" button, and includes a "Bot User".
I have asked for the "bot" OAuth scope, and subscribed to the "message.channels,message.groups and message.im" Team Events (at https://api.slack.com/apps/myAppId/event-subscriptions) but do not appear to receive event POSTs through the Events API when new messages are sent.
Adding the "channels:history,groups:history,im:history" scopes makes the bot receive these event POSTs, but I believe only for the user that added the bot, so it will not watch groups that the adding-user was not a member of, or IMs between 2 other users. This means that behaviour will be different, depending on which user installed my bot.
Is there a way of installing the app/bot for an entire team? The documentation seems to indicate that a 'bot' scope should have the ability to receive events, but I am not seeing this (I require the channels:history scope etc. above).
bot - request this scope when your Slack app includes bot user functionality. Unlike incoming-webhook and commands, the bot scope grants your bot user access to a subset of Web API methods, the RTM API, and certain event types in the Events API.
(from https://api.slack.com/docs/oauth-scopes)
The page on bots also claims that a bot can receive all messages through the RTM API:
This websocket will send you all of the messages and activity that happen in public and private channels that the bot user is invited to, as well as messages that are sent to it via direct message. A bot user opens this websocket with the RTM API by sending an authenticated call to the rtm.start API method. To learn more about connecting to the RTM API, read the documentation here.
(from https://api.slack.com/bot-users)
Is this same behaviour possible in the events API without needing to use the RTM API or add those additional scopes mentioned above?
I see from your comment that you have understood that the bot scope (and the channels.message Events subscription) allows your bot to receive from channels it is present in.
You have two options
1) you ask for channel.write scope in addition to bot, and you invite the bot in all channels (using the user token, not the bot token)
2) you work on your onboarding and figure out a way to get your "champion", ie the user who installed your app, to invite your bot in relevant channel.
Keep in mind that solution 1) is usually seen as very intrusive, especially in large teams where most people haven't heard of your app nor taken the decision to install it. But it can be suitable for some very specific use cases. Option 2) is the recommended route, but it is hard :-) Good luck!

Resources