# Send Images to Microsoft Teams

Send device images uploaded to Harvest Files to Microsoft Teams.

## Introduction

[Soracom Flux](https://docs.soracom.io/en/services/flux) is a low-code IoT application builder designed for advanced automation.

In this guide, we send images to a Microsoft Teams channel using a [Soracom Flux Webhook Action](https://docs.soracom.io/en/services/flux/webhook). It walks you through setting up a seamless integration between Soracom Flux and Microsoft Teams. By configuring a Microsoft Power Automate workflow to receive and process webhook requests and by creating a Flux App complete with channels and webhook actions, you can automate the delivery of notifications to your Teams channel.

> [!WARNING]
>
> Refer to the [Pricing & Fee Schedule](https://docs.soracom.io/en/pricing#soracom-flux) for detailed information on Soracom Flux pricing. Soracom Flux includes a free tier providing limited usage for certain features at no cost.

## Requirements

For this project, you will need the following:

- A Soracom Account
  - If you don't already have a Soracom account, follow the steps in the [Quick Start guide](https://docs.soracom.io/en/guides/quick-start).

- An Account and a License for Microsoft Power Automate and Microsoft Teams

  - For more information, refer to the following:

    - [Microsoft Teams admin documentation](https://learn.microsoft.com/en-us/microsoftteams/)
    - [Microsoft Power Automate documentation](https://learn.microsoft.com/en-us/power-automate/)

- A Notification Channel in Microsoft Teams
  - [Create a standard, private, or shared channel in Microsoft Teams](https://support.microsoft.com/en-us/office/create-a-standard-private-or-shared-channel-in-microsoft-teams-fda0b75e-5b90-4fb8-8857-7e102b014525)

## Create a Workflow in Microsoft Power Automate

Build a workflow using Microsoft Power Automate that acts as the intermediary between Soracom Flux and Microsoft Teams. The workflow is designed to receive a webhook request from Flux, process the payload, and then post the message to a designated Teams channel.

1. Sign in to [Microsoft Power Automate](https://make.powerautomate.com/).

2. Click + **Create** in the left navigation panel.

   ![Screenshot of the Microsoft Power Automate console showing the Create option.](https://docs.soracom.io/_astro/power-automate01.C_Ov96df_Z2rldM.webp)

3. Click **Instant cloud flow**.

   ![Screenshot illustrating how to select Instant cloud flow in Microsoft Power Automate.](https://docs.soracom.io/_astro/power-automate02.BLQkIYr-_Bbnwe.webp)

4. Enter a **Flow name**.

   ![Screenshot highlighting the Flow Name input field in Microsoft Power Automate.](https://docs.soracom.io/_astro/soracom-flux-images-msteams-power-automate03.BINYCdav_Z1reRDG.webp)

5. From **Choose how to trigger this flow**, select **When a Teams webhook request is received**, then click **Create**.

   ![Screenshot showing the trigger selection When a Teams webhook request is received in Microsoft Power Automate.](https://docs.soracom.io/_astro/power-automate04.DC3JX9_W_Z2tHwiB.webp)

6. Click the + button to add an action.

   ![Screenshot demonstrating how to add a new action (via the plus button) in Microsoft Power Automate.](https://docs.soracom.io/_astro/soracom-flux-images-msteams-power-automate06.xPqIlmOx_ZWrF9c.webp)

7. In **Add an action**, enter **Post a card in a chat or channel** and select **Post a card in a chat or channel**.

   ![Screenshot of the action search panel for Post message in a chat or channel.](https://docs.soracom.io/_astro/soracom-flux-images-msteams-power-automate07.V5l8RMuG_Z1XNwCT.webp)

   > [!WARNING]
   >
   > Sign in to Microsoft Teams.
   >
   > If you are not already signed in to Microsoft Teams, [sign in](https://teams.microsoft.com/v2/) and create a connection to Microsoft Teams. Click **Sign In** and follow the on-screen instructions.

8. Configure the following fields:

   ![Screenshot showing the configuration fields for posting a message as a Flow bot to a specific Microsoft Teams channel.](https://docs.soracom.io/_astro/soracom-flux-images-msteams-power-automate08.DV_1023y_oxwS4.webp)

   - **Post as**: Select **Flow bot**.
   - **Post in**: Select **Channel**.
   - **Team**: Select the target team.
   - **Channel**: Select the target channel.

   > [!WARNING]
   >
   > For more information about the settings, see [Send a message in Teams using Power Automate](https://learn.microsoft.com/en-us/power-automate/teams/send-a-message-in-teams).

9. Click the **Adaptive Card** input field, then click the button.

   ![Screenshot highlighting the Adaptive Card button.](https://docs.soracom.io/_astro/soracom-flux-images-msteams-power-automate09.BWl_WZXJ_ZOs67M.webp)

10. Click **Attachments Adaptive Card**.

    ![Screenshot displaying the Attachments Adaptive Card option in Microsoft Power Automate.](https://docs.soracom.io/_astro/soracom-flux-images-msteams-power-automate10.C5GHVvqI_22c68z.webp)

    > [!WARNING]
    >
    > For more details on Adaptive Cards, see [Create your first adaptive card](https://learn.microsoft.com/en-us/power-automate/create-adaptive-cards).

11. Click the **When a Teams webhook request is received** component and in the left navigation panel, select **Anyone** under **Who can trigger the flow?**.

    ![Screenshot of the Who can trigger the flow setting set to Anyone.](https://docs.soracom.io/_astro/soracom-flux-images-msteams-power-automate05.BEzh7DO4_Z28uWt2.webp)

12. Click 💾 **Save** to save your flow.

13. Click the **When a Teams webhook request is received** trigger to see the **HTTP URL** provided in the flow and click the button to copy the value.

    ![Screenshot emphasizing the HTTP URL field in the When an HTTP request is received trigger.](https://docs.soracom.io/_astro/soracom-flux-images-msteams-power-automate11.D9UZxvBS_Z1lLSgv.webp)

    The **HTTP URL** will be used in the next step when configuring the [Webhook Action](https://docs.soracom.io/en/services/flux/webhook) in Soracom Flux.

    > [!WARNING]
    >
    > **To see the HTTP URL again**:
    >
    > 1. Open the left navigation panel.
    > 2. Select **My flows**, then the Cloud flow you created.
    > 3. Click ✏ **Edit**.
    > 4. Click the **When a Teams webhook request is received** trigger.

## Create a Flux App

A [Flux app](https://docs.soracom.io/en/services/flux) can integrate various forms of inputs and apply sophisticated business logic to achieve desired outcomes.

1. Sign in to the **[User Console](https://console.soracom.io/?coverage_type=g)**. From the **☰ Menu**, expand **Soracom Flux** and select **Flux Apps**.

2. Click **+ Create a new Flux app**.

3. Name the Flux app and provide an optional description, then click **Create**.

   The Flux app will be created and the **Studio** tab in **Soracom Flux Studio** will automatically be displayed.

### Create a Channel

A channel is a Flux [component](https://docs.soracom.io/en/services/flux#components) that connects an event source to actions in your Flux app.

1. Open the **Studio** tab in **Soracom Flux Studio**:

   - If you have just created a Flux app, you will already be in the **Studio** tab.
   - If you are returning, follow Step 1 under [Create a Flux App](https://docs.soracom.io/en/services/flux/ms-teams-images/#create-a-flux-app) to access your **Flux Apps**, then select your app to open the **Studio** tab.

2. Click **+ Create a channel**.

3. Choose **Soracom Harvest Files** as the [event source](https://docs.soracom.io/en/services/flux/harvest-files) and click **Next**.

4. Configure the following:

   ![Image of a dialog showing controls for the configuration items listed above](https://docs.soracom.io/_astro/harvest-file-event-channel.CKMCPlxC_Ge6ig.webp)

   - **Name**: Name your channel.

   - **Description**: Optionally provide a summary of the channel.

   - **Event source config**:

     - Enable **Soracom Harvest Files**.

     - Set **File Path prefix** for image file uploads:

       - Enter the desired path (e.g., `/flux/latest.jpg`).

         Files with paths that match this prefix will trigger events.

     - Select **Event Types** to trigger the event source:
       - Check **File Created** and **File Updated**.

5. Click **Create a new channel**.

6. After confirming that your configuration is correct, click the ✕ to return to the **Studio** tab.

### Create a Webhook Action

An [action](https://docs.soracom.io/en/services/flux/actions) is a component that can be added to a channel that can conditionally process information from an event source to execute a desired effect.

This step configures a Webhook action within your Flux app. When triggered, the action sends a message to your selected Microsoft Teams channel.

1. Click on the channel created in the [previous section](https://docs.soracom.io/en/services/flux/ms-teams-images/#create-a-channel) to open the configuration dialog, then select the **Actions** tab and click **+ Add Action**.

   ![add action](https://docs.soracom.io/_astro/flux-add-action.Cgn-t-WH_Z9TcID.webp)

2. In the **Create a new action** dialog, choose **Webhook** as your action type, then click **OK**.

3. Configure the following:

   - **Name**: Enter an action name.

   - **Description**: Optionally provide a summary.

   - **Enabled**: Set the action to enabled.

   - **Condition**:

     - **Action Condition**: Define when the action should trigger.

       In this case, leave this field blank so that the action executes each time it is called.

4. Configure the following in the **Config** section of the dialog:

   - **HTTP Method**: Select **POST**.

   - **URL**: Enter the URL obtained from [Create a Workflow in Microsoft Power Automate](https://docs.soracom.io/en/services/flux/ms-teams-images/#create-a-workflow-in-microsoft-power-automate).

   - **Auth Type**: Select **None**.

   - **HTTP Header**: Set the HTTP header to `Content-Type: application/json` for the Webhook HTTP request.

     Selecting **application/json** for **HTTP Body** automatically sets this value to `Content-Type: application/json`.

   - **HTTP Body**: Select **application/json** to set the HTTP body of the Webhook HTTP request and enter the following in JSON:

     ```json
     {
       "type": "message",
       "attachments": [
         {
           "contentType": "application/vnd.microsoft.card.adaptive",
           "contentUrl": null,
           "content": {
             "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
             "type": "AdaptiveCard",
             "version": "1.4",
             "body": [
               {
                 "type": "TextBlock",
                 "text": "File: ${event.payload.eventType}",
                 "size": "Large",
                 "wrap": true,
                 "style": "heading"
               },
               {
                 "type": "TextBlock",
                 "text": "Path: ${event.payload.path}",
                 "size": "Medium",
                 "weight": "Lighter",
                 "wrap": true
               },
               {
                 "type": "ImageSet",
                 "images": [
                   {
                     "type": "Image",
                     "url": "${event.payload.presignedUrls.get}",
                     "altText": "cats"
                   }
                 ]
               }
             ]
           }
         }
       ]
     }
     ```

     See [Adaptive Cards](https://learn.microsoft.com/en-us/adaptive-cards/) for more information on formatting.

   > [!WARNING]
   >
   > `"url": "${event.payload.presignedUrls.get}"`:
   >
   > In the [Create a Channel](https://docs.soracom.io/en/services/flux/harvest-files) section, the URL of the image file that is created or updated in Harvest Files is specified. For information about variables, operators, and functions that can be specified in the action, see [Expression Syntax Reference](https://docs.soracom.io/en/services/flux/action-expressions#expression-syntax-reference).

5. Configure the following in the **Output** section of the dialog:

   - **Republish this action output to another channel**: Set republishing to **Disabled**.

6. Click **Create**.

7. After confirming that your configuration is correct, click the ✕ to return to the **Studio** tab and see the new channel.

## Testing

### Upload an Image

Upload the image file to a path starting with `/flux` in Harvest Files so that it meets the conditions specified above. For instructions on uploading files to Harvest Files, see [Uploading Files](https://docs.soracom.io/en/services/harvest/uploading-files).

### Verify That Notifications Are Being Received in Microsoft Teams

1. Open [Microsoft Teams](https://teams.microsoft.com/v2/).

2. Click **Teams** and select your channel.

   The image should be displayed in the channel.

### Check the Execution History of the Flux App

1. Sign in to the **[User Console](https://console.soracom.io/?coverage_type=g)**. From the **☰ Menu**, expand **Soracom Flux** and select **Flux Apps**.

2. Click on the Flux app you created.

3. Select the **History** tab.

   For each channel, the Message, Context, Input, and Output of the action executed from that channel are displayed.

> [!WARNING]
>
> To learn about detailed logging, see the [View Logs](https://docs.soracom.io/en/services/flux/logs) documentation.
