hapi-ham
v6.2.1
Published
hapi answering machine
Downloads
83
Maintainers
Keywords
Readme
hapi-ham
hapi answering machine
Usage
'use strict';
const Hapi = require('hapi');
// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
port: 8000
});
// Register hapi-ham plugin
server.register({
register: require('hapi-ham'),
options: {
provider: 'facebook-messenger',
access_token: '<facebook_page_token>'
//debug: true
}
}, (err) => {
if (err) {
throw err
}
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
return reply.validateWebhook()
}
})
// Add the route
server.route({
method: 'POST',
path: '/',
handler: function (request, reply) {
const template = {
text: `Received message: ${request.event.message.text}`
}
return reply.message(template)
}
})
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri)
})
})