Microsoft Teams: Send Message with Attachment

Disclaimer

Your use of this download is governed by Stonebranch’s Terms of Use, which are available at https://www.stonebranch.com/integration-hub/Terms-and-Privacy/Terms-of-Use/

Overview

Microsoft Teams is a collaboration app that helps teams stay organized and have conversations.

This Universal Extension provides the capability to post messages with attachments on a Microsoft Teams channel.

Software Requirements

This Integration requires a Universal Agent and a Python runtime to execute the Universal Task.

Software Requirements for Universal Template and Universal Task

Requires Python 3.7.0 or higher. Tested with the Universal Agent bundled Python distribution.

Software Requirements for Universal Agent

Both Windows and Linux agents are supported:

  • Universal Agent for Windows x64 Version 7.0.0.0 and later with python options installed

  • Universal Agent for Linux Version 7.0.0.0 and later with python options installed

Software Requirements for Universal Controller

Universal Controller Version 7.0.0.0 and later

Network and Connectivity Requirements

Azure Active Directory Requirements

An application must be registered in the Azure Active Directory. See official instructions on Quickstart: Register an application with the Microsoft identity platform

  1. Use as "Supported account Types" option "Accounts in this organizational directory only".

  2. When registration finishes an Application (client) ID is generated (required as part of Extension Task configuration).

  3. Configure API permissions.

  • Assign the following Microsoft Graph API permissions.

    API / Permissions name

    Type

    Description

    ChannelMessage.Send

    Delegated

    Send channel messages

    Channel.ReadBasic.All

    Delegated

    Read the names and descriptions of channels.

    Files.ReadWrite.All

    Delegated

    Have full access to all files user can access.

    Team.ReadBasic.All

    Delegated

    Read the names and descriptions of teams.

    User.Read

    Delegated

    Sign in and read user profile.

  • Grant admin consent.

4. Create a client secret -> Add client secret (client secret is required as part of Extension Task configuration).

Key Features

This Universal Extension provides the following main features:

  • Support to post a message with an attachment on a Microsoft Teams channel.

  • Support for authentication to Microsoft Teams with Oauth2 ROPC (Resource Owner Password Credentials) grant type.

  • Support for automatic renewal of access token when expired.

  • Support for different attachment handling options in case an attachment already exists in Microsoft Sharepoint (fail, replace, rename).

This extension makes sure that the attachment is first uploaded on Microsoft Sharepoint and then used as attachment in the message sent to Microsoft Teams.

Import the Universal Template

To use this downloadable Universal Template, you first must perform the following steps:

  1. This Universal Task requires the Resolvable Credentials feature. Check that the Resolvable Credentials Permitted system property has been set to true.
  2. Download the provided ZIP file.
  3. In the Universal Controller UI, select Configuration > Universal Templates to display the current list of Universal Templates.
  4. Click Import Template.
  5. Select the template ZIP file and Import.

When the template has been imported successfully, the Universal Template will appear on the list. Refresh your Navigation Tree to see these tasks in the Automation Center Menu.

Configure Universal Task

For the new Universal Task type, create a new task, and enter the task-specific details that were created in the Universal Template.

Input Fields

The input fields for this Universal Extension are described below.

Field

Input type

Default value

Type

Description

Action

Required

Monitor Attachments

Choice

The action performed upon the task execution

Client Credentials

Required

-

Credentials

The credentials for the application registered in the Azure Active Directory.

They are comprised of:

  • Application (client) ID

  • Client secret : The client secret issued to the client during Application registration process

Resource Owner Credentials

Required

-

Credentials

The user's credentials for Microsoft 365.

They are comprised of:

  • username

  • password

Channel Identifier

Required

Channel Link

Choice

The Type of identifier for the channel.

For example: Channel Link to provide the URL

Channel Link

Optional

-

Text

The URL link of the required channel.

Required if Channel Identifier is "Channel Link".

Attachment

Required

-

Text

The full local path of the required file.

Message

Required

-

Text

The message that will be posted in Microsoft Teams along with the attachment.

SharePoint Filename

Optional

-

Text

The name that the file will have on SharePoint. If none is provided, the file will be saved with the same name as in the local path.

SharePoint File Creation Option

Required

Fail

Choice

Specifies how to proceed in case a file with the same name (SharePoint Filename) already exists on SharePoint.

Available options are :

  • Fail (The upload will be cancelled.)

  • Replace (The existing file will be replaced by the new file.)

  • Rename (The new file will be saved with a unique file name.) The default SharePoint renaming behavior is adding an incremental counter at the end of the name before the prefix; for example, file.txt, file (1).txt, file (2).txt)

Task Examples

Post Attachment

Follow the steps below to create a Task.

  1. Give the task a name (for example, sample-1-task-1).

  2. Select an active agent of version 7.0.0.0 or higher for the task to run on.

  3. Select the Action.

  4. Set your Client Credentials.

  5. Set your Resource Owner Credentials.

  6. Select the Channel Identifier.

  7. Enter the required Channel Link. An easy way to retrieve this is from the Microsoft Teams UI:



  8. In the Attachment field enter the local path where the file is located.

  9. Type a Message.

  10. Enter the SharePoint Filename.

  11. Select the SharePoint File Creation Option.

Additional Notes

In case the extension is used to send a message to a brand new channel that does not have any message, it is likely that it fails because the SharePoint folder is not yet created.

This is a common issue of MS Teams. The solution is either to post a message in the channel or to open the "Files" tab on Teams to bootstrap manually the creation of the folder on SharePoint.

Document References

This document references the following documents:

Name

Description

Universal Templates

User documentation for creating Universal Templates in the Universal Controller user interface.

Universal Tasks

User documentation for creating Universal Tasks in the Universal Controller user interface.

Disclaimer

Your use of this download is governed by Stonebranch’s Terms of Use, which are available at https://www.stonebranch.com/integration-hub/Terms-and-Privacy/Terms-of-Use/

Overview

Microsoft Teams is a collaboration app that helps teams stay organized and have conversations.

This Universal Extension provides the capability to post messages with attachments on a Microsoft Teams channel.

Software Requirements

This Integration requires a Universal Agent and a Python runtime to execute the Universal Task.

Software Requirements for Universal Template and Universal Task

Requires Python 3.7.0 or higher. Tested with the Universal Agent bundled Python distribution.

Software Requirements for Universal Agent

Both Windows and Linux agents are supported:

  • Universal Agent for Windows x64 Version 7.0.0.0 and later with python options installed

  • Universal Agent for Linux Version 7.0.0.0 and later with python options installed

Software Requirements for Universal Controller

Universal Controller Version 7.0.0.0 and later

Network and Connectivity Requirements

Azure Active Directory Requirements

An application must be registered in the Azure Active Directory. See official instructions on Quickstart: Register an application with the Microsoft identity platform

  1. Use as "Supported account Types" option "Accounts in this organizational directory only".

  2. When registration finishes an Application (client) ID is generated (required as part of Extension Task configuration).

  3. Configure API permissions.

  • Assign the following Microsoft Graph API permissions.

    API / Permissions name

    Type

    Description

    ChannelMessage.Send

    Delegated

    Send channel messages

    Channel.ReadBasic.All

    Delegated

    Read the names and descriptions of channels.

    Files.ReadWrite.All

    Delegated

    Have full access to all files user can access.

    Team.ReadBasic.All

    Delegated

    Read the names and descriptions of teams.

    User.Read

    Delegated

    Sign in and read user profile.

  • Grant admin consent.

4. Create a client secret -> Add client secret (client secret is required as part of Extension Task configuration).

Key Features

This Universal Extension provides the following main features:

  • Support to post a message with an attachment on a Microsoft Teams channel.

  • Support for authentication to Microsoft Teams with Oauth2 ROPC (Resource Owner Password Credentials) grant type.

  • Support for automatic renewal of access token when expired.

  • Support for different attachment handling options in case an attachment already exists in Microsoft Sharepoint (fail, replace, rename).

This extension makes sure that the attachment is first uploaded on Microsoft Sharepoint and then used as attachment in the message sent to Microsoft Teams.

Import the Universal Template

To use this downloadable Universal Template, you first must perform the following steps:

  1. This Universal Task requires the Resolvable Credentials feature. Check that the Resolvable Credentials Permitted system property has been set to true.
  2. Download the provided ZIP file.
  3. In the Universal Controller UI, select Configuration > Universal Templates to display the current list of Universal Templates.
  4. Click Import Template.
  5. Select the template ZIP file and Import.

When the template has been imported successfully, the Universal Template will appear on the list. Refresh your Navigation Tree to see these tasks in the Automation Center Menu.

Configure Universal Task

For the new Universal Task type, create a new task, and enter the task-specific details that were created in the Universal Template.

Input Fields

The input fields for this Universal Extension are described below.

Field

Input type

Default value

Type

Description

Action

Required

Monitor Attachments

Choice

The action performed upon the task execution

Client Credentials

Required

-

Credentials

The credentials for the application registered in the Azure Active Directory.

They are comprised of:

  • Application (client) ID

  • Client secret : The client secret issued to the client during Application registration process

Resource Owner Credentials

Required

-

Credentials

The user's credentials for Microsoft 365.

They are comprised of:

  • username

  • password

Channel Identifier

Required

Channel Link

Choice

The Type of identifier for the channel.

For example: Channel Link to provide the URL

Channel Link

Optional

-

Text

The URL link of the required channel.

Required if Channel Identifier is "Channel Link".

Attachment

Required

-

Text

The full local path of the required file.

Message

Required

-

Text

The message that will be posted in Microsoft Teams along with the attachment.

SharePoint Filename

Optional

-

Text

The name that the file will have on SharePoint. If none is provided, the file will be saved with the same name as in the local path.

SharePoint File Creation Option

Required

Fail

Choice

Specifies how to proceed in case a file with the same name (SharePoint Filename) already exists on SharePoint.

Available options are :

  • Fail (The upload will be cancelled.)

  • Replace (The existing file will be replaced by the new file.)

  • Rename (The new file will be saved with a unique file name.) The default SharePoint renaming behavior is adding an incremental counter at the end of the name before the prefix; for example, file.txt, file (1).txt, file (2).txt)

Task Examples

Post Attachment

Follow the steps below to create a Task.

  1. Give the task a name (for example, sample-1-task-1).

  2. Select an active agent of version 7.0.0.0 or higher for the task to run on.

  3. Select the Action.

  4. Set your Client Credentials.

  5. Set your Resource Owner Credentials.

  6. Select the Channel Identifier.

  7. Enter the required Channel Link. An easy way to retrieve this is from the Microsoft Teams UI:



  8. In the Attachment field enter the local path where the file is located.

  9. Type a Message.

  10. Enter the SharePoint Filename.

  11. Select the SharePoint File Creation Option.

Additional Notes

In case the extension is used to send a message to a brand new channel that does not have any message, it is likely that it fails because the SharePoint folder is not yet created.

This is a common issue of MS Teams. The solution is either to post a message in the channel or to open the "Files" tab on Teams to bootstrap manually the creation of the folder on SharePoint.

Document References

This document references the following documents:

Name

Description

Universal Templates

User documentation for creating Universal Templates in the Universal Controller user interface.

Universal Tasks

User documentation for creating Universal Tasks in the Universal Controller user interface.