This repository contains sample code and instructions on how to integrate with Microsoft Graph API to interact with chat messages and channels in Microsoft Teams.
These instructions will help you set up and use the integration to retrieve and post messages using Microsoft Graph API.
- Microsoft Azure Account
- Microsoft Teams Account
- Python 3.x
requests
library (Install usingpip install requests
)
- Go to the Azure Portal.
- Create a new App Registration.
- Note down the Application (client) ID and create a new client secret.
- Grant necessary permissions (e.g.,
Chat.Read
,ChatMessage.ReadWrite.All
) to your app registration. - Get your tenant ID from the Azure portal.
- Clone this repository:
git clone https://github.com/yourusername/microsoft-graph-chat-integration.git
cd microsoft-graph-chat-integration
- Create a virtual environment (optional but recommended):
python3 -m venv venv
source venv/bin/activate
- Install required packages:
pip install -r requirements.txt
- Rename
config.sample.json
toconfig.json
and fill in your app registration details:
{
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"tenant_id": "YOUR_TENANT_ID"
}
- Run the script to retrieve chat messages:
python get_chat_messages.py --chat_id "CHAT_ID"
- Run the script to post a message to a chat:
python post_chat_message.py --chat_id "CHAT_ID" --message "Hello from Microsoft Graph API!"
- Run the script to post a message to a channel:
python post_channel_message.py --channel_id "CHANNEL_ID" --message "Hello from Microsoft Graph API!"
Feel free to contribute to this project by creating issues or pull requests. Your feedback and contributions are welcome!
This project is licensed under the MIT License - see the LICENSE file for details.