Microsoft Teams

Microsoft Teams messages to channels, people and groups through self.microsoft.teams.send.

Zato integrates with Microsoft Teams, letting you send messages to channels, people and groups from your Python services through self.microsoft.teams.send.

The connections are send-only - they are for delivering notifications, alerts and updates from your integrations to the people who need them.

A Teams connection is a Microsoft 365 connection that talks to the Graph API - the same Azure app registration, credentials and authentication, only the screens and the service API differ.

Getting your Microsoft app credentials

The connection uses the same credentials as any other Microsoft 365 one - a tenant ID, a client ID and a client secret of an app registered in your organization. The Microsoft 365 tutorial covers how to obtain them.

In addition, the app registration needs Graph application permissions to work with Teams, granted with admin consent:

  • Team.ReadBasic.All and Channel.ReadBasic.All - to resolve team and channel names to their IDs
  • ChannelMessage.Send - to post messages to channels
  • Chat.ReadWrite.All - to post messages to chats with people and groups

Configuring Zato

  1. Go to ConnectionsChatMicrosoft Teams
  2. Click Create a new connection
  3. Enter a name for the connection, along with the client ID, tenant ID and scopes, and click OK
  4. Click Change secret on the connection's page and enter the client secret

The same screens are also reachable through CloudMicrosoftTeams and VendorsMicrosoftTeams.

The same connections can also be created with enmasse, using the microsoft_teams key:

microsoft_teams:
  - name: My Teams
    client_id: 45678901-4567-4567-4567-4567890abcde
    secret_value: Zato_Enmasse_Env.MicrosoftTeamsSecretValue
    scopes: https://graph.microsoft.com/.default
    tenant_id: 87654321-7654-7654-7654-fedcba987654

Use Ping on the connection's page to confirm that the credentials work.

Sending messages

Messages are sent with self.microsoft.teams.send, giving it the connection's name, the target and the text:

from zato.server.service import Service

class NotifyOnboardingComplete(Service):

    def handle(self):
        self.microsoft.teams.send('My Teams', to='My Team/General', text='All accounts for Jane Doe are ready')

The target can be:

  • A channel, given as Team name/Channel name - the names are resolved to their Graph IDs automatically
  • A chat with a person or a group, given as its chat ID, e.g. 19:b8577894a63548969c5c92bb9c80c5e1@thread.v2

Rich text

The text is HTML, which is how Teams messages deliver rich content:

from zato.server.service import Service

class NotifyDeploymentDone(Service):

    def handle(self):

        text = """
        <b>Deployment finished</b>
        <ul>
            <li>Environment: production</li>
            <li>Status: <i>all checks passed</i></li>
        </ul>
        """

        self.microsoft.teams.send('My Teams', to='My Team/Deployments', text=text)

More than sending

The client behind each connection exposes the full Microsoft 365 client, should you need more than sending messages:

from zato.server.service import Service

class ListTeams(Service):

    def handle(self):

        # The underlying client - its .impl attribute is the same Microsoft 365 client
        # that self.microsoft.cloud connections use.
        client = self.microsoft.teams['My Teams']

        # Use the Graph API directly
        response = client.impl.con.get('https://graph.microsoft.com/v1.0/teams')

        for team in response.json()['value']:
            self.logger.info('Team: %s', team['displayName'])

Learn more