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
You can get these credentials with the help of an article which has all the steps: Setup Azure App for Microsoft Teams Chat automation
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: ms-teams-python
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 :)