'use strict';

const TelegramSDK   = require('./telegramSDK');
const LuisSDK = require('./luisSDK');

let telegramToken = process.env.TELEGRAM_BOT_TOKEN || '';
let luisToken = process.env.LUIS_TOKEN || '';
let luisKey = process.env.LUIS_SUBSCRIPTION_KEY || '';

let bot = new  TelegramSDK(telegramToken);
let luis = new LuisSDK(luisToken, luisKey);

bot.on('message', (message) => {

    let chatId = message.chat.id;
    let text = message.text;
    let user = message.from.username || message.from.first_name;
	
	let luisResp = luis.analyseMessage('When does the next train leaves to Garching?').then(data => {
    	return data;
  	});
	
	bot.sendMessage(chatId, luisResp);	
	
    let msg = `${user} send the message: ${text}` ;
	
    bot.sendMessage(chatId,msg);

});

bot.on('error', (message) => {

    let errorMsg = 'Error in request:' + message;
    let chatTestId = '-178955930';

    bot.sendMessage(chatTestId, errorMsg);

});

//luis.on('message', (message) => )


module.exports = bot;



@@ -339,24 +339,25 @@
  luisKey);%0A%0A
+%0A
 bot.on('mess
@@ -513,23 +513,8 @@
 %0A%09%0A%09
-let luisResp = 
 luis
@@ -601,19 +601,37 @@
    %09
-return
+bot.sendMessage(chatId,
  data
+)
 ;%0A  

fix luis promise resolving