Created
July 13, 2017 11:03
-
-
Save travispaul/3aa3a7b343f0f31aaad88c56dac1fb38 to your computer and use it in GitHub Desktop.
Cowsay test bot for MatterMost outgoing webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: '[email protected]', | |
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