Forum Discussion
Send Messages using Bot/Change Notification in MS Teams
I have some questions regarding bot functionality within Microsoft Teams.
I'm developing an app/plug-in to monitor and analyze all incoming messages in chats and channels. The goal is to intercept these messages, check them for specific flagged (e.g., inappropriate) content, and instantly send a notification back to the respective chat or channel if flagged content is detected. I need to achieve this in real time.
Currently, I’ve implemented the first half of this functionality using Microsoft Graph’s change notifications API, allowing me to intercept and read messages as they arrive. However, I’m facing a limitation: since my app doesn’t have permissions to post messages, I can't use the Graph API’s send capabilities to notify users within the channels or chats.
To work around this, I’m considering utilizing a bot. My approach is to have a bot send these notifications to the appropriate chats and channels, using identifiers such as tenant ID, team ID, channel ID, message ID, and chat ID—information I retrieve through the change notifications API.
So here are my main questions:
- Can I use a bot to send messages to various chats and channels on demand, leveraging the IDs obtained from the change notifications API? This would allow my app to handle message interception while the bot takes over in sending the flagged notifications.
- In my current setup, is there a way to reply to chats or channels directly using the Graph API's 'send' functionality through the app itself? It is related to Application/Delegation Permissions.
Thanks
5 Replies
- Meghana-MSFTFormer Employee
salmannaeem17 - You can use Graph API for this https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=http. This requires team id, channel id and message id. Please note that this send messages works with only delegated permissions.
You can also refer this doc to send messages via bot using Rest API - https://learn.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bot-conversations/bots-conv-channel#replying-to-messages. But this may not suit your requirement as it needs conversation id and activity id.
- salmannaeem17Copper Contributor
Hi,
Thanks for your reply.1) You mean this approach will not work? Can you tell me ways/examples to get conversation id, activity id etc.
2) What if I use 'bot' both for listening and sending messages. Can I achieve my task like this? Do I need IDs for this approach too?
3) Is there any other approach to achieve my task which I explained above?
Thanks
- salmannaeem17Copper Contributor
Hi,
Meghana-MSFTAny update?Secondly If I want to use only bot for my listening and sending messages, how can I do it? Is it possible?
Thanks