2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-30 13:58:27 +00:00
This commit is contained in:
Yago
2015-09-27 11:18:25 +02:00
parent 48045b98ff
commit 6a679b5644
7 changed files with 46 additions and 14 deletions

11
.jshintrc Normal file
View File

@@ -0,0 +1,11 @@
{
"curly" : true,
"eqeqeq" : true,
"indent" : 2,
"latedef" : true,
"newcap" : true,
"quotmark": "single",
"strict" : true,
"undef" : true,
"node" : true
}

View File

@@ -16,7 +16,8 @@
"scripts": { "scripts": {
"test": "./node_modules/.bin/mocha test/index.js", "test": "./node_modules/.bin/mocha test/index.js",
"test-cov": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", "test-cov": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"gen-doc": "./node_modules/.bin/jsdoc2md --src src/telegram.js -t README.hbs > README.md" "gen-doc": "./node_modules/.bin/jsdoc2md --src src/telegram.js -t README.hbs > README.md",
"jshint": "./node_modules/.bin/jshint src test"
}, },
"author": "Yago Pérez <yagoperezs@gmail.com>", "author": "Yago Pérez <yagoperezs@gmail.com>",
"license": "MIT", "license": "MIT",
@@ -32,6 +33,7 @@
"del": "^2.0.2", "del": "^2.0.2",
"istanbul": "^0.3.17", "istanbul": "^0.3.17",
"jsdoc-to-markdown": "^1.2.0", "jsdoc-to-markdown": "^1.2.0",
"jshint": "^2.8.0",
"mocha": "^2.2.5", "mocha": "^2.2.5",
"mocha-lcov-reporter": "0.0.2", "mocha-lcov-reporter": "0.0.2",
"should": "^7.0.1" "should": "^7.0.1"

View File

@@ -1,9 +1,11 @@
'use strict';
var TelegramBotWebHook = require('./telegramWebHook'); var TelegramBotWebHook = require('./telegramWebHook');
var TelegramBotPolling = require('./telegramPolling'); var TelegramBotPolling = require('./telegramPolling');
var debug = require('debug')('node-telegram-bot-api'); var debug = require('debug')('node-telegram-bot-api');
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var Promise = require("bluebird"); var Promise = require('bluebird');
var request = require("request"); var request = require('request');
var stream = require('stream'); var stream = require('stream');
var util = require('util'); var util = require('util');
var mime = require('mime'); var mime = require('mime');
@@ -56,7 +58,7 @@ util.inherits(TelegramBot, EventEmitter);
TelegramBot.prototype.initPolling = function() { TelegramBot.prototype.initPolling = function() {
if (this._polling) { if (this._polling) {
this._polling.abort = true; this._polling.abort = true;
this._polling.lastRequest.cancel("Polling restart"); this._polling.lastRequest.cancel('Polling restart');
} }
this._polling = new TelegramBotPolling(this.token, this.options.polling, this.processUpdate); this._polling = new TelegramBotPolling(this.token, this.options.polling, this.processUpdate);
}; };
@@ -111,7 +113,7 @@ TelegramBot.prototype._buildURL = function(path) {
host: 'api.telegram.org', host: 'api.telegram.org',
pathname: '/bot' + this.token + '/' + path pathname: '/bot' + this.token + '/' + path
}); });
} };
/** /**
* Returns basic information about the bot in form of a `User` object. * Returns basic information about the bot in form of a `User` object.
@@ -462,6 +464,6 @@ TelegramBot.prototype.downloadFile = function(fileId, downloadDir) {
}); });
}); });
} };
module.exports = TelegramBot; module.exports = TelegramBot;

View File

@@ -1,5 +1,7 @@
'use strict';
var debug = require('debug')('node-telegram-bot-api'); var debug = require('debug')('node-telegram-bot-api');
var Promise = require("bluebird"); var Promise = require('bluebird');
var request = require('request'); var request = require('request');
var URL = require('url'); var URL = require('url');
@@ -7,7 +9,7 @@ var requestPromise = Promise.promisify(request);
var TelegramBotPolling = function (token, options, callback) { var TelegramBotPolling = function (token, options, callback) {
options = options || {}; options = options || {};
if (typeof options === "function") { if (typeof options === 'function') {
callback = options; callback = options;
options = {}; options = {};
} }

View File

@@ -1,7 +1,8 @@
'use strict';
var debug = require('debug')('node-telegram-bot-api'); var debug = require('debug')('node-telegram-bot-api');
var https = require('https'); var https = require('https');
var http = require('http'); var http = require('http');
var util = require('util');
var fs = require('fs'); var fs = require('fs');
var TelegramBotWebHook = function (token, options, callback) { var TelegramBotWebHook = function (token, options, callback) {
@@ -26,7 +27,7 @@ var TelegramBotWebHook = function (token, options, callback) {
} }
this._webServer.listen(options.port, options.host, function () { this._webServer.listen(options.port, options.host, function () {
debug("WebHook listening on port %s", options.port); debug('WebHook listening on port %s', options.port);
}); });
}; };

12
test/.jshintrc Normal file
View File

@@ -0,0 +1,12 @@
{
"mocha" : true,
"curly" : true,
"eqeqeq" : true,
"indent" : 2,
"latedef" : true,
"newcap" : true,
"quotmark": "single",
"strict" : true,
"undef" : true,
"node" : true
}

View File

@@ -1,10 +1,12 @@
'use strict';
var TelegramPolling = require('../src/telegramPolling'); var TelegramPolling = require('../src/telegramPolling');
var Telegram = require('../index'); var Telegram = require('../index');
var request = require('request'); var request = require('request');
var should = require('should'); var should = require('should');
var fs = require('fs'); var fs = require('fs');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var TOKEN = process.env.TEST_TELEGRAM_TOKEN; var TOKEN = process.env.TEST_TELEGRAM_TOKEN;
if (!TOKEN) { if (!TOKEN) {
throw new Error('Bot token not provided'); throw new Error('Bot token not provided');
@@ -69,7 +71,7 @@ describe('Telegram', function () {
method: 'POST', method: 'POST',
json: true, json: true,
headers: { headers: {
"content-type": "application/json", 'content-type': 'application/json',
}, },
body: {update_id: 0, message: {text: 'test'}} body: {update_id: 0, message: {text: 'test'}}
}); });
@@ -94,7 +96,7 @@ describe('Telegram', function () {
method: 'POST', method: 'POST',
json: true, json: true,
headers: { headers: {
"content-type": "application/json", 'content-type': 'application/json',
}, },
rejectUnhauthorized: false, rejectUnhauthorized: false,
body: {update_id: 0, message: {text: 'test'}} body: {update_id: 0, message: {text: 'test'}}
@@ -190,7 +192,7 @@ describe('Telegram', function () {
describe('#sendChatAction', function () { describe('#sendChatAction', function () {
it('should send a chat action', function (done) { it('should send a chat action', function (done) {
var bot = new Telegram(TOKEN); var bot = new Telegram(TOKEN);
var action = "typing"; var action = 'typing';
bot.sendChatAction(USERID, action).then(function (resp) { bot.sendChatAction(USERID, action).then(function (resp) {
resp.should.be.exactly(true); resp.should.be.exactly(true);
done(); done();