home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.06k stars 29.13k forks source link

O365 connectors within Microsoft Teams will be deprecated and notifications from this service will stop #121574

Open baitsops opened 2 weeks ago

baitsops commented 2 weeks ago

The problem

Have begun receiving this in the messages in Teams when using the msteams notification method:

Action Required: O365 connectors within Teams will be deprecated and notifications from this service will stop. Learn more about the timing and how the Workflows app provides a more flexible and secure experience. If you want to continue receiving these types of messages, you can use a workflow to post messages from a webhook request.

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

home-assistant[bot] commented 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!

Code owner commands Code owners of `msteams` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign msteams` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


msteams documentation msteams source (message by IssueLinks)

CU-Jon commented 1 week ago

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 🙂

CU-Jon commented 6 days ago

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:

  1. Create a new Workflows app in Teams using the link in one of the messages sent to the Teams channel by HA (Click Set up workflow)
  2. At the end of the wizard, copy your webhook URL. You'll need this for later.
  3. Once the workflow app is created, go to workflows for the channel, and edit the workflow
  4. Drop down "Send each adaptive card"
  5. Drop down "Post your own adaptive card as the Flow bot to a channel"
  6. Clear out (click the X) for the Team, then select the dropdown and select the appropriate Team
  7. Do the same for the Channel
  8. Then on to the configuration for HA:

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: image

Message in Teams: image

moarph commented 5 days ago

@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!