Skip to content

Commit 2b89e8a

Browse files
committed
add Bots 2.0
- add `all` option - add `kickChatMember`, `unbanChatMember`, `answerCallbackQuery` - add `editMessageText`, `editMessageCaption`, `editMessageReplyMarkup` related issue: yagop/node-telegram-bot-api#102
1 parent 8089999 commit 2b89e8a

File tree

3 files changed

+231
-7
lines changed

3 files changed

+231
-7
lines changed

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ var bot = new TelegramBot(token, {polling: true});
1919
```
2020

2121
# Options
22+
## all
23+
with this option you can enable all patch.
24+
```js
25+
options = {all: true};
26+
// setup bot ...
27+
// usage
28+
bot.stopPolling();
29+
bot.kickChatMember(chatId, userId);
30+
// ...
31+
```
32+
2233
## stopPolling
2334
With this option you can stop polling.
2435
```js
@@ -67,6 +78,72 @@ bot.sendVenue(chatID, lat, long, title, address);
6778
[related pull request](https://github.com/yagop/node-telegram-bot-api/pull/121)
6879

6980

81+
## kickChatMember
82+
This option provide `kickChatMember` method
83+
```js
84+
options = {kickChatMember: true};
85+
// setup bot ...
86+
// usage
87+
bot.kickChatMember(chatId, userId);
88+
```
89+
[related pull request](https://github.com/yagop/node-telegram-bot-api/pull/102)
90+
91+
92+
## unbanChatMember
93+
This option provide `unbanChatMember` method
94+
```js
95+
options = {unbanChatMember: true};
96+
// setup bot ...
97+
// usage
98+
bot.unbanChatMember(chatId, userId);
99+
```
100+
[related pull request](https://github.com/yagop/node-telegram-bot-api/pull/102)
101+
102+
## answerCallbackQuery
103+
This option provide `answerCallbackQuery` method
104+
```js
105+
options = {unbanChatMember: true};
106+
// setup bot ...
107+
// usage
108+
bot.answerCallbackQuery(callbackQueryId, text, showAlert);
109+
```
110+
[related pull request](https://github.com/yagop/node-telegram-bot-api/pull/102)
111+
112+
113+
## editMessageText
114+
This option provide `editMessageText` method
115+
```js
116+
options = {editMessageText: true};
117+
// setup bot ...
118+
// usage
119+
bot.editMessageText(text);
120+
```
121+
[related pull request](https://github.com/yagop/node-telegram-bot-api/pull/102)
122+
123+
124+
## editMessageCaption
125+
This option provide `editMessageCaption` method
126+
```js
127+
options = {editMessageCaption: true};
128+
// setup bot ...
129+
// usage
130+
bot.editMessageCaption(caption);
131+
```
132+
[related pull request](https://github.com/yagop/node-telegram-bot-api/pull/102)
133+
134+
135+
## editMessageReplyMarkup
136+
This option provide `editMessageReplyMarkup` method
137+
```js
138+
options = {editMessageReplyMarkup: true};
139+
// setup bot ...
140+
// usage
141+
bot.editMessageReplyMarkup(replyMarkup);
142+
```
143+
[related pull request](https://github.com/yagop/node-telegram-bot-api/pull/102)
144+
145+
146+
70147
# Compatibility
71148

72149
I test this package with `[email protected]` and `[email protected]`

index.js

Lines changed: 153 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ function patchEmitCallbackQuery(TelegramBot) {
3232
}
3333
}
3434

35-
function patchSendVenue(TelegramBot)
36-
{
35+
function patchSendVenue(TelegramBot) {
3736
/**
3837
* Send venue.
3938
* Use this method to send information about a venue.
@@ -58,18 +57,166 @@ function patchSendVenue(TelegramBot)
5857
}
5958
}
6059

60+
function patchKickChatMember(TelegramBot) {
61+
/**
62+
* Use this method to kick a user from a group or a supergroup.
63+
* In the case of supergroups, the user will not be able to return
64+
* to the group on their own using invite links, etc., unless unbanned
65+
* first. The bot must be an administrator in the group for this to work.
66+
* Returns True on success.
67+
*
68+
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
69+
* @param {String} userId Unique identifier of the target user
70+
* @return {Promise}
71+
* @see https://core.telegram.org/bots/api#kickchatmember
72+
*/
73+
TelegramBot.prototype.kickChatMember = function kickChatMember(chatId, userId) {
74+
const form = {
75+
chat_id: chatId,
76+
user_id: userId
77+
};
78+
return this._request('kickChatMember', {form: form});
79+
}
80+
}
81+
82+
function patchUnbanChatMember(TelegramBot) {
83+
/**
84+
* Use this method to unban a previously kicked user in a supergroup.
85+
* The user will not return to the group automatically, but will be
86+
* able to join via link, etc. The bot must be an administrator in
87+
* the group for this to work. Returns True on success.
88+
*
89+
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
90+
* @param {String} userId Unique identifier of the target user
91+
* @return {Promise}
92+
* @see https://core.telegram.org/bots/api#unbanchatmember
93+
*/
94+
TelegramBot.prototype.unbanChatMember = function unbanChatMember(chatId, userId) {
95+
const form = {
96+
chat_id: chatId,
97+
user_id: userId
98+
};
99+
return this._request('unbanChatMember', {form: form});
100+
}
101+
}
102+
103+
function pathAnswerCallbackQuery(TelegramBot) {
104+
/**
105+
* Use this method to send answers to callback queries sent from
106+
* inline keyboards. The answer will be displayed to the user as
107+
* a notification at the top of the chat screen or as an alert.
108+
* On success, True is returned.
109+
*
110+
* @param {Number|String} callbackQueryId Unique identifier for the query to be answered
111+
* @param {String} text Text of the notification. If not specified, nothing will be shown to the user
112+
* @param {Boolean} showAlert Whether to show an alert or a notification at the top of the screen
113+
* @param {Object} [options] Additional Telegram query options
114+
* @return {Promise}
115+
* @see https://core.telegram.org/bots/api#answercallbackquery
116+
*/
117+
TelegramBot.prototype.answerCallbackQuery = function answerCallbackQuery(callbackQueryId, text, showAlert, form) {
118+
form = form || {};
119+
form.callback_query_id = callbackQueryId;
120+
form.text = text;
121+
form.show_alert = showAlert;
122+
return this._request('answerCallbackQuery', {form: form});
123+
}
124+
}
125+
126+
function patchEditMessageText(TelegramBot) {
127+
/**
128+
* Use this method to edit text messages sent by the bot or via
129+
* the bot (for inline bots). On success, the edited Message is
130+
* returned.
131+
*
132+
* Note that you must provide one of chat_id, message_id, or
133+
* inline_message_id in your request.
134+
*
135+
* @param {String} text New text of the message
136+
* @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
137+
* @return {Promise}
138+
* @see https://core.telegram.org/bots/api#editmessagetext
139+
*/
140+
TelegramBot.prototype.editMessageText = function editMessageText(text, form) {
141+
form = form || {};
142+
form.text = text;
143+
return this._request('editMessageText', {form: form});
144+
}
145+
146+
}
147+
148+
149+
function patchEditMessageCaption(TelegramBot) {
150+
/**
151+
* Use this method to edit captions of messages sent by the
152+
* bot or via the bot (for inline bots). On success, the
153+
* edited Message is returned.
154+
*
155+
* Note that you must provide one of chat_id, message_id, or
156+
* inline_message_id in your request.
157+
*
158+
* @param {String} caption New caption of the message
159+
* @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
160+
* @return {Promise}
161+
* @see https://core.telegram.org/bots/api#editmessagecaption
162+
*/
163+
TelegramBot.prototype.editMessageCaption = function editMessageCaption(caption, form) {
164+
form = form || {};
165+
form.caption = caption;
166+
return this._request('editMessageCaption', {form: form});
167+
}
168+
}
169+
function patchEditMessageReplyMarkup(TelegramBot) {
170+
/**
171+
* Use this method to edit only the reply markup of messages
172+
* sent by the bot or via the bot (for inline bots).
173+
* On success, the edited Message is returned.
174+
*
175+
* Note that you must provide one of chat_id, message_id, or
176+
* inline_message_id in your request.
177+
*
178+
* @param {Object} replyMarkup A JSON-serialized object for an inline keyboard.
179+
* @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
180+
* @return {Promise}
181+
* @see https://core.telegram.org/bots/api#editmessagereplymarkup
182+
*/
183+
TelegramBot.prototype.editMessageReplyMarkup = function editMessageReplyMarkup(replyMarkup, form) {
184+
form = form || {};
185+
form.reply_markup = replyMarkup;
186+
return this._request('editMessageReplyMarkup', {form: form});
187+
}
188+
}
189+
61190
module.exports = function (TelegramBot, options) {
62191
options = options || {};
63-
if (options.stopPolling) {
192+
if (options.all || options.stopPolling) {
64193
patchStopPolling(TelegramBot);
65194
}
66-
if (options.emitUpdate) {
195+
if (options.all || options.emitUpdate) {
67196
patchEmitUpdate(TelegramBot);
68197
}
69-
if (options.emitCallbackQuery) {
198+
if (options.all || options.emitCallbackQuery) {
70199
patchEmitCallbackQuery(TelegramBot);
71200
}
72-
if (options.sendVenue){
201+
if (options.all || options.sendVenue) {
73202
patchSendVenue(TelegramBot);
74203
}
204+
if (options.all || options.kickChatMember) {
205+
patchKickChatMember(TelegramBot);
206+
}
207+
if (options.all || options.unbanChatMember) {
208+
patchUnbanChatMember(TelegramBot);
209+
}
210+
if (options.all || options.answerCallbackQuery) {
211+
pathAnswerCallbackQuery(TelegramBot);
212+
}
213+
if (options.all || options.editMessageText) {
214+
patchEditMessageText(TelegramBot);
215+
}
216+
if (options.all || options.editMessageCaption) {
217+
patchEditMessageCaption(TelegramBot);
218+
}
219+
if (options.all || options.editMessageReplyMarkup) {
220+
patchEditMessageReplyMarkup(TelegramBot);
221+
}
75222
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "monkey-patches-node-telegram-bot-api",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "monkey patch for https://github.com/yagop/node-telegram-bot-api",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)