<commit_before>'use strict';

var inherits = require('util').inherits,
	Steppy = require('twostep').Steppy,
	_ = require('underscore'),
	https = require('https'),
	shttps = require('socks5-https-client');


exports.register = function(app) {
	var ParentTransport = app.lib.notifier.BaseNotifierTransport,
		logger = app.lib.logger('telegram notifier'),
		emojiHash = {
			done: '\u2705',
			error: '\ufe0f\u26d4\ufe0f',
			canceled: '\u26a0'
		};

	function Transport() {
		ParentTransport.call(this);
	}

	inherits(Transport, ParentTransport);

	Transport.prototype.init = function(params, callback) {
		this.token = params.token;
		this.proxy = params.proxy;
		callback();
	};

	Transport.prototype._sendMessage = function(params, callback) {
		callback = _.once(callback);

		var requestOptions = {
			host: 'api.telegram.org',
			path: '/bot' + this.token + '/sendMessage',
			headers: {'Content-Type': 'application/json'},
			method: 'POST'
		};

		if (this.proxy) {
			var proxyOptions = {
				socksHost: this.proxy.host,
				socksPort: this.proxy.port,
				socksUsername: this.proxy.username,
				socksPassword: <PASSWORD>
			};

			requestOptions = _(requestOptions).extend(proxyOptions);
		}

		var httpsModule = this.proxy ? shttps : https;

		var req = httpsModule.request(
			requestOptions,
			function(res) {
				logger.log('response status code %d', res.statusCode);

				var chunks = [];
				res.on('data', function(chunk) {
					chunks.push(chunk);
				});
				res.on('end', function() {
					logger.log('response %s', Buffer.concat(chunks).toString());
					callback();
				});
			}
		);
<commit_msg>handle response error event<commit_after>'use strict';

var inherits = require('util').inherits,
	Steppy = require('twostep').Steppy,
	_ = require('underscore'),
	https = require('https'),
	shttps = require('socks5-https-client');


exports.register = function(app) {
	var ParentTransport = app.lib.notifier.BaseNotifierTransport,
		logger = app.lib.logger('telegram notifier'),
		emojiHash = {
			done: '\u2705',
			error: '\ufe0f\u26d4\ufe0f',
			canceled: '\u26a0'
		};

	function Transport() {
		ParentTransport.call(this);
	}

	inherits(Transport, ParentTransport);

	Transport.prototype.init = function(params, callback) {
		this.token = params.token;
		this.proxy = params.proxy;
		callback();
	};

	Transport.prototype._sendMessage = function(params, callback) {
		callback = _.once(callback);

		var requestOptions = {
			host: 'api.telegram.org',
			path: '/bot' + this.token + '/sendMessage',
			headers: {'Content-Type': 'application/json'},
			method: 'POST'
		};

		if (this.proxy) {
			var proxyOptions = {
				socksHost: this.proxy.host,
				socksPort: this.proxy.port,
				socksUsername: this.proxy.username,
				socksPassword: <PASSWORD>
			};

			requestOptions = _(requestOptions).extend(proxyOptions);
		}

		var httpsModule = this.proxy ? shttps : https;

		var req = httpsModule.request(
			requestOptions,
			function(res) {
				logger.log('response status code %d', res.statusCode);

				res.on('error', callback);

				var chunks = [];
				res.on('data', function(chunk) {
					chunks.push(chunk);
				});
				res.on('end', function() {
					logger.log('response %s', Buffer.concat(chunks).toString());
					callback();
				});
			}
		);

{'fraction_non_alphanumeric': 0.15996343692870202, 'fraction_numerical': 0.007921998781230956, 'mean_word_length': 3.7034383954154726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4756307', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1073, 'n_words': 201}