import { PAGE_ACCESS_TOKEN } from './token';

const apiai = require('apiai');
const FBMessenger = require('fb-messenger');

const messenger = new FBMessenger(PAGE_ACCESS_TOKEN);
const app = apiai('73f11a6d692146bdb9708b4e434e7ec9');

export default function engineEnglish(data) {
  const senderID = data.sender.id;
  const request = app.textRequest(data.message.text, {
    sessionId: senderID,
  });
  request.on('response', (response) => {
    messenger.sendTextMessage(senderID, response.fulfillment.speech);
  });
  request.on('error', (error) => {
    console.log(error);
  });
  request.end();
}

@@ -398,49 +398,301 @@
 %7D);%0A
-  request.on('response', (response) =%3E %7B%0A
+%0A  isDefined(obj) %7B%0A    if (typeof obj == 'undefined') %7B%0A        return false;%0A    %7D%0A%0A    if (!obj) %7B%0A        return false;%0A    %7D%0A%0A    return obj != null;%0A%7D%0A%0A  request.on('response', (response) =%3E %7B%0A    if (this.isDefined(response.result) && this.isDefined(response.result.fulfillment)) %7B%0A    
     
@@ -736,16 +736,23 @@
 esponse.
+result.
 fulfillm
@@ -764,16 +764,30 @@
 peech);%0A
+    %7D        %0A
   %7D);%0A  

Update for English Intent Classifier Bug Fix