-
-
Save carlosmarte/0125ce110eb21acb5d39ade6d07557cd to your computer and use it in GitHub Desktop.
Send a screenshot (by using puppeteer) to Slack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import request from "request"; | |
import puppeteer from "puppeteer"; | |
const API_URL = "https://slack.com/api/files.upload"; | |
const SLACK_API_TOKEN = process.env.SLACK_API_TOKEN as string; | |
const CHANNEL = "general"; | |
(async () => { | |
const url = "http://neverssl.com" | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto(url); | |
const b64string: string = await page.screenshot({ encoding: "base64" }) as string; | |
const buffer: Buffer = Buffer.from(b64string, "base64"); | |
await browser.close(); | |
const data = { | |
url: API_URL, | |
formData: { | |
channels: CHANNEL, | |
file: { | |
value: buffer, | |
options: { | |
filename: "test.png", | |
} | |
}, | |
filename: "test.png", | |
filetype: "image/png", | |
token: SLACK_API_TOKEN, | |
} | |
}; | |
request.post(data, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
console.log(body); | |
} else { | |
console.log(error); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment