formspree webhooks to twist

node v10.24.1
version: 1.1.0
endpointsharetweet
const axios = require('axios') const bodyParser = require('body-parser') const express = require("@runkit/runkit/express-endpoint/1.0.0") const prettyaml = require('prettyaml') var app = express(exports) app.use(bodyParser.json()) const FORMSPREE_READONLY_KEY = '3979533d2e40b8ccfb70d03bdab21216e56331bb' app.get("/", (r, w) => { w.end('hello') }) app.post("/hook", async (r, w) => { if (r.get('X-Hook-Secret')) { w.set('X-Hook-Secret', r.get('X-Hook-Secret')) w.end('~') return } console.log(process.env.TWIST_POST_URL) console.log(r.body) let suburl = `https://formspree.cantillon.alhur.es/api/0/forms/${r.body.form}/submissions?since=${r.body.submission._date}` let s_r = await axios.get(suburl, { headers: {'Authorization': 'Bearer ' + FORMSPREE_READONLY_KEY} }) for (let i = 0; i < s_r.data.submissions.length; i++) { let sub = s_r.data.submissions[i] console.log(prettyaml.stringify(sub)) let twist_r = await axios.post(process.env.TWIST_POST_URL, { content: '```\n' + prettyaml.stringify(sub) + '\n```' }, {headers: {'content-type': 'application/json'}}) console.log(twist_r.status) console.log(twist_r.data) } w.end() })
Loading…

no comments

    sign in to comment