'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;



'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;
	
	luis.analyseMessage('When does the next train leaves to Garching?').then(data => {
    	bot.sendMessage(chatId, 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;



fix luis promise resolving