A user asked for examples of using Realtime DX’s Rest action to send messages to MSFT Teams via the Graph API. It was suggested to follow ControlUp guidelines (https://support.controlup.com/docs/using-webhooks-as-follow-up-action) and use webhooks and Adaptive Cards for Teams. Sample powershell code was provided along with the permissions typically needed (Chat.ReadWrite or ChannelMessage.Send).

Read the entire ‘Sending MSFT Teams Messages with Realtime DX’s Rest Action’ thread below:
Good day all, does anyone have any examples of using Realtime DX’s Rest action to send messages to MSFT Teams leveraging the MSFT Graph API? Having trouble getting the JSON payload formatted correctly. Thanks in advance.
Followed these guidelines? https://support.controlup.com/docs/using-webhooks-as-follow-up-action
Obviously in conjunction with MS specific payload instructions
@member You’ve sent messages via MS Teams, right? Was that via Teams webhooks or via the graph API?
wasn’t needed yet for any graph integrations. Microsoft Teams Webhook created by right clicking the channel -> Integrations and then used PowerShell to leverage adaptive cards – the pretty O365 cards for teams.
Sample code @member:
param (
[string]$webhookUrl = "INSERT-WEBHOOK-URL-HERE"
)
$body = @{
"@type" = "MessageCard"
"@context" = ""
"summary" = "VMware Connection Brokers Health Alert"
"themeColor" = "D8000C"
"title" = "ALERT: VMware Connection Brokers are not healthy"
"sections" = @(
`@{`
`"activityTitle" = "Details"`
`"facts" = @(`
`@{`
`"name" = "Broker 1"`
`"value" = "Not Responding"`
`},`
`@{`
`"name" = "Broker 2"`
`"value" = "Not Responding"`
`},`
`@{`
`"name" = "Broker 3"`
`"value" = "Not Responding"`
`}`
`)`
`"text" = "Immediate attention required. Please check the VMware Connection Brokers as soon as possible."`
`}`
)
} | ConvertTo-Json -Compress -Depth 20
$body = $body -replace ‘\\r\\n’,”
Web hooks are a security issue, so are frowned upon. We’re looking at using Powershell to get to Teams via Graph API
I’d certainly point out the fact a particular webhook would only have access to the explicit channel it was given access to. It also can only post, not read. Either way, I’ll check last I looked the Graph API lacked a lot of the teams functions.
Looks like it most certainly can be done, just haven’t had an opportunity to test it. Here’s an example in PowerShell that interfaces with the Graph API to send a message to a Teams Channel:
# Install the required module
Install-Module -Name Microsoft.Graph.Authentication -Scope CurrentUser
# Import the module
Import-Module Microsoft.Graph.Authentication
# Connect to Microsoft Graph
$clientId = "YOUR-APP-CLIENT-ID"
$tenantId = "YOUR-TENANT-ID"
$clientSecret = "YOUR-APP-SECRET"
$scopes = ""
$tokenRequest = @{
`TenantId = $tenantId`
`ClientId = $clientId`
`ClientSecret = $clientSecret`
`Scope = $scopes`
}
Connect-MgGraph -ClientSecret $tokenRequest
# Set the required parameters
$teamId = "YOUR-TEAM-ID"
$channelId = "YOUR-CHANNEL-ID"
$messageContent = "Hello from PowerShell!"
# Create the message to post
$messageBody = @{
`body = @{`
`content = $messageContent`
`contentType = "text"`
`}`
} | ConvertTo-Json
# Send the message to the channel
$uri = ""
$response = Invoke-MgGraphRequest -Method POST -Uri $uri -Body $messageBody -ContentType "application/json"
# Output the response
$response | ConvertTo-Json | Write-Output
Just FYI @member the permissions you’ll typically need are Chat.ReadWrite for posting messages in a chat or ChannelMessage.Send for sending messages in a channel.
Continue reading and comment on the thread ‘Sending MSFT Teams Messages with ControlUp Realtime DX’s Rest Action’. Not a member? Join Here!
Categories: All Archives, ControlUp Real-Time DX, ControlUp Scripts & Triggers