Power Automate Workflows

Inbound workflow

The "Post PB Message from Webhook" workflow in Power Automate is designed to process incoming data from a webhook and post structured messages to a Microsoft Teams channel using adaptive cards. This workflow acts as a bridge between SAP and Teams

Importing

In Power Automate, navigate to 'My Flows' in the left hand menu.

At the top of the page, click on the 'Import' button. This will open the import screen where you can upload your workflow.

Select 'Import Package (Legacy)' and select the workflow package file (Post_PB_Message_From_Webhook.zip) from your local machine.

After the workflow is uploaded, you will see a list of resources in the package.

You will need to action the related resource and re-establish the connections. You will need to authenticate with the appropriate credentials for the services the workflow uses.

Once all resources are configured, click the 'Import' button at the bottom of the page.

Outbound workflow

The outbound workflow is designed to handle responses to adaptive cards within Microsoft Teams.

When a user interacts with an adaptive card, the workflow captures key information such as the message source system, message ID, user details, and the response provided. This data is then passed to a HTTP POST method, which facilitates the integration by sending the response back to SAP.

Importing a flow from a package file

For the outbound workflow, you can follow the same steps as for the inbound flow (above), but additional modifications will be necessary within the package content.

Select 'Import Package (Legacy)' and select the workflow package file (Handle_PB_Message_response.zip) from your local machine.

For the resource type flow select the Update or Action Spanner.

On the Import Setup, under the field Setup, select “Create as new” and give Resource name “Handle PB Message Response”.

You must configure the related resource and re-establish the connections, following the same process as the inbound workflow. Ensure you authenticate using the correct credentials for the services utilized by the workflow. If a connection is not available, select 'Create New' and add the required connection.

Amending Outbound Workflow

After importing the package file, locate the workflow. Select 'More Commands' and then select 'Edit'.

Review each step in the workflow to ensure accuracy.

Populate the following parameters:

“When someone responds to an adaptive card”

Inputs adaptive card

{
                "type": "AdaptiveCard",
                "version": "1.3",
                "body": [
                    {
                        "type": "ColumnSet",
                        "columns": [
                            {
                                "type": "Column",
                                "width": "50px",
                                "items": [
                                    {
                                        "type": "ImageSet",
                                        "images": [
                                            {
                                                "type": "Image",
                                                "size": "Small",
                                                "url": "https://portal.theconfigteam.co.uk/images/mnu_box_icon.png"
                                            }
                                        ],
                                        "imageSize": "Small"
                                    }
                                ]
                            },
                            {
                                "type": "Column",
                                "width": "stretch",
                                "items": [
                                    {
                                        "type": "TextBlock",
                                        "text": "Message from PreBilt",
                                        "size": "Medium",
                                        "weight": "Bolder",
                                        "wrap": true,
                                        "style": "heading"
                                    }
                                ],
                                "verticalContentAlignment": "Center"
                            }
                        ]
                    },
                    {
                        "type": "FactSet",
                        "facts": [
                            {
                                "title": "Date:",
                                "value": "{date}"
                            },
                            {
                                "title": "SAP User:",
                                "value": "{sap_user}"
                            },
                            {
                                "title": "Email:",
                                "value": "{email}"
                            },
                            {
                                "title": "Name:",
                                "value": "{name}"
                            }
                        ],
                        "spacing": "Medium",
                        "separator": true
                    },
                    {
                        "type": "TextBlock",
                        "text": "Message:",
                        "wrap": true,
                        "spacing": "Medium",
                        "weight": "Bolder"
                    },
                    {
                        "type": "TextBlock",
                        "text": "{message}",
                        "wrap": true
                    }
                ],
                "actions": [
                    {
                        "type": "Action.ShowCard",
                        "title": "Send Reply",
                        "card": {
                            "type": "AdaptiveCard",
                            "body": [
                                {
                                    "type": "Input.Text",
                                    "id": "message",
                                    "isMultiline": true,
                                    "label": "Add a message"
                                },
                                {
                                    "type": "Input.Text",
                                    "isVisible": false,
                                    "id": "msgID",
                                    "value": "{msgID}"
                                },
                                {
                                    "type": "Input.Text",
                                    "isVisible": false,
                                    "id": "msgSourceSys",
                                    "value": "{msgSourceSys}"
                                },
                            ],
                            "actions": [
                                {
                                    "type": "Action.Submit",
                                    "title": "Send"
                                }
                            ]
                        }
                    }
                ]
            }

Card Type ID

PB_EWM_OM_Message

“Get user profile (V2)”

User (UPN)

@{triggerBody()?['entity']?['teamsFlowRunContext']?['messagePayload']?['from']?['user']?['id']}
“Reply with an adaptive card in a channel”

Post As - Flow bot

Post In - Channel

Message ID

@{triggerBody()?['entity']?['teamsFlowRunContext']?['messagePayload']?['id']}

Team

{"source":"la-draft-clipboard","value":[{"tokenKey":"A425FA86-3499-4557-A388-052C538376C8","type":"token","token":{"source":"body","name":"entity.teamsFlowRunContext.channelData.team.aadGroupId","required":false,"value":"triggerBody()?['entity']?['teamsFlowRunContext']?['channelData']?['team']?['aadGroupId']","title":"Team ID","key":"body.$.rows.[*].entity.teamsFlowRunContext.channelData.team.aadGroupId","type":"string","isInsideArray":false,"parentArray":"rows","description":"The ID of the Team from which this activity is started","icon":"https://conn-afd-prod-endpoint-bmc9bqahasf3grgk.b01.azurefd.net/v1.0.1754/1.0.1754.4231/teams/icon.png","brandColor":"#474747"},"tokenExpression":"triggerBody()?['entity']?['teamsFlowRunContext']?['channelData']?['team']?['aadGroupId']"}]}

Channel

{"source":"la-draft-clipboard","value":[{"tokenKey":"A35F66DC-E7ED-4F91-B78B-66471A3AFFD3","type":"token","token":{"source":"body","name":"entity.teamsFlowRunContext.channelData.channel.id","required":false,"value":"triggerBody()?['entity']?['teamsFlowRunContext']?['channelData']?['channel']?['id']","title":"Channel ID","key":"body.$.rows.[*].entity.teamsFlowRunContext.channelData.channel.id","type":"string","isInsideArray":false,"parentArray":"rows","description":"The channel ID for this activity","icon":"https://conn-afd-prod-endpoint-bmc9bqahasf3grgk.b01.azurefd.net/v1.0.1754/1.0.1754.4231/teams/icon.png","brandColor":"#474747"},"tokenExpression":"triggerBody()?['entity']?['teamsFlowRunContext']?['channelData']?['channel']?['id']"}]}

Adaptive card

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "items": [
                        {
                            "type": "Component",
                            "name": "graph.microsoft.com/user",
                            "view": "compact",
                            "properties": {
                                "id": "@{outputs('Get_user_profile_(V2)')?['body/id']}",
                                "displayName": "@{outputs('Get_user_profile_(V2)')?['body/displayName']}",
                                "userPrincipalName": "@{outputs('Get_user_profile_(V2)')?['body/userPrincipalName']}"
                            }
                        },
                    ],
                    "width": "auto"
                },
                {
                    "type": "Column",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "@{formatDateTime(utcNow(), 'HH:mm')} UTC",
                            "wrap": true,
                            "size": "Small",
                            "isSubtle": true
                        }
                    ],
                    "width": "stretch",
                    "verticalContentAlignment": "Center"
                }
            ]
        },
        {
            "type": "TextBlock",
            "text": "@{triggerBody()?['entity']?['cardOutputs']?['message']}",
            "wrap": true
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3"
}

Insert a new step below 'Get user profile (V2)':

Select 'Add an Action' and search for 'HTTP'.

Select action 'HTTP PREMIUM':

Populate the following parameters:

Method - POST

URL - PreBilt URL, with /ztctm_ewm_om on the end

Body

{
  "MSGSOURCESYS": "@{triggerBody()?['entity']?['cardOutputs']?['msgSourceSys']}",
  "MSGID": "@{triggerBody()?['entity']?['cardOutputs']?['msgID']}",
  "MSGUSERID": "@{outputs('Get_user_profile_(V2)')?['body/mail']}",
  "MSGUSERNAME": "@{outputs('Get_user_profile_(V2)')?['body/displayName']}",
  "MSGACTION": "SendReply",
  "MSG": "@{triggerBody()?['entity']?['cardOutputs']?['message']}"
}

Delete the highlighted step below:

Select 'Save' to save the changes to the outbound workflow.

Last updated

Was this helpful?