-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b045b96
commit 6d8ac32
Showing
2 changed files
with
48 additions
and
2 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
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,46 @@ | ||
// Simple Webhook Server | ||
// | ||
// This server is a simple express serer designed to mimic responses from webhooks | ||
|
||
// Libraries | ||
import express from 'express' | ||
import { json } from 'body-parser' | ||
|
||
// Config | ||
const app = express().use(json()) // creates http server | ||
const token = 'test' // type here your verification token | ||
|
||
// Setup routes | ||
app.get('/', (req, res) => { | ||
// check if verification token is correct | ||
if (req.query.token !== token) { | ||
return res.sendStatus(401) | ||
} | ||
|
||
// return challenge | ||
return res.end(req.query.challenge) | ||
}) | ||
|
||
app.post('/', (req, res) => { | ||
// check if verification token is correct | ||
if (req.query.token !== token) { | ||
return res.sendStatus(401) | ||
} | ||
|
||
// print request body | ||
console.log(req.body) | ||
|
||
// return a text response | ||
const data = { | ||
responses: [ | ||
{ | ||
type: 'text', | ||
elements: ['Hi', 'Hello'] | ||
} | ||
] | ||
} | ||
|
||
res.json(data) | ||
}) | ||
|
||
app.listen(3000, () => console.log('[BotEngine] Webhook is listening')) |