import dotenv from 'dotenv';
import http from 'http';
import express from 'express';
import bodyParser from 'body-parser';

import MessengerWrapper from '../messenger-wrapper.js';

dotenv.config();

let app = express();

let wrapper = new MessengerWrapper({
  verifyToken: process.env.VERIFY_TOKEN,
  pageAccessToken: process.env.PAGE_ACCESS_TOKEN
});

wrapper.on('message', (event) => {
  wrapper.sendData({ text: 'hello user' }, event);
});

wrapper.on('delivery', (event) => {
  console.log('delivery has come');
});

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.get('/webhook', (req, res) => {
  wrapper.verify(req, res);
});

app.get('/subscribe', (req, res) => {
  wrapper.subscribe().then((response) => {
    res.send(response.body);
  });
});

app.post('/webhook', (req, res) => {
  res.sendStatus(200);
  wrapper.handle(req);
});

http.createServer(app).listen(3000);

@@ -210,24 +210,105 @@
 express();%0A%0A
+app.use(bodyParser.json());%0Aapp.use(bodyParser.urlencoded(%7B extended: true %7D));%0A%0A
 let wrapper 
@@ -582,16 +582,13 @@
 ery 
-has come
+event
 ');%0A
@@ -596,85 +596,78 @@
 );%0A%0A
+wr
 app
-.use(bodyPars
 er.
-js
 on(
-));%0Aapp.use(bodyParser.urlencoded(%7B extended: true %7D)
+'postback', (event) =%3E %7B%0A  console.log('postback event');%0A%7D
 );%0A%0A

add on 'postback' listener