Automate Teams with your first Python Alerting Bot


In many companies, Microsoft Teams is at the heart of corporate communications. You can talk with colleagues, plan and assist meetings, create Teams to share information and files within a project. As claimed, it is the hub of Microsoft collaboration.

Today, let’s see how to empower Teams with automation and use it for sending personal or professional notifications. The setup of webhooks is super easy and takes no more than 5 minutes. Incredible!


  1. You’re training an ML model. It might take hours, and you want to be alerted at the end of the run. Sending yourself an end-of-run signal on your computer and phone is super easy.
  2. You’re running compute operations of 10 minutes. Too short to do anything else, too long to watch the screen. You might end up on your phone! Receiving a status notification at the end of the run allows to work more efficiently and stop losing time.
  3. You or your team want to be alerted of some information during a computing process in case of abnormal execution. (Ex: evaluating poor data quality.)
  4. You want to share daily or monthly data as a report with your team or a wider work audience. Your colleagues will appreciate receiving the data as a dedicated notification in a specific (and organized) channel instead of another email with another joined PowerPoint containing the data.

Technical overview

To send a teams notification, the necessary steps are the following ones

  • Having a Teams account and a Team with a Channel to post on (prerequisites)
  • Adding the webhook connector to that Team
  • Configuring a webhook connector in the Channel
  • Creating the content to post
  • Requesting the correct URL from any web-connected device (eventually with Python)

Creating the webhook

A webhook is a link that you’ll get and use to send an HTTP post request, with the desired notification content.

First, you’ll need to decide in which Chanel of which Team you’ll want to post notifications. For this blog post, I created a dedicated Medium Chatbot Team, with a private tutorial channel.

  1. On the settings (“”) of the channel, click on Connectors.
Fig. 2 — Opening connectors window on a Teams Channel

2. It will open, all the available connectors. Look up “webhook” in the top right search bar.

3. Click on the “Add” button of the “Incoming Webhook”

Fig. 3 — Selecting the Incoming Webhook on Teams

4. This opens a new dialog to validate your choice. Once again, click on “Add

Fig. 4 — Installing the Incoming Webhook on Teams

5. The different windows will then close

6. Re-open the connectors of the channel: settings “” > Connectors. And you’ll see that the first available connector is now the Incoming webhook.

7. Click on the “Configure” button

Fig. 5 — Resume to connectors page of the Teams Channel

8. The configuration box opens. And you immediately see how easy the configuration is:

  • Give a name to the bot. It will be the name displayed in the channel when the notification arrives. I use to add a robot emoji in the name 🤖 ! Let’s name that one “Your devoted bot 🤖”
  • Add a profile picture. Will also be displayed when messages are posted. Since we want to automate it with Python, I’ll add the Python logo as a profile picture. But you can obviously use your company logo, a robot picture, or your Facebook profile picture!

And that’s it! Don’t be afraid, if you’re not sure about your bot’s name, you’ll be able to change this information later without consequences 😉

9. Click on the “Create” button

Fig. 6 — Configuring the Incoming Webhook

10. The URL of your devoted bot will appear and you’ll be able to copy it.

Fig. 7 — Getting the URL of the Incoming Webhook

It will look like the following one :

11. Save this URL somewhere and we’ll see later how to use it.

12. You can now click on the “Done” button and close the connector’s window.

13. Now, get back to the channel, and you’ll see a message indicating that you configured an Incoming Webhook.

Fig. 8 — Confirmation of correct installation

And… That’s pretty much of it! Might take you a few minutes the first time, but in the future, I’m sure you’ll be able to follow the process in less than 45 seconds ⏲

Now that your channel can receive a message from an external source, let’s get deeper and discover how to send that notification.

Sending the notification

Notification composition

There are plenty of ways to create content via the webhook. You’ll find the Microsoft documentation here, but among the many tests that I’ve done, not many worked. Then I’ll show you a basic message that can be interpreted by the webhook.

The message must be JSON formatted and contain a minimum of 3 mandatory fields.

  • summary: is the text that’ll be displayed on phone notifications.
  • activityTitle: is the text that’ll be displayed in the channel on top of your notification
  • activitySubtitle: is the content of your notification’s message.
  • themeColor (optional): on top of your notification, you’ll see a line appear. This value defines its color with hexadecimal color code.

Sending the message

As mentioned earlier, to send the notification, you’ll need to send a post request with data. Post requests might not be sent from usual browsers, but can easily be managed with Python.

And to send a post request, nothing is more simple than using the requests package, simplifying HTTP for humans. the request from a Python script

Executing this code will basically send the notification to your channel 😎

No need to say that an internet connection is AB-SO-LU-TE-LY necessary for this step.

Fig. 9 — Your first automated notification

You can see the green line that corresponds to the used hexadecimal color value “00FF00”.

Note: instead of using python for the post request, you can also use software such as postman to send notifications.

Fig. 10 — Automated notification using Postman — Incoming Webhook on Teams

The result will be very similar (not to say exactly the same!).

Fig. 11 — Your second automated notification

It might be useful for testing but no need to say that using python will be easier for further integration!

Formatting the content

The content of your message must be wrapped in a string. Thus, it can be written with basic text such as in this example. But you can also use the Teams markdown solution. But since it uses markers that you can also use in your messages, I’d recommend using standard HTML format which is understood by the webhook. formated notification

If you want to use multiline, the <br> tag will be your best friend. Using triple quotes string in Python allows a visual effect so that you can materialize the “Enter” effect.

Fig. 12 — HTML formatted & sophisticated automated notification

If you want to use variables in the message, I suggest using f-strings. And then you can totally create dynamic code HTML content dynamically with Python and f-strings

⚠️ Erasing a message : using webhook url, it is currently not possible to delete a message. So be careful of the data that you send with it.

Receiving the alert

You now know how to post messages on a channel. But since you are not mentioned in it (not possible for now with this basic notification solution), you’ll have to subscribe to the channel notifications.

  1. Open channel settings “
  2. Click on “ 🔔 Channel notifications
  3. Select “Custom
Fig. 13 — Updating notifications parameters

4. Set the parameters as shown in Figure 14.

Fig. 14 — Custom notifications parameters

5. Click on the “Save” button

Now you can try to resend a message, you’ll receive a real notification from teams. And if you have the app installed on your phone, you’ll get notifications on it.

Fig. 15 — Receiving notification on Computer (Left picture) and phone (Right picture)

Losing the bot URL

If you can not remember what the URL of the bot was, don’t panic. It is always possible to find it in the configuration.

  1. Click on channel settings “”, open “Connectors
  2. On the left part of the window, click on “Configured
  3. 🛑 Do NOT click on the “Configure” button
  4. But kindly click the “1 Configured” link
  5. Click on the “Manage” button
Fig. 16 — Getting back to the existing Incoming Webhook’s configuration

You’ll then be able to modify the configuration of your bot and copy again the URL to use.


Today we created and configured a Webhook URL in a Teams Channel. Then we saw how to create content to send to this webhook, and most importantly how to proceed to the sending process, with python.

This allows you to include alerting code ATAWAD (AnyTime, AnyWhere, AnyDevice), since you have an internet connection, and to receive these alerts or messages from your mobile phone, for you or your current project’s team.


  1. you create your bot handler using this code as a starting point:
  2. you register its URL in MS Bot framerwork here:
  3. you add MS Teams as a channel