Skip to content

Commit 2109d8c

Browse files
committed
Update to bot Api 5.3
1 parent 9bb8281 commit 2109d8c

9 files changed

Lines changed: 251 additions & 24 deletions

File tree

context.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ class TelegrafContext {
344344
return this.telegram.exportChatInviteLink(this.chat.id, ...args)
345345
}
346346

347+
banChatMember (...args) {
348+
this.assert(this.chat, 'banChatMember')
349+
return this.telegram.banChatMember(this.chat.id, ...args)
350+
}
351+
347352
kickChatMember (...args) {
348353
this.assert(this.chat, 'kickChatMember')
349354
return this.telegram.kickChatMember(this.chat.id, ...args)
@@ -426,7 +431,12 @@ class TelegrafContext {
426431

427432
getChatMembersCount (...args) {
428433
this.assert(this.chat, 'getChatMembersCount')
429-
return this.telegram.getChatMembersCount(this.chat.id, ...args)
434+
return this.telegram.getChatMemberCount(this.chat.id, ...args)
435+
}
436+
437+
getChatMemberCount (...args) {
438+
this.assert(this.chat, 'getChatMemberCount')
439+
return this.telegram.getChatMemberCount(this.chat.id, ...args)
430440
}
431441

432442
setPassportDataErrors (errors) {
@@ -570,14 +580,18 @@ class TelegrafContext {
570580
return this.telegram.addStickerToSet(this.from.id, ...args)
571581
}
572582

573-
getMyCommands () {
574-
return this.telegram.getMyCommands()
583+
getMyCommands (...args) {
584+
return this.telegram.getMyCommands(...args)
575585
}
576586

577587
setMyCommands (...args) {
578588
return this.telegram.setMyCommands(...args)
579589
}
580590

591+
deleteMyCommands (...args) {
592+
return this.telegram.deleteMyCommands(...args)
593+
}
594+
581595
replyWithMarkdown (markdown, extra) {
582596
return this.reply(markdown, { parse_mode: 'Markdown', ...extra })
583597
}

markup.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class Markup {
99
return this
1010
}
1111

12+
inputFieldPlaceholder (placeholder) {
13+
this.input_field_placeholder = placeholder
14+
return this
15+
}
16+
1217
selective (value = true) {
1318
this.selective = value
1419
return this
@@ -111,6 +116,10 @@ class Markup {
111116
return new Markup().resize(value)
112117
}
113118

119+
static inputFieldPlaceholder (placeholder) {
120+
return new Markup().inputFieldPlaceholder(placeholder)
121+
}
122+
114123
static selective (value = true) {
115124
return new Markup().selective(value)
116125
}

telegram.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ class Telegram extends ApiClient {
175175
}
176176

177177
getChatMembersCount (chatId) {
178-
return this.callApi('getChatMembersCount', { chat_id: chatId })
178+
return this.callApi('getChatMemberCount', { chat_id: chatId })
179+
}
180+
181+
getChatMemberCount (chatId) {
182+
return this.callApi('getChatMemberCount', { chat_id: chatId })
179183
}
180184

181185
answerInlineQuery (inlineQueryId, results, extra) {
@@ -186,8 +190,12 @@ class Telegram extends ApiClient {
186190
return this.callApi('setChatPermissions', { chat_id: chatId, permissions })
187191
}
188192

193+
banChatMember (chatId, userId, extra) {
194+
return this.callApi('banChatMember', { chat_id: chatId, user_id: userId, ...extra })
195+
}
196+
189197
kickChatMember (chatId, userId, untilDate) {
190-
return this.callApi('kickChatMember', { chat_id: chatId, user_id: userId, until_date: untilDate })
198+
return this.callApi('banChatMember', { chat_id: chatId, user_id: userId, until_date: untilDate })
191199
}
192200

193201
promoteChatMember (chatId, userId, extra) {
@@ -403,12 +411,16 @@ class Telegram extends ApiClient {
403411
return this.callApi('deleteStickerFromSet', { sticker })
404412
}
405413

406-
getMyCommands () {
407-
return this.callApi('getMyCommands')
414+
getMyCommands (extra) {
415+
return this.callApi('getMyCommands', extra)
416+
}
417+
418+
setMyCommands (commands, extra) {
419+
return this.callApi('setMyCommands', { commands, ...extra })
408420
}
409421

410-
setMyCommands (commands) {
411-
return this.callApi('setMyCommands', { commands })
422+
deleteMyCommands (extra) {
423+
return this.callApi('deleteMyCommands', extra)
412424
}
413425

414426
setPassportDataErrors (userId, errors) {

test/markup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,4 @@ test('should generate correct markup with HTML tags', (t) => {
283283
}
284284
])
285285
t.deepEqual(markup, '&lt;b&gt;<b>bold</b>&lt;/b&gt; &lt;i&gt;<i>italic</i>&lt;/i&gt;')
286-
})
286+
})

typings/context.d.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ export declare class TelegrafContext {
103103
getChatMember(userId: number): Promise<tt.ChatMember>
104104

105105
/**
106-
* Use this method to get the number of members in a chat
106+
* Legasy, see getChatMemberCount
107107
* @returns Number on success
108108
*/
109109
getChatMembersCount(): Promise<number>
110110

111+
/**
112+
* Use this method to get the number of members in a chat
113+
* @returns Number on success
114+
*/
115+
getChatMemberCount(): Promise<number>
116+
111117
/**
112118
* Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user. Returns True on success.
113119
* @param userId Unique identifier of the target user
@@ -571,7 +577,18 @@ export declare class TelegrafContext {
571577
): Promise<tt.MessageLocation | boolean>
572578

573579
/**
574-
* Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights
580+
* Use this method to ban a user in a group, a supergroup or a channel.
581+
* @param userId Unique identifier of the target user
582+
* @param extra Extra params
583+
* @returns True on success
584+
*/
585+
banChatMember(
586+
userId: number,
587+
extra?: tt.ExtraBan
588+
): Promise<boolean>
589+
590+
/**
591+
* Legacy, see banChatMember
575592
* @param userId Unique identifier of the target user
576593
* @param untilDate Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
577594
* @returns True on success
@@ -706,17 +723,34 @@ export declare class TelegrafContext {
706723
): Promise<boolean>
707724

708725
/**
709-
* Use this method to get the current list of the bot's commands. Requires no parameters.
726+
* Use this method to get the current list of the bot's commands for the given scope and user language.
727+
* @param extra Extra parameters for getMyCommands
710728
* @returns Array of BotCommand on success.
711729
*/
712-
getMyCommands(): Promise<tt.BotCommand[]>
730+
getMyCommands(
731+
extra?: tt.ExtraGetMyCommands
732+
): Promise<tt.BotCommand[]>
713733

714734
/**
715735
* Use this method to change the list of the bot's commands.
716736
* @param commands A list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
737+
* @param extra Extra parameters for setMyCommands
738+
* @returns True on success
739+
*/
740+
setMyCommands(
741+
commands: tt.BotCommand[],
742+
extra?: tt.ExtraSetMyCommands
743+
): Promise<boolean>
744+
745+
/**
746+
* Use this method to delete the list of the bot's commands for the given scope and user language.
747+
* After deletion, higher level commands will be shown to affected users.
748+
* @param extra Extra parameters for deleteMyCommands
717749
* @returns True on success
718750
*/
719-
setMyCommands(commands: tt.BotCommand[]): Promise<boolean>
751+
deleteMyCommands(
752+
extra?: tt.ExtraDeleteMyCommands
753+
): Promise<boolean>
720754

721755
/**
722756
* Use this method to create an additional invite link for a chat.

typings/markup.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export declare class Markup<T extends tt.KeyboardMarkupBundle> {
8787

8888
removeKeyboard(value?: boolean): Markup<tt.ReplyKeyboardRemove> & tt.ReplyKeyboardRemove
8989

90+
inputFieldPlaceholder<T extends tt.ReplyKeyboardMarkup | tt.ForceReply>(this: Markup<T> & T, placeholder: string): this
91+
9092
selective<T extends tt.ReplyMarkupBundle>(this: Markup<T> & T, value?: boolean): this
9193

9294
extra<T extends tt.KeyboardMarkupBundle>(this: Markup<T> & T, options?: tt.Extra): tt.ExtraReply<T> & Extra
@@ -140,7 +142,7 @@ export declare class Markup<T extends tt.KeyboardMarkupBundle> {
140142

141143
static removeKeyboard(value?: string): Markup<tt.ReplyKeyboardRemove> & tt.ReplyKeyboardRemove
142144

143-
static forceReply(value?: string): Markup<tt.ForceReply> & tt.ForceReply
145+
static forceReply(value?: boolean): Markup<tt.ForceReply> & tt.ForceReply
144146

145147
static keyboard(
146148
buttons: KeyboardButton[] | KeyboardButton[][],
@@ -154,6 +156,8 @@ export declare class Markup<T extends tt.KeyboardMarkupBundle> {
154156

155157
static resize(value?: boolean): Markup<tt.ReplyKeyboardMarkup>
156158

159+
static inputFieldPlaceholder(placeholder: string): Markup<tt.ReplyKeyboardMarkup | tt.ForceReply>
160+
157161
static selective(value?: boolean): Markup<tt.ReplyMarkupBundle>
158162

159163
static oneTime(value?: boolean): Markup<tt.ReplyKeyboardMarkup>

typings/telegram-types.d.ts

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ export interface ExtraBan {
694694
revoke_messages: boolean
695695
}
696696

697-
export interface ExtraCreateChatIviteLink {
697+
interface ExtraChatIviteLink {
698698
/**
699699
* Point in time (Unix timestamp) when the link will expire
700700
*/
@@ -706,7 +706,10 @@ export interface ExtraCreateChatIviteLink {
706706
member_limit?: number
707707
}
708708

709-
export interface ExtraEditChatIviteLink extends ExtraCreateChatIviteLink {}
709+
710+
export interface ExtraCreateChatIviteLink extends ExtraChatIviteLink {}
711+
712+
export interface ExtraEditChatIviteLink extends ExtraChatIviteLink {}
710713

711714
export type MessageAudio = TT.Message.AudioMessage
712715
export type MessageContact = TT.Message.ContactMessage
@@ -907,6 +910,120 @@ export interface ExtraAnswerInlineQuery {
907910
switch_pm_parameter?: string
908911
}
909912

913+
/**
914+
* Represents the default scope of bot commands.
915+
* Default commands are used if no commands with a narrower scope are specified for the user.
916+
*/
917+
export interface BotCommandScopeDefault {
918+
/**
919+
* Scope type
920+
*/
921+
type: 'default'
922+
}
923+
924+
/**
925+
* Represents the scope of bot commands, covering all private chats.
926+
*/
927+
export interface BotCommandScopeAllPrivateChats {
928+
/**
929+
* Scope type
930+
*/
931+
type: 'all_private_chats'
932+
}
933+
934+
/**
935+
* Represents the scope of bot commands, covering all group and supergroup chats.
936+
*/
937+
export interface BotCommandScopeAllGroupChats {
938+
/**
939+
* Scope type
940+
*/
941+
type: 'all_groups_chats'
942+
}
943+
944+
/**
945+
* Represents the scope of bot commands, covering all group and supergroup chat administrators.
946+
*/
947+
export interface BotCommandScopeAllChatAdministrators {
948+
/**
949+
* Scope type
950+
*/
951+
type: 'all_chat_administrators'
952+
}
953+
954+
/**
955+
* Represents the scope of bot commands, covering a specific chat.
956+
*/
957+
export interface BotCommandScopeChat {
958+
/**
959+
* Scope type
960+
*/
961+
type: 'chat'
962+
}
963+
964+
/**
965+
* Represents the scope of bot commands, covering all administrators of a specific group or supergroup chat.
966+
*/
967+
export interface BotCommandScopeChatAdministrators {
968+
/**
969+
* Scope type
970+
*/
971+
type: 'chat_administrators'
972+
}
973+
974+
/**
975+
* Represents the scope of bot commands, covering a specific member of a group or supergroup chat.
976+
*/
977+
export interface BotCommandScopeChatMember {
978+
/**
979+
* Scope type
980+
*/
981+
type: 'chat_member'
982+
}
983+
984+
/**
985+
* This object represents the scope to which bot commands are applied.
986+
*/
987+
export type BotCommandScope =
988+
BotCommandScopeDefault
989+
| BotCommandScopeAllPrivateChats
990+
| BotCommandScopeAllGroupChats
991+
| BotCommandScopeAllChatAdministrators
992+
| BotCommandScopeChat
993+
| BotCommandScopeChatAdministrators
994+
| BotCommandScopeChatMember
995+
996+
export interface ExtraScope {
997+
/**
998+
* A JSON-serialized object, describing scope of users for which the commands are relevant.
999+
* Defaults to BotCommandScopeDefault.
1000+
*/
1001+
scope?: BotCommandScope
1002+
}
1003+
1004+
export interface ExtraSetMyCommands extends ExtraScope {
1005+
/**
1006+
* A two-letter ISO 639-1 language code.
1007+
* If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
1008+
*/
1009+
language_code?: string
1010+
}
1011+
1012+
export interface ExtraDeleteMyCommands extends ExtraScope {
1013+
/**
1014+
* A two-letter ISO 639-1 language code.
1015+
* If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
1016+
*/
1017+
language_code?: string
1018+
}
1019+
1020+
export interface ExtraGetMyCommands extends ExtraScope {
1021+
/**
1022+
* A two-letter ISO 639-1 language code or an empty string
1023+
*/
1024+
language_code?: string
1025+
}
1026+
9101027
/**
9111028
* This object represents a bot command
9121029
*/

0 commit comments

Comments
 (0)