Skip to content

Instantly share code, notes, and snippets.

@mike623
Created August 22, 2018 04:05
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 mike623/3a9e6f309494b316d2f56cfe83b72808 to your computer and use it in GitHub Desktop.
Save mike623/3a9e6f309494b316d2f56cfe83b72808 to your computer and use it in GitHub Desktop.
get message from mandrill inbound
var talon = require("talon");
var extractSignature = talon.signature.bruteforce.extractSignature;
var planer = require('planer');
const cheerio = require('cheerio')
// https://github.com/PrettyHotProgrammer/mandrill-inbound-parser/blob/master/mandrill-inbound-parser.js
// mandrill_events%3D%5B%7B%22event%22%3A%22inbound
const parse = function(inboundMsg) {
if (inboundMsg.includes('mandrill_events=%5B%7B%22event%22%3A%22inbound')) {
return decodeURIComponent(inboundMsg)
.replace(/\+/g, ' ')
.replace('mandrill_events=', '');
}
return 'Not a valid inbound message from Mandrill';
}
var fs = require('fs');
module.exports = async (req, res) => {
const body = await text(req)
const obt = JSON.parse(parse(body))
// const html = planer.extractFrom(obt[0].msg.html, 'text/html')
const text2 = planer.extractFrom(obt[0].msg.text, 'text/plain')
// const text2 = cheerio.load(html).text()
const result = extractSignature(text2)
console.log('result', result)
fs.writeFile('myjsonfile.json', JSON.stringify(obt), 'utf8', () => {
res.end('Welcome to Micro')
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment