This project allows one to post a simple message (string) to a channel in a team in Microsoft Teams via REST API POST. One can also update that message via REST API PUT. These messages are posted/updated using a Bot.
I built this project because I couldn't find a simple example of how to send proactive messages to users/channels in Microsoft Teams. Every example either started with a user sending a message to my bot (and thus had pre-existing Teams context), or had a ton of other functionality wrapped around the proactive message. This project is meant to be the most basic implementation of proactive messages. This project is not production-ready nor a representation of how you should do this for reals.
- Register with the Bot Framework
- We don't need to get callbacks from Teams at this point, so we don't need a web service for our Bot at this point. Just put whatever in the URL.
- Copy the
Microsoft App IDandpasswordyou get from this process, paste it into Notepad or soemthing for later
- Create your app manifest and package
- Make sure you enable the
Teamscope
- Make sure you enable the
- Upload your package to Microsoft Teams to install your Bot in the Team where you want to post channel messages
When you do this for reals, you may want to check this out if you have to send to many channels or users: Enable proactive bot installation and proactive messaging in Teams with Microsoft Graph (Public Preview)
Use the Teams web client to figure out the channel id
- Browse to https://teams.microsoft.com
- Navigate to the channel you want to post messages to (under the Team you installed your Bot to above)
- Copy the
threadidfrom the URL in the address bar, paste this in Notepad or something for later
- Create an appsettings.Development.json file (if there isn't one already) under appsettings.json
- Copy settings from appsettings.json to appsettings.Development.json
"MicrosoftAppId": "YOUR BOT ID",
"MicrosoftAppPassword": "YOUR BOT SECRET",
"ChannelId": "TEAMS CHANNEL ID (SHOULD START WITH SOMETHING LIKE 19:blahblahblah)",
"ConversationsUrl": "https://smba.trafficmanager.net/amer/v3/conversations"
- Populate
MicrosoftAppId,MicrosoftAppPassword, andChannelIdusing the values you copied from Prerequisites
- Run your API project (in Debug mode in IIS Express)
- Open Postman
- Import this collection into Postman
- Open the
Post a new message to a channelrequest andSendit- Note: This request saves the value of
idfrom the response to a collection variable to be used by the next request
- Note: This request saves the value of
- Check your channel in Teams to see the message
- Open the
Update an existing message in a channelrequest andSendit - Check your channel in Teams to see the updated message