Skip to content

Instantly share code, notes, and snippets.

@maxwellb
Created November 10, 2017 05:13
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 maxwellb/4ad06a8d0243760f5f807bc2c6ee333a to your computer and use it in GitHub Desktop.
Save maxwellb/4ad06a8d0243760f5f807bc2c6ee333a to your computer and use it in GitHub Desktop.
Webtask + microfeedback + keybase-encrypt + trello
"use latest";
/*
Copyright (c) 2017 Maxwell Bloch, All rights reserved.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import express from "express";
import { fromExpress } from "webtask-tools";
import bodyParser from "body-parser";
const popsicle = require("popsicle");
const querystring = require("querystring");
const encrypt = require("keybase-encrypt");
var app = express();
app.use(bodyParser.json());
function auth(key, token) {
return function auth(self, next) {
let qs = {}
qs.key = key;
qs.token = token;
self.url += "?" + querystring.stringify(qs);
return next();
}
}
app.post('/', function (req, res) {
let ctx = req.webtaskContext;
popsicle.get(ctx.secrets.PGP_KEY_URL)
.then(resp => encrypt(resp.body, req.body.body))
.then(message =>
popsicle.post({
url: "https://api.trello.com/1/cards",
body: {
name: "Feedback received",
desc: message,
idList: ctx.secrets.TRELLO_LIST,
pos: "bottom"
}
})
.use(auth(ctx.secrets.TRELLO_KEY, ctx.secrets.TRELLO_TOKEN))
)
.then(resp => {
console.log(`${resp.status}: ${resp.body}`);
res.status(201).send({});
})
.catch(err => {
console.error(err);
res.status(500).send();
});
});
module.exports = fromExpress(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment