Skip to content

Commit aa97d11

Browse files
committed
Update to bot API 5.1
1 parent b96edef commit aa97d11

6 files changed

Lines changed: 177 additions & 8 deletions

File tree

context.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const UpdateTypes = [
99
'pre_checkout_query',
1010
'message',
1111
'poll',
12-
'poll_answer'
12+
'poll_answer',
13+
'my_chat_member',
14+
'chat_member'
1315
]
1416

1517
const MessageSubTypes = [
@@ -43,7 +45,11 @@ const MessageSubTypes = [
4345
'connected_website',
4446
'passport_data',
4547
'poll',
46-
'forward_date'
48+
'forward_date',
49+
'message_auto_delete_timer_changed',
50+
'voice_chat_started',
51+
'voice_chat_ended',
52+
'voice_chat_participants_invited'
4753
]
4854

4955
const MessageSubTypesMapping = {
@@ -120,12 +126,22 @@ class TelegrafContext {
120126
return this.update.poll_answer
121127
}
122128

129+
get myChatMember () {
130+
return this.update.my_chat_member
131+
}
132+
133+
get chatMember () {
134+
return this.update.chat_member
135+
}
136+
123137
get chat () {
124138
return (this.message && this.message.chat) ||
125139
(this.editedMessage && this.editedMessage.chat) ||
126140
(this.callbackQuery && this.callbackQuery.message && this.callbackQuery.message.chat) ||
127141
(this.channelPost && this.channelPost.chat) ||
128-
(this.editedChannelPost && this.editedChannelPost.chat)
142+
(this.editedChannelPost && this.editedChannelPost.chat) ||
143+
(this.myChatMember && this.myChatMember.chat) ||
144+
(this.chatMember && this.chatMember.chat)
129145
}
130146

131147
get from () {
@@ -137,7 +153,9 @@ class TelegrafContext {
137153
(this.editedChannelPost && this.editedChannelPost.from) ||
138154
(this.shippingQuery && this.shippingQuery.from) ||
139155
(this.preCheckoutQuery && this.preCheckoutQuery.from) ||
140-
(this.chosenInlineResult && this.chosenInlineResult.from)
156+
(this.chosenInlineResult && this.chosenInlineResult.from) ||
157+
(this.myChatMember && this.myChatMember.from) ||
158+
(this.chatMember && this.chatMember.from)
141159
}
142160

143161
get inlineMessageId () {
@@ -605,6 +623,21 @@ class TelegrafContext {
605623
this.assert(message, 'copyMessage')
606624
return this.telegram.copyMessage(chatId, message.chat.id, message.message_id, extra)
607625
}
626+
627+
createChatInviteLink (...args) {
628+
this.assert(this.chat, 'createChatInviteLink')
629+
return this.telegram.createChatInviteLink(this.chat.id, ...args)
630+
}
631+
632+
editChatInviteLink (...args) {
633+
this.assert(this.chat, 'editChatInviteLink')
634+
return this.telegram.editChatInviteLink(this.chat.id, ...args)
635+
}
636+
637+
revokeChatInviteLink (...args) {
638+
this.assert(this.chat, 'revokeChatInviteLink')
639+
return this.telegram.revokeChatInviteLink(this.chat.id, ...args)
640+
}
608641
}
609642

610643
module.exports = TelegrafContext

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"module-alias": "^2.2.2",
4141
"node-fetch": "^2.2.0",
4242
"sandwich-stream": "^2.0.1",
43-
"typegram": "^3.1.5"
43+
"typegram": "^3.4.3"
4444
},
4545
"devDependencies": {
4646
"@types/node": "^13.1.0",

telegram.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,28 @@ class Telegram extends ApiClient {
445445
...extra
446446
})
447447
}
448+
449+
createChatInviteLink (chatId, extra) {
450+
return this.callApi('createChatInviteLink', {
451+
chat_id: chatId,
452+
...extra
453+
})
454+
}
455+
456+
editChatInviteLink (chatId, inviteLink, extra) {
457+
return this.callApi('editChatInviteLink', {
458+
chat_id: chatId,
459+
invite_link: inviteLink,
460+
...extra
461+
})
462+
}
463+
464+
revokeChatInviteLink (chatId, inviteLink) {
465+
return this.callApi('revokeChatInviteLink', {
466+
chat_id: chatId,
467+
invite_link: inviteLink
468+
})
469+
}
448470
}
449471

450472
module.exports = Telegram

typings/context.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,4 +717,33 @@ export declare class TelegrafContext {
717717
* @returns True on success
718718
*/
719719
setMyCommands(commands: tt.BotCommand[]): Promise<boolean>
720+
721+
/**
722+
* Use this method to create an additional invite link for a chat.
723+
* @param extra Extra parameters for createChatInviteLink
724+
* @returns the new invite link as ChatInviteLink object
725+
*/
726+
createChatInviteLink(
727+
extra?: tt.ExtraCreateChatIviteLink
728+
): Promise<tt.ChatInviteLink>
729+
730+
/**
731+
* Use this method to edit a non-primary invite link created by the bot.
732+
* @param inviteLink The invite link to edit
733+
* @param extra Extra parameters for editChatInviteLink
734+
* @returns the edited invite link as a ChatInviteLink object
735+
*/
736+
editChatInviteLink(
737+
inviteLink: string,
738+
extra?: tt.ExtraEditChatIviteLink
739+
): Promise<tt.ChatInviteLink>
740+
741+
/**
742+
* Use this method to revoke an invite link created by the bot.
743+
* @param inviteLink The invite link to revoke
744+
* @returns the revoked invite link as a ChatInviteLink object
745+
*/
746+
revokeChatInviteLink(
747+
inviteLink: string
748+
): Promise<tt.ChatInviteLink>
720749
}

typings/telegram-types.d.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export type UpdateType =
3434
'pre_checkout_query' |
3535
'shipping_query' |
3636
'poll' |
37-
'poll_answer'
37+
'poll_answer' |
38+
'my_chat_member' |
39+
'chat_member'
3840

3941
export type MessageSubTypes =
4042
'voice' |
@@ -67,7 +69,11 @@ export type MessageSubTypes =
6769
'connected_website' |
6870
'passport_data' |
6971
'poll' |
70-
'forward'
72+
'forward' |
73+
'message_auto_delete_timer_changed' |
74+
'voice_chat_started' |
75+
'voice_chat_ended' |
76+
'voice_chat_participants_invited'
7177

7278
export type InputMediaTypes =
7379
'photo'
@@ -83,6 +89,7 @@ export type ChatMemberStatus =
8389
| 'restricted'
8490
| 'left'
8591
| 'kicked'
92+
8693
export type MessageEntityType =
8794
'mention'
8895
| 'hashtag'
@@ -276,6 +283,9 @@ export interface ExtraPromoteChatMember {
276283
/** Pass True, if the administrator can delete messages of other users */
277284
can_delete_messages?: boolean
278285

286+
/** Pass True, if the administrator can manage voice chats */
287+
can_manage_voice_chats?: boolean,
288+
279289
/** Pass True, if the administrator can invite new users to the chat */
280290
can_invite_users?: boolean
281291

@@ -661,10 +671,42 @@ export type Extra = ExtraSendMessage
661671
| ExtraCopyMessage
662672

663673
export interface ExtraUnban {
664-
/** Do nothing if the user is not banned */
674+
/**
675+
* Do nothing if the user is not banned
676+
*/
665677
only_if_banned?: Boolean
666678
}
667679

680+
export interface ExtraBan {
681+
/**
682+
* Date when the user will be unbanned, unix time.
683+
* 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.
684+
* Applied for supergroups and channels only.
685+
*/
686+
until_date?: number,
687+
688+
/**
689+
* Pass True to delete all messages from the chat for the user that is being removed.
690+
* If False, the user will be able to see messages in the group that were sent before the user was removed.
691+
* Always True for supergroups and channels.
692+
*/
693+
revoke_messages: boolean
694+
}
695+
696+
export interface ExtraCreateChatIviteLink {
697+
/**
698+
* Point in time (Unix timestamp) when the link will expire
699+
*/
700+
expire_date?: number,
701+
702+
/**
703+
* Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
704+
*/
705+
member_limit?: number
706+
}
707+
708+
export interface ExtraEditChatIviteLink extends ExtraCreateChatIviteLink {}
709+
668710
export type MessageAudio = TT.Message.AudioMessage
669711
export type MessageContact = TT.Message.ContactMessage
670712
export type MessageDocument = TT.Message.DocumentMessage
@@ -697,6 +739,10 @@ type ServiceMessageBundle = TT.Message.ChannelChatCreatedMessage
697739
& TT.Message.PinnedMessageMessage
698740
& TT.Message.SuccessfulPaymentMessage
699741
& TT.Message.SupergroupChatCreated
742+
& TT.Message.MessageAutoDeleteTimerChangedMessage
743+
& TT.Message.VoiceChatStartedMessage
744+
& TT.Message.VoiceChatEndedMessage
745+
& TT.Message.VoiceChatEndedMessage
700746

701747
type CommonMessageBundle = TT.Message.AnimationMessage
702748
& TT.Message.AudioMessage
@@ -727,6 +773,8 @@ export type Update = TT.Update.CallbackQueryUpdate
727773
& TT.Update.PollAnswerUpdate
728774
& TT.Update.PollUpdate
729775
& TT.Update.ShippingQueryUpdate
776+
& TT.Update.MyChatMemberUpdate
777+
& TT.Update.ChatMemberUpdate
730778

731779
export interface CallbackQuery extends TT.CallbackQuery.DataCallbackQuery, TT.CallbackQuery.GameShortGameCallbackQuery {
732780
message: Message
@@ -855,3 +903,5 @@ export interface BotCommand {
855903
*/
856904
description: string
857905
}
906+
907+
export type ChatInviteLink = TT.ChatInviteLink

typings/telegram.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,4 +962,39 @@ export declare class Telegram extends ApiClient {
962962
messageId: number,
963963
extra?: tt.ExtraCopyMessage
964964
): Promise<tt.MessageId>
965+
966+
/**
967+
* Use this method to create an additional invite link for a chat.
968+
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
969+
* @param extra Extra parameters for createChatInviteLink
970+
* @returns the new invite link as ChatInviteLink object
971+
*/
972+
createChatInviteLink(
973+
chatId: number | string,
974+
extra?: tt.ExtraCreateChatIviteLink
975+
): Promise<tt.ChatInviteLink>
976+
977+
/**
978+
* Use this method to edit a non-primary invite link created by the bot.
979+
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
980+
* @param inviteLink The invite link to edit
981+
* @param extra Extra parameters for editChatInviteLink
982+
* @returns the edited invite link as a ChatInviteLink object
983+
*/
984+
editChatInviteLink(
985+
chatId: number | string,
986+
inviteLink: string,
987+
extra?: tt.ExtraEditChatIviteLink
988+
): Promise<tt.ChatInviteLink>
989+
990+
/**
991+
* Use this method to revoke an invite link created by the bot.
992+
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
993+
* @param inviteLink The invite link to revoke
994+
* @returns the revoked invite link as a ChatInviteLink object
995+
*/
996+
revokeChatInviteLink(
997+
chatId: number | string,
998+
inviteLink: string
999+
): Promise<tt.ChatInviteLink>
9651000
}

0 commit comments

Comments
 (0)