Forum Discussion
Send Teams message over unattended script
Hi,
I have some scripting to perform some security tasks, and I would like to send a Teams message to a group with the results of the scripting. So I've got this code, which is working fine:
Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All,Chat.Read,Chat.ReadWrite,ChatMember.ReadWrite,Chat.ReadBasic"
$chatId = "19:c83c84a4abd142aeb2922f8ed22f4811@thread.v2"
$params = @{
Body = @{
Content = "Test Message"
}
}
New-MgChatMessage -ChatId $chatId -BodyParameter $params
And everything goes well. But I need an unattended script, so I connecto to MgGraph this way:
Connect-MgGraph -ClientId "clientid" -TenantId "tenantid" -CertificateThumbprint "certificatethumbprint"
But I've got this error:
New-MgChatMessage : Message POST is allowed in application-only context only for import purposes. Refer to https://docs.microsoft.com/microsoftteams/platform/graph-api/import-messages/import-external-messages-to-teams for more details.
So it's not an issue with permissions. Anyone faced the same issue and knows how to solve it?
Thanks
- Andres-BohrenSteel Contributor
Hi dmarquesgn
It's not supported with Application Authentication
https://learn.microsoft.com/en-us/graph/api/chat-post-messages?view=graph-rest-1.0&tabs=http
What about some Alternatives:
- Send an Email to a Teams Channel
- Use a Webhook to send a Message
Regards
Andres