I'm attempting to send a message to a Teams channel programmatically. Nothing special or fancy going on.
The payload (JSON encoded):
%{
"createdDateTime" => DateTime.utc_now(),
"from" => %{
"user" => %{
"id" => @user_id,
"displayName" => @display_name,
"userIdentityType" => "aadUser"
}
},
"body" => %{
"content" => message
}
}
My request URL:
https://graph.microsoft.com/v1.0/teams/<team_id>/channels/<channel_id>/messages
Headers have the authorization bearer token and the Content-Type set to application/json
As far as I know (I don't have direct access to the environment), we have the api permission set to delegate permissions, not application permissions. The role has the ChannelMessage.Send permission. I receive this response:
error: %{
code: "Forbidden",
message: "InsufficientPrivileges",
innerError: %{
code: "1",
message: "MessageWritesBlocked-Thread is not marked for import",
date: "2024-03-27T16:55:18",
"request-id": "947c97a0-2bdb-4168-b18e-bdebf8de6c86",
"client-request-id": "947c97a0-2bdb-4168-b18e-bdebf8de6c86"
}
}
The roles sent back in the access token are the following:
"roles": [
"Chat.UpdatePolicyViolation.All",
"Teamwork.Migrate.All",
"Directory.ReadWrite.All",
"Team.Create",
"Group.ReadWrite.All",
"Chat.ReadWrite.WhereInstalled",
"Chat.Read.WhereInstalled",
"Chat.Read.All",
"Chat.ReadBasic.WhereInstalled",
"Chat.ReadWrite.All",
"Chat.ReadBasic.All",
"Chat.ManageDeletion.All",
"Chat.Create"
]
Any assistance with this error, as to what permissions/roles I may be missing or other help would be appreciated as usual.
You need to check API permissions and ensure that the Microsoft Graph API permission ChannelMessage.Send is correctly set up. For sending messages to a Teams channel, delegated permissions are required, but you might also need ChannelMessage.Send specifically for this task.