Skip to content

Instantly share code, notes, and snippets.

@humannus
Last active July 3, 2022 22:40
Show Gist options
  • Save humannus/a7a9d6ff05446f0547aedef3c1ab5560 to your computer and use it in GitHub Desktop.
Save humannus/a7a9d6ff05446f0547aedef3c1ab5560 to your computer and use it in GitHub Desktop.
Setting attributes only (without returning any bot response)
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const app = express().use(bodyParser.json()); // creates http server
const token = 'TOKEN'; // type here your verification token
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 responses and actions
const data = {
// return attributes
attributes: {
signedUpForNewsletter: 'yes'
}
};
res.json(data);
});
app.listen(3000, () => console.log('[ChatBot] Webhook is listening'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment