diff --git a/README.md b/README.md index 01607d5..9017078 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ TelegramBot * [new TelegramBot(token, [options])](#new_TelegramBot_new) * [.stopPolling()](#TelegramBot+stopPolling) ⇒ Promise * [.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 @@ -119,6 +120,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]) diff --git a/src/telegram.js b/src/telegram.js index cde1858..d82e06b 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -205,6 +205,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 207a015..defefd2 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);