From 5d30b6a1348d11886b4edf16fcddbda718b9c39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Thu, 10 Dec 2020 11:47:22 +0100 Subject: [PATCH] Telegram Bot API 5.0 Support (#835) * Add new method sendPoll * getMyCommands * setMyCommands * Update doc/api * 1# Fix Test sendPhoto The sendPhoto method does not support .gif files, use sendAnimation. This fix remplace .gif file by .png * CustomTitle and ChatPermissions support setChatAdministratorCustomTitle setChatPermissions * Update Readme Update Badge Telegram API Version * Minor Fix and Fix setChatPhoto The Telegram Bots api has a bug that they are fixing and gives problems with the previous image. While they don't fix it, the image replacement is the fastest solution * Minor Fix and Add Test Fixed setChatPermissions Test: - sendDice - getMyCommands - setMyCommands - setChatAdministratorCustomTitle - setChatPermissions * Update Changelog and Package.json version * Fix typos in Changelog * Add support for poll_answer From: https://github.com/yagop/node-telegram-bot-api/pull/777 * Add JieJiSS contribution in Changelog * Add sendPoll Test * Add unpinAllChatMessages Support * Add copyMessage support * Add close and logOut Support * Add Test + Minor fixes * Update CHANGELOG Update version 0.50.1 * Update Readme Bot API Badge * Update Version to 0.51.0 --- CHANGELOG.md | 21 ++++++- README.md | 2 +- doc/api.md | 64 +++++++++++++++++++++- package.json | 2 +- src/telegram.js | 61 +++++++++++++++++++++ test/telegram.js | 140 ++++++++++++++++++++++++++++------------------- 6 files changed, 230 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce23d50..ddd59c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,28 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.51.0][0.51.0] - 2020-11-04 + +Added: + +1. Support Bot API v5.0: (by @danielperez9430) + * Add method *copyMessage()* + * Add method *unpinAllChatMessages()* + * Add method *close()* + * Add method *logOut()* + + Changed: (by @danielperez9430) + * Remove trailing-spaces + * Fix Bugs in Test + + New Test: (by @danielperez9430) + * copyMessage + * unpinAllChatMessages + + ## [0.50.0][0.50.0] - 2020-05-2020 -Added: +Added: 1. Support Bot API v4.8: (by @danielperez9430) * Add methods: *sendDice()* diff --git a/README.md b/README.md index b27e1d6..6b4f04a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Node.js module to interact with the official [Telegram Bot API](https://core.telegram.org/bots/api). -[![Bot API](https://img.shields.io/badge/Bot%20API-v.4.8.0-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-v.5.0-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) [![npm package](https://img.shields.io/npm/v/node-telegram-bot-api?logo=npm&style=flat-square)](https://www.npmjs.org/package/node-telegram-bot-api) [![Build Status](https://img.shields.io/travis/yagop/node-telegram-bot-api/master?style=flat-square&logo=travis)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Coverage Status](https://img.shields.io/codecov/c/github/yagop/node-telegram-bot-api?style=flat-square&logo=codecov)](https://codecov.io/gh/yagop/node-telegram-bot-api) diff --git a/doc/api.md b/doc/api.md index c79b9a5..b791ba4 100644 --- a/doc/api.md +++ b/doc/api.md @@ -22,6 +22,8 @@ TelegramBot * [.closeWebHook()](#TelegramBot+closeWebHook) ⇒ Promise * [.hasOpenWebHook()](#TelegramBot+hasOpenWebHook) ⇒ Boolean * [.getMe([options])](#TelegramBot+getMe) ⇒ Promise + * [.logOut([options])](#TelegramBot+logOut) ⇒ Promise + * [.close([options])](#TelegramBot+close) ⇒ Promise * [.setWebHook(url, [options], [fileOptions])](#TelegramBot+setWebHook) ⇒ Promise * [.deleteWebHook([options])](#TelegramBot+deleteWebHook) ⇒ Promise * [.getWebHookInfo([options])](#TelegramBot+getWebHookInfo) ⇒ Promise @@ -30,6 +32,7 @@ TelegramBot * [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ Promise * [.answerInlineQuery(inlineQueryId, results, [options])](#TelegramBot+answerInlineQuery) ⇒ Promise * [.forwardMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+forwardMessage) ⇒ Promise + * [.copyMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+copyMessage) ⇒ Promise * [.sendPhoto(chatId, photo, [options], [fileOptions])](#TelegramBot+sendPhoto) ⇒ Promise * [.sendAudio(chatId, audio, [options], [fileOptions])](#TelegramBot+sendAudio) ⇒ Promise * [.sendDocument(chatId, doc, [options], [fileOptions])](#TelegramBot+sendDocument) ⇒ Promise @@ -52,6 +55,7 @@ TelegramBot * [.setChatDescription(chatId, description, [options])](#TelegramBot+setChatDescription) ⇒ Promise * [.pinChatMessage(chatId, messageId, [options])](#TelegramBot+pinChatMessage) ⇒ Promise * [.unpinChatMessage(chatId, [options])](#TelegramBot+unpinChatMessage) ⇒ Promise + * [.unpinAllChatMessages(chatId, [options])](#TelegramBot+unpinAllChatMessages) ⇒ Promise * [.answerCallbackQuery(callbackQueryId, [options])](#TelegramBot+answerCallbackQuery) ⇒ Promise * [.setMyCommands(commands, [options])](#TelegramBot+setMyCommands) ⇒ Promise * [.getMyCommands([options])](#TelegramBot+getMyCommands) ⇒ Promise @@ -235,6 +239,35 @@ Returns basic information about the bot in form of a `User` object. | --- | --- | --- | | [options] | Object | Additional Telegram query options | + + +### telegramBot.logOut([options]) ⇒ Promise +This method log out your bot from the cloud Bot API server before launching the bot locally. +You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. +After a successful call, you will not be able to log in again using the same token for 10 minutes. +Returns True on success. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#logout + +| Param | Type | Description | +| --- | --- | --- | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.close([options]) ⇒ Promise +This method close the bot instance before moving it from one local server to another. +This method will return error 429 in the first 10 minutes after the bot is launched. +Returns True on success. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#close + +| Param | Type | Description | +| --- | --- | --- | +| [options] | Object | Additional Telegram query options | + ### telegramBot.setWebHook(url, [options], [fileOptions]) ⇒ Promise @@ -354,6 +387,20 @@ Forward messages of any kind. | messageId | Number \| String | Unique message identifier | | [options] | Object | Additional Telegram query options | + + +### telegramBot.copyMessage(chatId, fromChatId, messageId, [options]) ⇒ Promise +Copy messages of any kind. + +**Kind**: instance method of [TelegramBot](#TelegramBot) + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the message recipient | +| fromChatId | Number \| String | Unique identifier for the chat where the original message was sent | +| messageId | Number \| String | Unique message identifier | +| [options] | Object | Additional Telegram query options | + ### telegramBot.sendPhoto(chatId, photo, [options], [fileOptions]) ⇒ Promise @@ -720,7 +767,7 @@ Returns True on success. ### telegramBot.unpinChatMessage(chatId, [options]) ⇒ Promise -Use this method to unpin a message in a supergroup chat. +Use this method to unpin a message from the list of pinned messages in a chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. @@ -732,6 +779,21 @@ Returns True on success. | chatId | Number \| String | Unique identifier for the message recipient | | [options] | Object | Additional Telegram query options | + + +### telegramBot.unpinAllChatMessages(chatId, [options]) ⇒ Promise +Use this method to clear the list of pinned messages in a chat +The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. +Returns True on success. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#unpinallchatmessages + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the message recipient | +| [options] | Object | Additional Telegram query options | + ### telegramBot.answerCallbackQuery(callbackQueryId, [options]) ⇒ Promise diff --git a/package.json b/package.json index c55f571..50234ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-telegram-bot-api", - "version": "0.50.0", + "version": "0.51.0", "description": "Telegram Bot API", "main": "./index.js", "directories": { diff --git a/src/telegram.js b/src/telegram.js index 4e10f2f..7c04112 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -473,6 +473,31 @@ class TelegramBot extends EventEmitter { return this._request('getMe', { form }); } + /** + * This method log out your bot from the cloud Bot API server before launching the bot locally. + * You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. + * After a successful call, you will not be able to log in again using the same token for 10 minutes. + * Returns True on success. + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#logout + */ + logOut(form = {}) { + return this._request('logOut', { form }); + } + + /** + * This method close the bot instance before moving it from one local server to another. + * This method will return error 429 in the first 10 minutes after the bot is launched. + * Returns True on success. + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#close + */ + close(form = {}) { + return this._request('close', { form }); + } + /** * Specify an url to receive incoming updates via an outgoing webHook. * This method has an [older, compatible signature][setWebHook-v0.25.0] @@ -712,6 +737,7 @@ class TelegramBot extends EventEmitter { * @param {Number|String} messageId Unique message identifier * @param {Object} [options] Additional Telegram query options * @return {Promise} + * @see https://core.telegram.org/bots/api#forwardmessage */ forwardMessage(chatId, fromChatId, messageId, form = {}) { form.chat_id = chatId; @@ -720,6 +746,26 @@ class TelegramBot extends EventEmitter { return this._request('forwardMessage', { form }); } + /** + * Copy messages of any kind. + * The method is analogous to the method forwardMessages, but the copied message doesn't + * have a link to the original message. + * Returns the MessageId of the sent message on success. + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {Number|String} fromChatId Unique identifier for the chat where the + * original message was sent + * @param {Number|String} messageId Unique message identifier + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#copymessage + */ + copyMessage(chatId, fromChatId, messageId, form = {}) { + form.chat_id = chatId; + form.from_chat_id = fromChatId; + form.message_id = messageId; + return this._request('copyMessage', { form }); + } + /** * Send photo * @param {Number|String} chatId Unique identifier for the message recipient @@ -1202,6 +1248,21 @@ class TelegramBot extends EventEmitter { return this._request('unpinChatMessage', { form }); } + /** + * Use this method to clear the list of pinned messages in a chat + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * Returns True on success. + * + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#unpinallchatmessages + */ + unpinAllChatMessages(chatId, form = {}) { + form.chat_id = chatId; + return this._request('unpinAllChatMessages', { form }); + } + /** * Use this method to send answers to callback queries sent from * inline keyboards. The answer will be displayed to the user as diff --git a/test/telegram.js b/test/telegram.js index fa7b02f..55a460b 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -63,11 +63,11 @@ describe('module.exports', function moduleExportsSuite() { const nodeVersion = parseInt(process.versions.node.split('.')[0], 10); it('is loaded from src/ on Node.js v6+ and above', function test() { if (nodeVersion <= 5) this.skip(); // skip on Node.js v5 and below - assert.equal(TelegramBot, require('../src/telegram')); + assert.strictEqual(TelegramBot, require('../src/telegram')); }); it('is loaded from lib/ on Node.js v5 and below', function test() { if (nodeVersion > 5) this.skip(); // skip on newer versions - assert.equal(TelegramBot, require('../lib/telegram')); + assert.strictEqual(TelegramBot, require('../lib/telegram')); }); }); @@ -125,22 +125,22 @@ describe('TelegramBot', function telegramSuite() { }); it('automatically starts polling', function test() { - assert.equal(botPolling.isPolling(), true); + assert.strictEqual(botPolling.isPolling(), true); return utils.isPollingMockServer(pollingPort2); }); it('automatically opens webhook', function test() { - assert.equal(botWebHook.hasOpenWebHook(), true); + assert.strictEqual(botWebHook.hasOpenWebHook(), true); return utils.hasOpenWebHook(webHookPort2); }); it('does not automatically poll if "autoStart" is false', function test() { - assert.equal(testbot.isPolling(), false); + assert.strictEqual(testbot.isPolling(), false); return utils.isPollingMockServer(pollingPort, true); }); it('does not automatically open webhook if "autoOpen" is false', function test() { - assert.equal(testbot.hasOpenWebHook(), false); + assert.strictEqual(testbot.hasOpenWebHook(), false); return utils.hasOpenWebHook(webHookPort, true); }); @@ -169,7 +169,7 @@ describe('TelegramBot', function telegramSuite() { const myBot = new TelegramBot(12345, { polling: true }); myBot.once('polling_error', (error) => { assert.ok(error); - assert.equal(error.code, 'ETELEGRAM'); + assert.strictEqual(error.code, 'ETELEGRAM'); return myBot.stopPolling().then(() => { done(); }).catch(done); }); }); @@ -182,7 +182,7 @@ describe('TelegramBot', function telegramSuite() { it('(webhook) emits "webhook_error" if could not parse webhook request body', function test(done) { botWebHook.once('webhook_error', (error) => { assert.ok(error); - assert.equal(error.code, 'EPARSE'); + assert.strictEqual(error.code, 'EPARSE'); return done(); }); utils.sendWebHookMessage(webHookPort2, TOKEN, { update: 'unparseable!', json: false }); @@ -192,13 +192,13 @@ describe('TelegramBot', function telegramSuite() { describe('WebHook', function webHookSuite() { it('returns 200 OK for health endpoint', function test(done) { utils.sendWebHookRequest(webHookPort2, '/healthz').then(resp => { - assert.equal(resp, 'OK'); + assert.strictEqual(resp, 'OK'); return done(); }); }); it('returns 401 error if token is wrong', function test(done) { utils.sendWebHookMessage(webHookPort2, 'wrong-token').catch(resp => { - assert.equal(resp.statusCode, 401); + assert.strictEqual(resp.statusCode, 401); return done(); }); }); @@ -250,7 +250,7 @@ describe('TelegramBot', function telegramSuite() { const myBot = new TelegramBot(null); return myBot.sendMessage(USERID, 'text').catch(error => { // FIX: assert.ok(error instanceof TelegramBot.errors.FatalError); - assert.equal(error.code, 'EFATAL'); + assert.strictEqual(error.code, 'EFATAL'); assert.ok(error.message.indexOf('not provided') > -1); }); }); @@ -263,7 +263,7 @@ describe('TelegramBot', function telegramSuite() { } return bot.sendPhoto(USERID, buffer).catch(error => { // FIX: assert.ok(error instanceof TelegramBot.errors.FatalError); - assert.equal(error.code, 'EFATAL'); + assert.strictEqual(error.code, 'EFATAL'); assert.ok(error.message.indexOf('Unsupported') > -1); }); }); @@ -273,13 +273,13 @@ describe('TelegramBot', function telegramSuite() { }); return myBot.getMe().catch(error => { // FIX: assert.ok(error instanceof TelegramBot.errors.FatalError); - assert.equal(error.code, 'EFATAL'); + assert.strictEqual(error.code, 'EFATAL'); }); }); it('ParseError is thrown if response body could not be parsed', function test() { botParse.sendMessage(USERID, 'text').catch(error => { // FIX: assert.ok(error instanceof TelegramBot.errors.ParseError); - assert.equal(error.code, 'EPARSE'); + assert.strictEqual(error.code, 'EPARSE'); assert.ok(typeof error.response === 'object'); assert.ok(typeof error.response.body === 'string'); }); @@ -287,7 +287,7 @@ describe('TelegramBot', function telegramSuite() { it('TelegramError is thrown if error is from Telegram', function test() { return bot.sendMessage('404', 'text').catch(error => { // FIX: assert.ok(error instanceof TelegramBot.errors.TelegramError); - assert.equal(error.code, 'ETELEGRAM'); + assert.strictEqual(error.code, 'ETELEGRAM'); assert.ok(typeof error.response === 'object'); assert.ok(typeof error.response.body === 'object'); }); @@ -304,7 +304,7 @@ describe('TelegramBot', function telegramSuite() { return botWebHook.startPolling().catch((err) => { // TODO: check for error in a better way // FIX: assert.ok(err instanceof TelegramBot.errors.FatalError); - assert.equal(err.code, 'EFATAL'); + assert.strictEqual(err.code, 'EFATAL'); assert.ok(err.message.indexOf('mutually exclusive') !== -1); }); }); @@ -312,12 +312,12 @@ describe('TelegramBot', function telegramSuite() { describe('#isPolling', function isPollingSuite() { it('returns true if bot is polling', function test() { - assert.equal(testbot.isPolling(), true); + assert.strictEqual(testbot.isPolling(), true); return utils.isPollingMockServer(pollingPort); }); it('returns false if bot is not polling', function test() { return testbot.stopPolling().then(() => { - assert.equal(testbot.isPolling(), false); + assert.strictEqual(testbot.isPolling(), false); utils.clearPollingCheck(pollingPort); return utils.isPollingMockServer(pollingPort, true); }); @@ -346,7 +346,7 @@ describe('TelegramBot', function telegramSuite() { return botPolling.openWebHook().catch((err) => { // TODO: check for error in a better way // FIX: assert.ok(err instanceof TelegramBot.errors.FatalError); - assert.equal(err.code, 'EFATAL'); + assert.strictEqual(err.code, 'EFATAL'); assert.ok(err.message.indexOf('mutually exclusive') !== -1); }); }); @@ -354,12 +354,12 @@ describe('TelegramBot', function telegramSuite() { describe('#hasOpenWebHook', function hasOpenWebHookSuite() { it('returns true if webhook is opened', function test() { - assert.equal(testbot.hasOpenWebHook(), true); + assert.strictEqual(testbot.hasOpenWebHook(), true); return utils.hasOpenWebHook(webHookPort); }); it('returns false if webhook is closed', function test() { testbot.closeWebHook().then(() => { - assert.equal(testbot.hasOpenWebHook(), false); + assert.strictEqual(testbot.hasOpenWebHook(), false); return utils.hasOpenWebHook(webHookPort, true); }); }); @@ -397,28 +397,28 @@ describe('TelegramBot', function telegramSuite() { return bot .setWebHook(ip) .then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); it('should set a webHook with certificate', function test() { return bot .setWebHook(ip, { certificate: cert }) .then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); it('(v0.25.0 and lower) should set a webHook with certificate', function test() { return bot .setWebHook(ip, cert) .then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); it('should delete the webHook', function test() { return bot .setWebHook('') .then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -429,7 +429,7 @@ describe('TelegramBot', function telegramSuite() { }); it('should delete webhook', function test() { return bot.deleteWebHook().then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -459,12 +459,12 @@ describe('TelegramBot', function telegramSuite() { }); it('should return an Array', function test() { return bot.getUpdates(opts).then(resp => { - assert.equal(Array.isArray(resp), true); + assert.strictEqual(Array.isArray(resp), true); }); }); it('(v0.25.0 and lower) should return an Array', function test() { return bot.getUpdates(opts.timeout, opts.limit).then(resp => { - assert.equal(Array.isArray(resp), true); + assert.strictEqual(Array.isArray(resp), true); }); }); }); @@ -500,6 +500,23 @@ describe('TelegramBot', function telegramSuite() { }); }); + describe('#copyMessage', function copyMessageSuite() { + before(function before() { + utils.handleRatelimit(bot, 'sendMessage', this); + utils.handleRatelimit(bot, 'copyMessage', this); + }); + it('should send copy of a message', function test() { + return bot.sendMessage(USERID, 'test').then(resp => { + const messageId = resp.message_id; + return bot.copyMessage(USERID, USERID, messageId) + .then(copy => { + assert.ok(is.object(copy)); + assert.ok(is.number(copy.message_id)); + }); + }); + }); + }); + describe('#sendPhoto', function sendPhotoSuite() { let photoId; this.timeout(timeout); @@ -812,7 +829,7 @@ describe('TelegramBot', function telegramSuite() { it('should send a chat action', function test() { const action = 'typing'; return bot.sendChatAction(USERID, action).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -892,25 +909,25 @@ describe('TelegramBot', function telegramSuite() { it('should set a chat photo from file', function test() { const photo = `${__dirname}/data/chat_photo.png`; return bot.setChatPhoto(GROUPID, photo).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); it('should set a chat photo from fs.readStream', function test() { const photo = fs.createReadStream(`${__dirname}/data/chat_photo.png`); return bot.setChatPhoto(GROUPID, photo).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); it('should set a chat photo from request Stream', function test() { const photo = request(`${staticUrl}/chat_photo.png`); return bot.setChatPhoto(GROUPID, photo).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); it('should set a chat photo from a Buffer', function test() { const photo = fs.readFileSync(`${__dirname}/data/chat_photo.png`); return bot.setChatPhoto(GROUPID, photo).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -921,7 +938,7 @@ describe('TelegramBot', function telegramSuite() { }); it('should delete the chat photo', function test() { return bot.deleteChatPhoto(GROUPID).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -933,7 +950,7 @@ describe('TelegramBot', function telegramSuite() { it('should set the chat title', function test() { const random = Math.floor(Math.random() * 1000); return bot.setChatTitle(GROUPID, `ntba test group (random: ${random})`).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -946,7 +963,7 @@ describe('TelegramBot', function telegramSuite() { const random = Math.floor(Math.random() * 1000); const description = `node-telegram-bot-api test group (random: ${random})`; return bot.setChatDescription(GROUPID, description).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -961,7 +978,7 @@ describe('TelegramBot', function telegramSuite() { }); it('should pin chat message', function test() { return bot.pinChatMessage(GROUPID, messageId).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -972,7 +989,18 @@ describe('TelegramBot', function telegramSuite() { }); it('should unpin chat message', function test() { return bot.unpinChatMessage(GROUPID).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); + }); + }); + }); + + describe('#unpinAllChatMessages', function unpinAllChatMessagesSuite() { + before(function before() { + utils.handleRatelimit(bot, 'unpinAllChatMessages', this); + }); + it('should unpin all chats messages', function test() { + return bot.unpinAllChatMessages(GROUPID).then(resp => { + assert.ok(is.boolean(resp)); }); }); }); @@ -984,13 +1012,13 @@ describe('TelegramBot', function telegramSuite() { }); it('should edit a message sent by the bot', function test() { return bot.sendMessage(USERID, 'test').then(resp => { - assert.equal(resp.text, 'test'); + assert.strictEqual(resp.text, 'test'); const opts = { chat_id: USERID, message_id: resp.message_id }; return bot.editMessageText('edit test', opts).then(msg => { - assert.equal(msg.text, 'edit test'); + assert.strictEqual(msg.text, 'edit test'); }); }); }); @@ -1006,13 +1034,13 @@ describe('TelegramBot', function telegramSuite() { const photo = `${__dirname}/data/photo.png`; const options = { caption: 'test caption' }; return bot.sendPhoto(USERID, photo, options).then(resp => { - assert.equal(resp.caption, 'test caption'); + assert.strictEqual(resp.caption, 'test caption'); const opts = { chat_id: USERID, message_id: resp.message_id }; return bot.editMessageCaption('new test caption', opts).then(msg => { - assert.equal(msg.caption, 'new test caption'); + assert.strictEqual(msg.caption, 'new test caption'); }); }); }); @@ -1053,7 +1081,7 @@ describe('TelegramBot', function telegramSuite() { }); it('should delete message', function test() { return bot.deleteMessage(USERID, messageId).then(resp => { - assert.equal(resp, true); + assert.strictEqual(resp, true); }); }); }); @@ -1248,7 +1276,7 @@ describe('TelegramBot', function telegramSuite() { it('should get a file stream', function test(done) { const fileStream = bot.getFileStream(FILE_ID); assert.ok(fileStream instanceof stream.Readable); - assert.equal(fileStream.path, FILE_ID); + assert.strictEqual(fileStream.path, FILE_ID); fileStream.on('info', (info) => { assert.ok(info); assert.ok(utils.isTelegramFileURI(info.uri), `${info.uri} is not a file URI`); @@ -1270,7 +1298,7 @@ describe('TelegramBot', function telegramSuite() { return bot.downloadFile(FILE_ID, downloadPath) .then(filePath => { assert.ok(is.string(filePath)); - assert.equal(path.dirname(filePath), downloadPath); + assert.strictEqual(path.dirname(filePath), downloadPath); assert.ok(fs.existsSync(filePath)); fs.unlinkSync(filePath); // Delete file after test }); @@ -1281,7 +1309,7 @@ describe('TelegramBot', function telegramSuite() { it('should call `onText` callback on match', function test(done) { const regexp = /\/onText (.+)/; botWebHook.onText(regexp, (msg, match) => { - assert.equal(match[1], 'ECHO ALOHA'); + assert.strictEqual(match[1], 'ECHO ALOHA'); assert.ok(botWebHook.removeTextListener(regexp)); return done(); }); @@ -1292,7 +1320,7 @@ describe('TelegramBot', function telegramSuite() { it('should reset the global regex state with each message', function test(done) { const regexp = /\/onText (.+)/g; botWebHook.onText(regexp, () => { - assert.equal(regexp.lastIndex, 0); + assert.strictEqual(regexp.lastIndex, 0); assert.ok(botWebHook.removeTextListener(regexp)); return done(); }); @@ -1314,10 +1342,10 @@ describe('TelegramBot', function telegramSuite() { bot.onText(regexp, callback); bot.onText(regexp2, callback); const textListener = bot.removeTextListener(regexp); - assert.equal(regexp, textListener.regexp); + assert.strictEqual(regexp, textListener.regexp); }); it('returns `null` if missing', function test() { - assert.equal(null, bot.removeTextListener(/404/)); + assert.strictEqual(null, bot.removeTextListener(/404/)); }); }); @@ -1330,14 +1358,14 @@ describe('TelegramBot', function telegramSuite() { it('returns the right reply-listener', function test() { const id = bot.onReplyToMessage(chatId, messageId, callback); const replyListener = bot.removeReplyListener(id); - assert.equal(id, replyListener.id); - assert.equal(chatId, replyListener.chatId); - assert.equal(messageId, replyListener.messageId); - assert.equal(callback, replyListener.callback); + assert.strictEqual(id, replyListener.id); + assert.strictEqual(chatId, replyListener.chatId); + assert.strictEqual(messageId, replyListener.messageId); + assert.strictEqual(callback, replyListener.callback); }); it('returns `null` if missing', function test() { // NOTE: '0' is never a valid reply listener ID :) - assert.equal(null, bot.removeReplyListener(0)); + assert.strictEqual(null, bot.removeReplyListener(0)); }); }); @@ -1467,7 +1495,7 @@ describe('TelegramBot', function telegramSuite() { 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.strictEqual(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)); @@ -1511,7 +1539,7 @@ describe('TelegramBot', function telegramSuite() { disable_notification: true, }).then(resp => { assert.ok(is.array(resp)); - assert.equal(resp.length, 3); + assert.strictEqual(resp.length, 3); }); }); });