From 67344660d44b0788fbe2d1392a310a01f51f6a95 Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Mon, 27 Jun 2016 18:09:44 +0200 Subject: [PATCH] Added getChat, getChatAdministrators, getChatMembersCount and getChatMember --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- src/telegram.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ace732f..12566d2 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,10 @@ TelegramBot * [.downloadFile(fileId, downloadDir)](#TelegramBot+downloadFile) ⇒ Promise * [.onText(regexp, callback)](#TelegramBot+onText) * [.onReplyToMessage(chatId, messageId, callback)](#TelegramBot+onReplyToMessage) + * [.getChat(chatId)](#TelegramBot+getChat) ⇒ Promise + * [.getChatAdministrators(chatId)](#TelegramBot+getChatAdministrators) ⇒ Promise + * [.getChatMembersCount(chatId)](#TelegramBot+getChatMembersCount) ⇒ Promise + * [.getChatMember(chatId, userId)](#TelegramBot+getChatMember) ⇒ Promise @@ -362,7 +366,7 @@ Note that you must provide one of chat_id, message_id, or inline_message_id in your request. **Kind**: instance method of [TelegramBot](#TelegramBot) -**See**: https://core.telegram.org/bots/api#editmessagetext +**See**: https://core.telegram.org/bots/api#editmessagecaption | Param | Type | Description | | --- | --- | --- | @@ -489,4 +493,53 @@ Register a reply to wait for a message response. | messageId | Number | String | The message id to be replied. | | callback | function | Callback will be called with the reply message. | + + +### telegramBot.getChat(chatId) ⇒ Promise +Returns information about the chat in form of a `Chat` object. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#getchat + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the target group or username of the target supergroup | + + + +### telegramBot.getChatAdministrators(chatId) ⇒ Promise +Returns the administrators in a chat in form of an Array of `ChatMember` objects. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#getchatadministrators + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the target group or username of the target supergroup | + + + +### telegramBot.getChatMembersCount(chatId) ⇒ Promise +Returns the number of members in a chat in form of an `Int` object. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#getchatmemberscount + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the target group or username of the target supergroup | + + + +### telegramBot.getChatMember(chatId, userId) ⇒ Promise +Returns information about a member of a chat in form of a `ChatMember` object. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#getchatmember + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the target group or username of the target supergroup | +| userId | String | Unique identifier of the target user | + * * * diff --git a/src/telegram.js b/src/telegram.js index d033b11..7a5e61a 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -699,6 +699,60 @@ class TelegramBot extends EventEmitter { callback }); } + + /** + * Returns information about the chat in form of a `Chat` object. + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup + * @return {Promise} + * @see https://core.telegram.org/bots/api#getchat + */ + getChat(chatId) { + const form = { + chat_id: chatId + }; + return this._request('getChat', { form }); + } + + /** + * Returns the administrators in a chat in form of an Array of `ChatMember` objects. + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup + * @return {Promise} + * @see https://core.telegram.org/bots/api#getchatadministrators + */ + getChatAdministrators(chatId) { + const form = { + chat_id: chatId + }; + return this._request('getChatAdministrators', { form }); + } + + /** + * Returns the number of members in a chat in form of an `Int` object. + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup + * @return {Promise} + * @see https://core.telegram.org/bots/api#getchatmemberscount + */ + getChatMembersCount(chatId) { + const form = { + chat_id: chatId + }; + return this._request('getChatMembersCount', { form }); + } + + /** + * Returns information about a member of a chat in form of a `ChatMember` object. + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup + * @param {String} userId Unique identifier of the target user + * @return {Promise} + * @see https://core.telegram.org/bots/api#getchatmember + */ + getChatMember(chatId, userId) { + const form = { + chat_id: chatId, + user_id: userId + }; + return this._request('getChatMember', { form }); + } } module.exports = TelegramBot;