I need to decrypt incoming webhook from a form website using express.js. I can get it to work locally. Is this possible by using Zapier? See the following snippet of code.
const express = require('express')
const app = express()
// Instantiating formsg-sdk without parameters default to using the package's production public signing key.
const formsg = require('@opengovsg/formsg-sdk')()
const POST_URI = 'zapier_sample'
const formSecretKey = process.env.FORM_SECRET_KEY
app.post(
'/submissions',
// Endpoint authentication by verifying signatures
function (req, res, next) {
try {
formsg.webhooks.authenticate(req.get('X-Formsg-Signature'), POST_URI)
// Continue processing the POST body
return next()
} catch (e) {
return next()
// return res.status(401).send({ message: 'Unauthorized' })
}
},
// Parse JSON from raw request body
express.json(),
// Decrypt the submission
async function (req, res, next) {
const submission = HAS_ATTACHMENTS
? await formsg.crypto.decryptWithAttachments(formSecretKey, req.body.data)
: formsg.crypto.decrypt(formSecretKey, req.body.data)
if (submission) {
console.log('This is submission' + JSON.stringify(submission))
return res.status(200).send({ message: 'See console for submission' })
// Continue processing the submission
} else {
return res.status(200).send({ message: 'Could not decrypt the submission' })
}
}
)