-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #308 from coinbase/discord-bot-vercel
feat(CDF-3933): Add Vercel support to discord bot implementation
- Loading branch information
Showing
7 changed files
with
88 additions
and
57 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vercel |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require("dotenv/config"); | ||
const express = require("express"); | ||
const axios = require("axios"); | ||
const bodyParser = require('body-parser') | ||
|
||
const app = express(); | ||
const jsonParser = bodyParser.json() | ||
|
||
app.get("/", jsonParser, (req, res) => { | ||
res.send("Your https server is working!"); | ||
}); | ||
|
||
app.post("/", jsonParser, (req, res) => { | ||
if (!process.env.DISCORD_URL) { | ||
console.log('DISCORD_URL is missing from env'); | ||
res.sendStatus(400); | ||
return; | ||
} | ||
|
||
const data = req.body; | ||
|
||
let messageContent = 'A new ' + data.eventType + ' event was received from the webhook: \n```' | ||
messageContent += JSON.stringify(data, null, 2) | ||
messageContent += '```\n' | ||
messageContent += `Data received at ${new Date().toLocaleString("en-US")}` | ||
|
||
const postData = { | ||
content: messageContent, | ||
} | ||
axios.post(process.env.DISCORD_URL, postData).then(() => { | ||
console.log('Successfully posted message to discord'); | ||
res.sendStatus(200); | ||
}).catch((e) => { | ||
console.error(e) | ||
res.sendStatus(400); | ||
}) | ||
}); | ||
|
||
app.listen(5000, () => { | ||
console.log("Running on port 5000."); | ||
}); | ||
|
||
module.exports = app; |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": 2, | ||
"builds": [ | ||
{ | ||
"src": "app.cjs", | ||
"use": "@now/node" | ||
} | ||
], | ||
"routes": [ | ||
|
||
{ | ||
"src": "/(.*)", | ||
"dest": "app.cjs" | ||
} | ||
] | ||
} |
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