auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const axios = require('axios')
const config = {
method: 'GET',
url: 'https://res.cloudinary.com/da5lyi17v/image/upload/v1570819140/sample.jpg',
responseType: 'arraybuffer',
}
const resp = await axios(config)
this.screenshot = resp.data.toString('base64');
async
(params, auths) => {
}
//See the API docs here: https://api.slack.com/methods/files.upload
//See a workflow example of this action: https://pipedream.com/@sergio/slack-file-upload-p_OKC2vx/edit
if (params.content) {
const data = {
channels: params.channel,
content: params.content,
filename: params.filename,
filetype: params.filetype,
initial_comment: params.initial_comment,
thread_ts: params.thread_ts,
title: params.title
}
const config = {
url: `https://slack.com/api/files.upload`,
headers: {
Authorization: `Bearer ${auths.slack.oauth_access_token}`,
"Content-Type": "application/x-www-form-urlencoded",
},
params: data,
}
return await require("@pipedreamhq/platform").axios(this, config)
}
else {
const streamifier = require("streamifier")
const { WebClient } = require('@slack/web-api');
const web = new WebClient(auths.slack.oauth_access_token)
const buffer = Buffer.from(params.file_contents, "base64");
const file = streamifier.createReadStream(buffer);
await web.files.upload(
{
channels: params.channel,
filename: params.filename,
file,
filetype: params.filetype,
initial_comment: params.initial_comment,
thread_ts: params.thread_ts,
title: params.title
}
);
}