Thank you for posting your question in the Microsoft Q&A forum and for sharing your detailed setup and the steps you've taken so far.
As a Microsoft Q&A forum moderator, I want to clarify that I don’t have access to your specific bot configuration, tenant environment, or deployment details. My role is to help guide users by sharing insights and suggestions based on publicly available documentation and community discussions. While I can't provide a definitive fix, I hope the following information helps you move closer to a solution.
Your issue with the 401 Unauthorized error when sending messages to a Teams channel via the Azure Bot Framework likely stems from mismatches in the conversation ID, token validation, API permissions, or payload structure. Based on your setup and common causes for this error, here’s a streamlined troubleshooting guide:
1. Validate the Access Token
Use jwt.ms to decode your token and confirm:
- aud (audience) is https://api.botframework.com
- appid matches your Microsoft App ID
- Token is not expired
If any of these are incorrect, regenerate your client secret (avoid special characters) and retry the token request.
2. Use the Correct Conversation ID and Service URL
- Use the channel-wide conversationId from the conversationUpdate event when the bot is added to the channel. Format should be like:
19:<channel_id>@thread.skype - Ensure the serviceUrl exactly matches the one received in the webhook (e.g., https://smba.trafficmanager.net/emea/)
- Avoid creating new conversations—proactive messaging requires an existing conversation context.
3. Confirm API Permissions and App Registration
In Azure Portal > App Registrations > Your App > API Permissions:
- Ensure Bot Framework or ChannelMessage.Send is added, and admin consent is granted.
- Under Enterprise Applications, confirm the service principal exists. If not, create one and assign roles like Contributor.
4. Verify Teams App Manifest
- botId matches your App ID
- validDomains includes token.botframework.com
- Scopes include team and groupchat
5. Refined Message Payload
Here’s an updated curl example using the structure you asked about:
curl -X POST "v3/conversations/<conversation_id>/activities" \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"type": "message",
"text": "Test message",
"from": {
"id": "",
"name": ""
},
"conversation": {
"id": "",
"name": ""
}
}'
Make sure all placeholders are replaced with accurate values from your Teams environment.
If the issue still persists after trying these suggestions, I recommend posting your question on the Microsoft TechCommunity where product experts and engineers actively engage and may be able to provide deeper insights based on your specific scenario.
I hope the above suggestions helpful to you. If you have any further questions, feel free to reach out again!
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.