Skip to content

Instantly share code, notes, and snippets.

@Dougley
Last active November 18, 2018 22:16
Show Gist options
  • Save Dougley/3b8dc535dae3e700729f3c0d238fb247 to your computer and use it in GitHub Desktop.
Save Dougley/3b8dc535dae3e700729f3c0d238fb247 to your computer and use it in GitHub Desktop.
Uservoice webhooks
const Express = require('express')
const BP = require('body-parser')
const app = Express()
const Discordie = require('discordie')
const bot = new Discordie()
const morgan = require('morgan')
const Entities = require('html-entities').AllHtmlEntities;
const entities = new Entities();
app.use(morgan('dev'))
const webhookID = 'id'
const webhookKEY = 'key'
const port = 3000
app.post('/', BP.urlencoded(), (req, res) => {
const data = JSON.parse(req.body.data)
let content = entities.decode(data.suggestion.text)
if (content.length < 1) content = '*No content*'
if (content.length > 1800) content = '*Content too long*'
bot.Webhooks.execute(webhookID, webhookKEY, {
content: 'New feedback submitted!',
embeds: [{
color: 0x3498db,
author: {
name: entities.decode(data.suggestion.creator.name),
icon_url: data.suggestion.creator.avatar_url,
url: data.suggestion.creator.url
},
title: entities.decode(data.suggestion.title),
description: content,
url: data.suggestion.url,
footer: {
text: `${entities.decode(data.suggestion.category.name)}, ID: ${data.suggestion.id}`
}
}]
})
res.status(204).end()
})
app.listen(port, function() {
console.log('API listening on port ' + port)
})
{
"name": "uv-webhook",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"discordie": "*",
"express": "*",
"body-parser": "*",
"morgan": "*",
"html-entities": "*"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Remco Jongschaap <[email protected]>",
"license": "UNLICENCED"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment