'use strict';

const FBProcess = require('./fb-process');
const util = require('util');

function FBMenu(options) {
  if (!(this instanceof FBMenu)) {
    return new FBMenu(options);
  }

  options = options || {};
  options.name = FBProcess.CONST.NAME.MENU;
  FBProcess.call(this, options);
}

util.inherits(FBMenu, FBProcess);

FBMenu.prototype.handleMessageState = function(options) {
  options = options || {};
  console.log('Menu!');
  console.log('user_id: ' + options.user_id);
  console.log('state: ' + options.state);
  console.log('type: ' + options.type);

  switch (options.state) {
    case 0:
      this.sendMenu(options);
      options.state = 1;
      this.transitionState(options);
      break;
    case 1:
      switch (options.type) {
        case 'message':
          this.bot.botly.sendText({
            id: options.user_id,
            text: 'menu message : ' + options.data.text
          });
          break;
        case 'postback':
          this.bot.botly.sendText({
            id: options.user_id,
            text: 'menu postback'
          });
          break;
        default:
          this.unknownCommand(options);
      }
      break;
    default:
      this.unknownCommand(options);
  }
};

FBMenu.prototype.sendMenu = function(options) {
  options = options || {};

  this.bot.botly.sendText({
    id: options.user_id,
    text: 'Bienvenue au menu!'
  });
};

FBMenu.prototype.unknownCommand = function(options) {
  options = options || {};

  options.proc = FBProcess.CONST.NAME.GREETING;
  this.transitionProcess(options);
};

module.exports = FBMenu;
@@ -771,16 +771,141 @@
 ssage':%0A
+          if (options.data.text.toUpperCase() == 'ANNULER') %7B%0A            this.unknownCommand(options);%0A          %7D else %7B%0A  
         
@@ -936,32 +936,34 @@
 t(%7B%0A            
+ 
+ 
 id: options.user
@@ -959,32 +959,34 @@
 ptions.user_id,%0A
+  
             text
@@ -1027,36 +1027,50 @@
 .text%0A          
+  
 %7D);%0A
+          %7D%0A
           break;

Test stopping process