Search code examples
slackazure-logic-apps

How do I create a logic app to copy pictures from slack channel?


I want to automate copying pictures that arrive in a slack channel to go to an Azure Blob.

I found some docs on connecting to Slack and was able to create a When File Is Created task

The next thing I tried was a Copy blob step. However this does not seem right.

logic app picture

[Update]

From George's help I added the HTTP task.

Here is what I see in the code view of the Slack trigger

trigger

or in modified text format

    {
    "$connections": {
        "value": {
            "slack_1": {
                "connectionId": "/subscriptions/subscriptionid/resourceGroups/SlackPicToBlob/providers/Microsoft.Web/connections/slack-1",
                "connectionName": "slack-1",
                "id": "/subscriptions/subscriptionid/providers/Microsoft.Web/locations/australiasoutheast/managedApis/slack"
            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {},
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_file_is_created": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['slack_1']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/trigger/files.list",
                    "queries": {
                        "channel": "CMRUVPHS5"
                    }
                },
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 3
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnection"
            }
        }
    }
}

[Update]

I ran the task and now understand George's instruction to create the link using the menu in Slack.

After creating the link I get the following error.

No output

No output

Looking at a run history, the HTTP Raw inputs are

{
    "uri": "https://files.slack.com/files-pri/TMLT14MDH-FN842SZD3/img_20190911_175347.jpg?pub_secret=3b49994016",
    "method": "GET"
}

and the raw outputs are

{
    "statusCode": 302,
    "headers": {
        "Connection": "keep-alive",
        "X-Backend": "supra-prod-syd-7d7dc657-m6t8j",
        "X-Slack-Meta": "?;proxy_redir",
        "X-Cache": "Miss from cloudfront",
        "X-Amz-Cf-Pop": "MEL50",
        "X-Amz-Cf-Id": "T8AsYDMMGWkO12pi97bvgfJzkxjXu5F_4cMOalyH9NQutxEpi8OseQ==",
        "Date": "Wed, 11 Sep 2019 07:56:13 GMT",
        "Location": "https://jobtalk-workspace.slack.com/?redir=%2Ffiles-pri%2FTMLT14MDH-FN842SZD3%2Fimg_20190911_175347.jpg%3Fpub_secret%3D3b49994016",
        "Via": "1.1 2f3f099f90ecec674faf8faec5c60de1.cloudfront.net (CloudFront)",
        "Content-Length": "152",
        "Content-Type": "text/html; charset=utf-8"
    },
    "body": "<a href=\"https://jobtalk-workspace.slack.com/?redir=%2Ffiles-pri%2FTMLT14MDH-FN842SZD3%2Fimg_20190911_175347.jpg%3Fpub_secret%3D3b49994016\">Found</a>.\n\n"
}

The Create blob tasks shows the error message

ActionConditionFailed. The execution of template action 'Create_blob' is skipped: the 'runAfter' condition for action 'HTTP' is not satisfied. Expected status values 'Succeeded' and actual value 'Failed'.

The Create blob tasks shows the error message

ActionConditionFailed. The execution of template action 'Create_blob' is skipped: the 'runAfter' condition for action 'HTTP' is not satisfied. Expected status values 'Succeeded' and actual value 'Failed'.

[Update]

After I created the external link I was able to get the tasks passing. However the blob did not arrive in storage.

Make blob

I expect I need a step to download the file.

I am following this question for help on that.


Solution

  • You could not create a blob with the slack trigger because the trigger response doesn't contain the file, check the slack trigger you will find it only return some file information and some links. It will be like the below picture.

    enter image description here

    So you have to use a HTTP GET action to get the picture from the link. And this doesn't return the external link(Cause the external link won't be created by default), so you also need create external link after upload the file.

    enter image description here

    And the default external link is combined with url_private and the pub_secret in permalink_public, so the HTTP GET url input will be like this

    @{triggerBody()['url_private']}?pub_secret=@{substring(triggerBody()['permalink_public'],44,10)}

    So my flow is like the below picture, you could have a try, if you still have problem please feel free to let me know.

    enter image description here