From cf8e90e70f15ecb0d109622e98d10ba92fa4a7e4 Mon Sep 17 00:00:00 2001 From: Serhii Dmytruk Date: Fri, 10 Jun 2016 12:51:10 +0300 Subject: [PATCH] getchat action --- README.md | 12 +++++++++++- src/telegram.js | 15 +++++++++++++++ test/index.js | 9 +++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ace732f..633227c 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ TelegramBot * [TelegramBot](#TelegramBot) * [new TelegramBot(token, [options])](#new_TelegramBot_new) * [.getMe()](#TelegramBot+getMe) ⇒ Promise + * [.getChat()](#TelegramBot+getChat) ⇒ Promise * [.setWebHook(url, [cert])](#TelegramBot+setWebHook) * [.getUpdates([timeout], [limit], [offset])](#TelegramBot+getUpdates) ⇒ Promise * [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ Promise @@ -111,6 +112,15 @@ Returns basic information about the bot in form of a `User` object. **Kind**: instance method of [TelegramBot](#TelegramBot) **See**: https://core.telegram.org/bots/api#getme + + +### telegramBot.getChat() ⇒ Promise +Use this method to get up to date information about the chat +(current name of the user for one-on-one conversations, current +username of a user, group or channel, etc.). + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#getchat ### telegramBot.setWebHook(url, [cert]) @@ -362,7 +372,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 | | --- | --- | --- | diff --git a/src/telegram.js b/src/telegram.js index d033b11..4ca529a 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -186,6 +186,21 @@ class TelegramBot extends EventEmitter { return this._request(_path); } + /** + * Use this method to get up to date information about the chat + * (current name of the user for one-on-one conversations, current + * username of a user, group or channel, etc.). + * @return {Promise} + * @see https://core.telegram.org/bots/api#getchat + */ + getChat(chatId) { + const form = { + chat_id: chatId + }; + + return this._request('getChat', {form: form}); + } + /** * Specify an url to receive incoming updates via an outgoing webHook. * @param {String} url URL where Telegram will make HTTP Post. Leave empty to diff --git a/test/index.js b/test/index.js index 698f3b6..4e2588d 100644 --- a/test/index.js +++ b/test/index.js @@ -131,6 +131,15 @@ describe('Telegram', function telegramSuite() { }); }); + describe('#getChat', function getMeSuite() { + it('should return an User object', function test() { + const bot = new Telegram(TOKEN); + return bot.getChat(USERID).then(resp => { + assert.ok(is.object(resp)); + }); + }); + }); + describe('#getUpdates', function getUpdatesSuite() { it('should return an Array', function test() { const bot = new Telegram(TOKEN);