Forum Discussion

dmarquesgn's avatar
dmarquesgn
Iron Contributor
Apr 18, 2023

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

Resources