Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cowsay test bot for MatterMost outgoing webhook
// https://docs.mattermost.com/developer/webhooks-outgoing.html
var express = require('express');
var cowsay = require('cowsay');
var bodyparser = require('body-parser');
var app = express();
app.use(bodyparser.urlencoded({ extended: true }));
app.get('/', function (req, res) {
res.end('<pre>'+ cowsay.say({text: 'Moo'}) + '</pre>');
});
app.post('/cowbot', function (req, res) {
if (req.body.token === process.env.MATTERMOST_TOKEN) {
var text = req.body.text.replace(new RegExp('^' + req.body.trigger_word + '\ '), '');
return res.json({
username: 'cowbot9000',
text: '```\n' + cowsay.say({text: text || 'wat?'}) + '\n```'
});
}
res.json(['who are you?']);
});
require('greenlock-express').create({
server: 'staging', //'https://acme-v01.api.letsencrypt.org/directory'
email: 'you@urdomain.tld',
agreeTos: true,
approveDomains: [ 'urdomain.tld' ],
app: app
}).listen(80, 443);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.