Question

How to include image/attachment using push to zapier in Slack?

  • 26 April 2021
  • 6 replies
  • 2078 views

Hi there, 

How would we be able to include file/images in Google Sheet when a message is pushed to Zapier from Slack?

The idea is to push these messages to Zapier and it will be added as a row in Google Sheet. 

Thanks heaps


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

6 replies

Userlevel 7
Badge +12

@eves 

By default, slack does not include an image when pushed to Zapier. However, since you are hoping to trigger only pushed messages there is a quick manual step you can take before pushing the message so that the image in the message is publicly accessible.  

Before pushing the message/image, hover on the the dots on the image and select “View external link”, copy the link, then when you go to push the message/image to zapier you can paste in the public view link to the image in the additional text box.  You can then map this url to a cell in google sheets ( you will be mapping the ‘text_added’ field from the trigger step)



*****ADVANCED****
However, technically, this link is just to an html page that contains the image. If you wanted to map the image itself into the google sheet it gets more advanced and will involve a code step. 

Badge

I am trying to do the same thing but instead of adding an image from Slack to Google Sheets I am wanting to add it to Asana. Can you elaborate on the coding needed to map the image itself rather than the html page?

Userlevel 7
Badge +11

Hi @Erica!

It seems like you can right-click on the “Open in browser” link then on “Copy Link” to get a direct, public, link to the image:

 

Userlevel 7
Badge +12

@nicksimard It doesn’t look like that link is publicly accessible and thus able to be used in further steps. 

 

For example, copying the link to the browser screen in my slack gives me this url: https://files.slack.com/files-pri/T01KBBEGM9D-F020161BHBL/screen_shot_2021-02-03_at_5.51.55_pm.png 

which when sent in a gmail step fails to populate as an attachment (makes sense, considering this link is private and requires you log in to view)

 


 

However, the public version of that file location would be https://files.slack.com/files-pri/T01KBBEGM9D-F020161BHBL/screen_shot_2021-02-03_at_5.51.55_pm.png?pub_secret=86e0137c9e *note the secret that slack appends to the url when viewing the image link from the external file url. 

 

A sort of webscaper would need to be hacked together using a code step to make a request to the external file link and then parse out the image location. Something like the below. 

const request = await fetch(inputData.url, {
method: "POST",
});
let html = await request.text();

var image_file_location_start = html.substring(html.indexOf('content="https://'));
var image_public_url = image_file_location_start.substring(image_file_location_start.indexOf('"')+1,image_file_location_start.indexOf('">'));

return {image_public_url}

 

The code will return the public url which you then can try mapping in the Attach File Asana action.

*Note the above is extraordinarily advanced and there may likely be better (less hacky) ways to accomplish this using the slack API. The above also only works if the only thing you put in the additional text box is the external link you’ve copied. It does not account for finding the project or the task to attach the file to

Badge

This is so wonderful thank you so much for the in depth explanation. I had been trying to use the link @nicksimard recommended but @GetUWired is correct that it does not populate an attachment like I am wanting. I am going to give this coding a shot today and see if I can get it to produce the results I am wanting. Thank you both for taking the time to help me with this !

Userlevel 7
Badge +12

@Erica 

No problem! Let me know if you have any questions, the code will be difficult to test as you won’t be able to test it in “test” mode since you won’t have a url from the trigger step. you’ll need to set everything up, then turn the zap on to test. 

To get around this, you can do 1 of two things. 

First Way:

Copy an external link from slack, paste it in manually in the code input, run the code, map the value in the asana step. Then go back to the code block and replace the url input with the dynamic info from the trigger. 

Alternate Approach:

Skip running the code step & try to map the “pill” in the next step using {{123157881__image_public_url}} . You will need to replace 123157881 with the node id of the code step in your zap. If you click on the code step, you will see that value populated. More on this type of stuff can be found here: