describe('#getMe', function getMeSuite() { before(function before() { utils.handleRatelimit(bot, 'getMe', this); }); it('should return an User object', function test() { return bot.getMe().then(resp => { assert.ok(is.object(resp)); assert.ok(is.number(resp.id)); assert.ok(is.string(resp.first_name)); }); }); });
describe('#getFileLink', function getFileLinkSuite() { this.timeout(timeout); before(function before() { utils.handleRatelimit(bot, 'getFileLink', this); }); it('should get a file link', function test() { return bot.getFileLink(FILE_ID) .then(fileURI => { assert.ok(is.string(fileURI)); assert.ok(utils.isTelegramFileURI(fileURI)); }); }); });
describe('#downloadFile', function downloadFileSuite() { const downloadPath = os.tmpdir(); this.timeout(timeout); before(function before() { utils.handleRatelimit(bot, 'downloadFile', this); }); it('should download a file', function test() { return bot.downloadFile(FILE_ID, downloadPath) .then(filePath => { assert.ok(is.string(filePath)); assert.equal(path.dirname(filePath), downloadPath); assert.ok(fs.existsSync(filePath)); fs.unlinkSync(filePath); // Delete file after test }); }); });
describe('#sendVenue', function sendVenueSuite() { before(function before() { utils.handleRatelimit(bot, 'sendVenue', this); }); it('should send a venue', function test() { const title = 'The Village Shopping Centre'; const address = '430 Topsail Rd,St. John\'s, NL A1E 4N1, Canada'; return bot.sendVenue(USERID, lat, long, title, address).then(resp => { assert.ok(is.object(resp)); assert.ok(is.object(resp.venue)); assert.ok(is.object(resp.venue.location)); assert.ok(is.number(resp.venue.location.latitude)); assert.ok(is.number(resp.venue.location.longitude)); assert.ok(is.string(resp.venue.title)); assert.ok(is.string(resp.venue.address)); }); }); });
describe('#getStickerSet', function getStickerSetSuite() { before(function before() { utils.handleRatelimit(bot, 'getStickerSet', this); }); it('should get the sticker set given the name of the set', function test() { return bot.getStickerSet(STICKER_SET_NAME).then(resp => { assert.ok(is.object(resp)); assert.equal(resp.name.toLowerCase(), STICKER_SET_NAME); assert.ok(is.string(resp.title)); assert.ok(is.boolean(resp.contains_masks)); assert.ok(is.array(resp.stickers)); }); }); });
describe('#getFile', function getFileSuite() { this.timeout(timeout); before(function before() { utils.handleRatelimit(bot, 'getFile', this); }); it('should get a file', function test() { return bot.getFile(FILE_ID) .then(resp => { assert.ok(is.object(resp)); assert.ok(is.string(resp.file_path)); }); }); });
describe('#sendAnimation', function sendAnimationSuite() { before(function before() { utils.handleRatelimit(bot, 'sendAnimation', this); }); it('should send a gif as an animation', function test() { return bot.sendAnimation(USERID, `${__dirname}/data/photo.gif`).then(resp => { assert.ok(is.object(resp)); assert.ok(is.object(resp.document)); describe('#editMessageMedia', function editMessageMediaSuite() { before(function before() { utils.handleRatelimit(bot, 'editMessageMedia', this); }); it('should edit a media message', function nextTest() { return bot.editMessageMedia({ type: 'animation', media: resp.document.file_id, caption: 'edited' }, { chat_id: resp.chat.id, message_id: resp.message_id }).then(editedResp => { assert.ok(is.object(editedResp)); assert.ok(is.string(editedResp.caption)); }); }); }); }); }); });
// NOTE: We are skipping TelegramBot#sendContact() as the // corresponding rate-limits enforced by the Telegram servers // are too strict! During our initial tests, we were required // to retry after ~72000 secs (1200 mins / 20 hrs). // We surely can NOT wait for that much time during testing // (or in most practical cases for that matter!) describe.skip('#sendContact', function sendContactSuite() { before(function before() { utils.handleRatelimit(bot, 'sendContact', this); }); it('should send a contact', function test() { const phoneNumber = '+1(000)000-000'; const firstName = 'John Doe'; return bot.sendContact(USERID, phoneNumber, firstName).then(resp => { assert.ok(is.object(resp)); assert.ok(is.object(resp.contact)); assert.ok(is.string(resp.contact.phone_number)); assert.ok(is.string(resp.contact.first_name)); }); }); });
describe('#uploadStickerFile', function sendPhotoSuite() { before(function before() { utils.handleRatelimit(bot, 'uploadStickerFile', this); }); it('should upload a sticker from file', function test() { const sticker = `${__dirname}/data/sticker.png`; return bot.uploadStickerFile(USERID, sticker).then(resp => { assert.ok(is.object(resp)); assert.ok(is.string(resp.file_id)); }); }); // Other tests (eg. Buffer, URL) are skipped, because they rely on the same features as sendPhoto. });
describe('#getChatMember', function getChatMemberSuite() { before(function before() { utils.handleRatelimit(bot, 'getChatMember', this); }); it('should return a ChatMember', function test() { return bot.getChatMember(GROUPID, USERID).then(resp => { assert.ok(is.object(resp)); assert.ok(is.object(resp.user)); assert.ok(is.string(resp.status)); }); }); });
upperFirst(str) { if (is.string(str)) { return str.replace(/^[a-z]/, function(w) { return w.toUpperCase(); }); } return str; }
eventTypes() { var arg, i = 0, ret = []; for (; i < arguments.length; i++) { arg = arguments[i]; if (is.array(arg)) { Array.prototype.push.apply(ret, this.eventTypes.apply(this, arg)); } else if (is.string(arg)) { Array.prototype.push.apply(ret, array.uniquePush(this._eventTypes, arg)); } } return ret; }
parseSize(size, cfg, idx) { if (is.string(size)) { return size; } else if (is.fn(size)) { return size(cfg, idx); } else if (is.hash(size)) { return this.parseSize(size[idx], cfg, idx); } else { return null; } }
var _parseOutputFileName = function(out, dir) { if (is.string(out)) { return out; } if (is.fn(out)) { return out(dir); } else { throw new Error('invalid output:' + out); } }