hapi-ham

6.2.1 • Public • Published

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)
  })
})

Readme

Keywords

none

Package Sidebar

Install

npm i hapi-ham

Weekly Downloads

4

Version

6.2.1

License

ISC

Unpacked Size

35.7 kB

Total Files

20

Last publish

Collaborators

  • jairyalere
  • nathali
  • alex_yalo
  • tarikferes
  • manuelcordon-yalo
  • waltermoorlag
  • reinholdyalo
  • cesar-aguirre-yalo
  • byronramos
  • adanmuguiro
  • uriel-yalo
  • ochoa_yalo
  • dapryalo
  • bonniemilianb
  • guilhermesborz
  • gago_ar
  • catyalere
  • jfelix-yalo
  • gabriel_yalo
  • janetyalo
  • julio.gonzalez
  • branmendozay
  • zkropotkine
  • fernandorincon
  • gustavoyalo
  • moisesflores22
  • josepablohm
  • yaogomezyalo
  • rommelyalopartner
  • yalo-engineering
  • yoelfme
  • josemanu