var logger = require('log4js').getLogger('telegram');

var nconf = require('nconf');

if (process.env.NODE_ENV === 'unit-test') {
	nconf.file('bots', __dirname + '/../../test/config/bots.json')
		.file('receviers', __dirname + '/../../test/config/receivers.json')
		.file('senders', __dirname + '/../../test/config/senders.json');
} else {
	nconf.file('bots', __dirname + '/../config/bots.json')
		.file('receviers', __dirname + '/../config/receivers.json')
		.file('senders', __dirname + '/../config/senders.json');
}

var request = require('request');

function sendMessage(receiver, message, botname, callback) {

	try {
		var chat_id = nconf.get(receiver).chat_id;
		var token = nconf.get(botname).token;
	} catch (ex) {

		err = {
			description: 'chat_id or token not found'
		};

		logger.error(err);

		callback(err);

        return;
	}

	request.post({
			url: 'https://api.telegram.org/bot' + token + '/sendMessage',
			form: {
				chat_id: chat_id,
				text: message
			}
		},
		function(err, res, body) {

			body = JSON.parse(body);

			if (err) {
				logger.error(err);
				callback(err, null);
				return;
			}

			if (body['error_code']) {

				logger.error(body['description']);

				err = {
					error: body['error_code'],
					description: body['description']
				};

				callback(err, null);

				return;
			}

			logger.info('Message sent!');

			var successMessage = {
				receiver: receiver,
				message: message,
				sendTime: new Date()
			};

			callback(null, successMessage);

		});
}

module.exports = {
	'sendMessage': sendMessage
};

var logger = require('log4js').getLogger('telegram');

var nconf = require('nconf');

if (process.env.NODE_ENV === 'unit-test') {
	nconf.file('bots', __dirname + '/../../test/config/bots.json')
		.file('receviers', __dirname + '/../../test/config/receivers.json')
		.file('senders', __dirname + '/../../test/config/senders.json');
} else {
	nconf.file('bots', __dirname + '/../config/bots.json')
		.file('receviers', __dirname + '/../config/receivers.json')
		.file('senders', __dirname + '/../config/senders.json');
}

var request = require('request');

function sendMessage(receiver, message, botname, callback) {

	try {
		var chat_id = nconf.get(receiver).chat_id;
		var token = nconf.get(botname).token;
	} catch (ex) {

		err = {
			error:'receiver or bot not found!'
		};

		logger.error(err);

		callback(err,null);

        return;
	}

	request.post({
			url: 'https://api.telegram.org/bot' + token + '/sendMessage',
			form: {
				chat_id: chat_id,
				text: message
			}
		},
		function(err, res, body) {

			body = JSON.parse(body);

			if (err) {
				logger.error(err);
				callback(err, null);
				return;
			}

			if (body['error_code']) {

				logger.error(body['description']);

				err = {
					error: body['error_code'],
					description: body['description']
				};

				callback(err, null);

				return;
			}

			logger.info('Message sent!');

			var successMessage = {
				receiver: receiver,
				message: message,
				sendTime: new Date()
			};

			callback(null, successMessage);

		});
}

module.exports = {
	'sendMessage': sendMessage
};

Fix the error message of chat_id or token not found