Python Power Automate - Teams

Teams channel messages, adaptive cards and direct messages sent through flows.

Posting to Microsoft Teams is one of the most popular things flows do. The pattern is simple - a flow with an HTTP request trigger and a "Post message in a chat or channel" action, and your Python services send it whatever should appear in Teams. The flow owns the Teams side entirely: which team, which channel, what formatting.

Posting a channel message

The service sends the message content, the flow posts it to the channel it was built for.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class NotifyOpsChannel(Service):

    input = 'message'

    def handle(self):

        # Get the connection by its Dashboard name
        conn = self.microsoft.power_platform['My Power Automate']

        # The flow posts the message to the ops channel
        conn.trigger('flow-notify-ops-channel', {
            'message': self.request.input.message,
        })

Alerting on integration errors

A natural use is alerting - a service that detects a problem posts to Teams through the flow, and the on-call team sees it immediately.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ProcessPartnerFeed(Service):

    def handle(self):

        conn = self.microsoft.power_platform['My Power Automate']

        try:
            response = self.out.rest['Partner API'].conn.get(self.cid)
            response.raise_for_status()

        except Exception as e:

            # Let the on-call channel know before re-raising
            conn.trigger('flow-notify-ops-channel', {
                'message': f'Partner feed processing failed: {e}',
            })
            raise

Sending adaptive cards

For richer messages, build the flow around a "Post adaptive card in a chat or channel" action, and send the card's fields from the service. Keeping the card layout in the flow means Teams-side changes never touch your Python code.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class SendDeploymentCard(Service):

    input = 'version', 'environment', 'changelog_url'

    def handle(self):

        conn = self.microsoft.power_platform['My Power Automate']

        # The flow renders these fields into its adaptive card template
        conn.trigger('flow-deployment-card', {
            'title': 'New deployment',
            'version': self.request.input.version,
            'environment': self.request.input.environment,
            'changelog_url': self.request.input.changelog_url,
        })

Messaging a specific person

Flows can also post one-on-one chats - build the flow with a "Post message in a chat" action and send the recipient with the payload.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class NotifyAccountOwner(Service):

    input = 'owner_email', 'account_name'

    def handle(self):

        conn = self.microsoft.power_platform['My Power Automate']

        conn.trigger('flow-direct-message', {
            'recipient': self.request.input.owner_email,
            'message': f'Account {self.request.input.account_name} needs your attention',
        })

More resources

Learn more