Skip to content

Instantly share code, notes, and snippets.

@dustinknopoff
Created August 2, 2022 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinknopoff/4c435a65c4ab50a79c6cd0475bac168d to your computer and use it in GitHub Desktop.
Save dustinknopoff/4c435a65c4ab50a79c6cd0475bac168d to your computer and use it in GitHub Desktop.
const express = require('express');
const bodyParser = require('body-parser');
const ngrok = require('ngrok');
const axios = require('axios');
const crypto = require('crypto');
const PORT = 3000;
const app = express();
const passcode = crypto.randomBytes(48).toString('hex');
app.use(bodyParser.json());
app.post('/', async (request, response) => {
if (request.body.passcode === passcode) {
const { file_name, timestamp, file_key } = request.body
console.log(`${file_name} was updated at ${timestamp}`);
response.sendStatus(200);
} else {
response.sendStatus(403);
}
})
app.listen(PORT, () => console.log(`🚀 Server running on port ${PORT}`));
ngrok.connect(PORT).then(async (endpoint) => {
const response = await axios({
url: "https://api.figma.com/v2/webhooks",
method: "POST",
headers: {
'X-Figma-Token': process.env.FIGMA_TOKEN,
},
data: {
event_type: 'FILE_VERSION_UPDATE',
team_id: 'TODO',
passcode,
endpoint
}
})
console.log(`🎣 Webhook ${response.data.id} successfully created`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment