From 3a4e3cd7212097cba91e3990671aae5b1b1e8ea0 Mon Sep 17 00:00:00 2001 From: Jishnu Mohan Date: Tue, 4 Oct 2016 00:05:20 +0530 Subject: [PATCH] adding sendGame and setGameScore --- README.md | 30 ++++++++++++++++++++++++++++++ src/telegram.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/README.md b/README.md index 01607d5..7bccc76 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,8 @@ TelegramBot * [.downloadFile(fileId, downloadDir)](#TelegramBot+downloadFile) ⇒ Promise * [.onText(regexp, callback)](#TelegramBot+onText) * [.onReplyToMessage(chatId, messageId, callback)](#TelegramBot+onReplyToMessage) + * [.sendGame(chatId, gameShortName, [options])](#TelegramBot+sendGame) ⇒ Promise + * [.setGameScore(userId, score, [options])](#TelegramBot+setGameScore) ⇒ Promise @@ -497,4 +499,32 @@ 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.sendGame(chatId, gameShortName, [options]) ⇒ Promise +Send game. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#sendgame + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the message recipient | +| gameShortName | String | name of the game to be sent. | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.setGameScore(userId, score, [options]) ⇒ Promise +Send new game score. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#sendgame + +| Param | Type | Description | +| --- | --- | --- | +| userId | String | Unique identifier of the target user | +| score | Number | New score value. | +| [options] | Object | Additional Telegram query options | + * * * diff --git a/src/telegram.js b/src/telegram.js index 7359306..7713635 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -711,6 +711,34 @@ class TelegramBot extends EventEmitter { callback }); } + + /** + * Send game. + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {String} gameShortName name of the game to be sent. + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#sendgame + */ + sendGame(chatId, gameShortName, form = {}) { + form.chat_id = chatId; + form.game_short_name = gameShortName; + return this._request('sendGame', { form: form }); + } + + /** + * Send new game score. + * @param {String} userId Unique identifier of the target user + * @param {Number} score New score value. + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#sendgame + */ + setGameScore(userId, score, form = {}) { + form.user_id = userId; + form.score = score; + return this._request('setGameScore', { form: form }); + } } module.exports = TelegramBot;