Skip to content

Instantly share code, notes, and snippets.

@co6x0
Last active April 8, 2023 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save co6x0/a591ac47209d6c1d9826bb335e10bb02 to your computer and use it in GitHub Desktop.
Save co6x0/a591ac47209d6c1d9826bb335e10bb02 to your computer and use it in GitHub Desktop.
Slack notification by "FILE_VERSION_UPDATE" of Figma webhook event at AWS Lambda.
const https = require('https');
const endpointHost = 'hooks.slack.com';
const endpointPath = 'Your Slack webhook URL Path';
exports.handler = async (event) => {
const body = JSON.parse(event.body);
const postData = JSON.stringify({
"text": "Update Version History in Figma",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":figma: Update Version History in Figma"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*<https://www.figma.com/file/${body.file_key}/${body.file_name}|${body.label}>*`
}
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": `:page_facing_up: File: ${body.file_name} | Updated by ${body.triggered_by.handle}`,
"emoji": true
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `> ${body.description || 'No description'}`
}
}
]
});
const options = {
hostname: endpointHost,
port: 443,
path: endpointPath,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
const promise = new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (chunk) => {
console.log(`Body: ${chunk}`);
});
res.on('end', () => {
console.log('FINISH');
resolve();
});
});
req.on('error', (e) => {
reject(e);
});
req.write(postData);
req.end();
});
return promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment