Open baitsops opened 2 weeks ago
Hey there @peroyvind, mind taking a look at this issue as it has been labeled with an integration (msteams
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
msteams documentation msteams source (message by IssueLinks)
I have also recently received this message within Teams for messages/notifications posted to a channel. Has anyone figured out a way to integrate HA with the Workflows app this message is mentioning? This is a breaking change for this integration, and I'd love to find a way to integrate this "workflows app," but I'm at a loss when it comes to development of an integration for HA.
EDIT: See my next reply for instructions on how to set up your own service for the new Workflows app 🙂
Update: For now, I was able to create a command_line
service to send a notification via the new Workflows app. Here's what I did:
In configuration.yaml
I added the following
...
command_line: !include command_line.yaml
...
Then under /config, I created command_line.yaml
with the following:
- notify:
name: Teams_Workflow
command: "/config/scripts/teams_notify.sh"
Finally, I created a new directory scripts
under /config
and made the following script teams_notify.sh
(so the full path is /config/scripts/teams_notify.sh
):
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0"
exit 1
}
# Read the message from STDIN
message=$(cat)
# Check if the message is provided
if [ -z "$message" ]; then
usage
fi
# Define the JSON payload
json_payload=$(cat <<EOF
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": {
"\$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "$message"
}
]
}
}
]
}
EOF
)
# Send the POST request using curl
curl -X POST "your-webhook-url-here" -H "Content-Type: application/json" -d "$json_payload"
IMPORTANT: replace your-webhook-url-here
in the curl command on the last line with your webhook URL copied from earlier.
Finally, make the script executable with chmod +x /config/scripts/teams_notify.sh
Notifications using command_line
are sent via STDIN so this script picks up that message, defines the JSON payload, and sends it as a POST request using curl. It's a quick and dirty way to do it, but it works. The downside to command_line
is you can only have a simple message with no title, at this time. Adaptive cards are pretty powerful, so if this integration was updated to use the new Workflows app and adaptive cards, the possibilities for the content in the cards are limitless, not just a simple message!
Test from HA:
Message in Teams:
@CU-Jon - Thx this workes great. MS Teams wont let me create a new "Incomming Webhook" as a connector - so I tried it with a workflow. Your bash script did the trick!
The problem
Have begun receiving this in the messages in Teams when using the msteams notification method:
It links to this: https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/
What version of Home Assistant Core has the issue?
core-2024.5.4
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
msteams
Link to integration documentation on our website
https://www.home-assistant.io/integrations/msteams/
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response