Photo by

The purpose of this article is to let you know how I’m using Python to send messages in Microsoft teams. Actually there isn’t any specific coding guideline for this whole flow, so that’s why I wrote some simple scripts which execute the whole flow with the help different utility functions. The script which I’ve requires following credentials:

  • Client ID
  • Tenant ID
  • Secret Key
  • Username
  • Password

You can get these credentials with the help of an article which has all the steps:

Let’s take a look at the main script which I’ve for this purpose:

Here in this script, you can see I’m using above credentials and then executing the each utility function one by one. As you may know, this process requires two types of permissions, one is Application permission and the other one is Delegated permission. Getting token process for these permission is also different that’s why I’m getting two different token according to the permission type.

You can get the complete code at:

Flow of the script is as follow:

  • Getting Singined user data because that is required when we need to create a chat with the user, there we need to provide the sender and receiver details.
  • After that I’m searching the receiver user details using it’s email for the chat creation process.
  • Sending message part involves two steps, create a chat and then send a message in that chat.

I tried to keep the explanation as simple as possible so that it can help you in understanding my approach. I know there are a lot of other ways to achieve this thing but this is what I used and implemented.

If you have any questions, please feel free to leave a comment below. If not then go for clap :)

A Python developer with 5 years of broad expertise in Django, Flask, JavaScript, Back-end Development, and web scraping/automation areas.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bookdog 5.3.21 Download For Mac

Java Programming: What’s New? Part 2

Reverse a Queue Coding Question

DataOps Automation — Accessing Databricks API with AAD Service Principal Name

Coroutines Kotlin

The DRY principle and why you should use it

Defining the web3 stack

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rizwan Butt

Rizwan Butt

A Python developer with 5 years of broad expertise in Django, Flask, JavaScript, Back-end Development, and web scraping/automation areas.

More from Medium

Deploy your dashboard app (Plotly Dash — Python) to Heroku with the container registry way

Setup Azure App for Microsoft Teams Chat automation

Dashboard Tale: Flask, Dash and Plotly

How to create a function in python to be used from the terminal