@tgify/tgify 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +356 -0
- package/filters.d.ts +1 -0
- package/filters.js +1 -0
- package/format.d.ts +1 -0
- package/format.js +1 -0
- package/future.d.ts +1 -0
- package/future.js +1 -0
- package/lib/button.js +100 -0
- package/lib/cli.mjs +105 -0
- package/lib/composer.js +582 -0
- package/lib/context.js +1219 -0
- package/lib/core/helpers/args.js +57 -0
- package/lib/core/helpers/check.js +55 -0
- package/lib/core/helpers/compact.js +16 -0
- package/lib/core/helpers/deunionize.js +12 -0
- package/lib/core/helpers/formatting.js +91 -0
- package/lib/core/helpers/util.js +50 -0
- package/lib/core/network/client.js +330 -0
- package/lib/core/network/error.js +21 -0
- package/lib/core/network/multipart-stream.js +71 -0
- package/lib/core/network/polling.js +87 -0
- package/lib/core/network/webhook.js +54 -0
- package/lib/core/types/typegram.js +27 -0
- package/lib/filters.js +69 -0
- package/lib/format.js +38 -0
- package/lib/future.js +149 -0
- package/lib/index.js +58 -0
- package/lib/input.js +61 -0
- package/lib/markup.js +121 -0
- package/lib/middleware.js +2 -0
- package/lib/reactions.js +84 -0
- package/lib/router.js +46 -0
- package/lib/scenes/base.js +39 -0
- package/lib/scenes/context.js +104 -0
- package/lib/scenes/index.js +21 -0
- package/lib/scenes/stage.js +49 -0
- package/lib/scenes/wizard/context.js +31 -0
- package/lib/scenes/wizard/index.js +45 -0
- package/lib/scenes.js +17 -0
- package/lib/session.js +166 -0
- package/lib/telegraf.js +256 -0
- package/lib/telegram-types.js +6 -0
- package/lib/telegram.js +1240 -0
- package/lib/types.js +2 -0
- package/lib/utils.js +5 -0
- package/markup.d.ts +1 -0
- package/markup.js +1 -0
- package/package.json +140 -0
- package/scenes.d.ts +1 -0
- package/scenes.js +1 -0
- package/session.d.ts +1 -0
- package/session.js +1 -0
- package/src/button.ts +182 -0
- package/src/composer.ts +1008 -0
- package/src/context.ts +1661 -0
- package/src/core/helpers/args.ts +63 -0
- package/src/core/helpers/check.ts +71 -0
- package/src/core/helpers/compact.ts +18 -0
- package/src/core/helpers/deunionize.ts +26 -0
- package/src/core/helpers/formatting.ts +119 -0
- package/src/core/helpers/util.ts +96 -0
- package/src/core/network/client.ts +396 -0
- package/src/core/network/error.ts +29 -0
- package/src/core/network/multipart-stream.ts +45 -0
- package/src/core/network/polling.ts +94 -0
- package/src/core/network/webhook.ts +58 -0
- package/src/core/types/typegram.ts +54 -0
- package/src/filters.ts +109 -0
- package/src/format.ts +110 -0
- package/src/future.ts +213 -0
- package/src/index.ts +17 -0
- package/src/input.ts +59 -0
- package/src/markup.ts +142 -0
- package/src/middleware.ts +24 -0
- package/src/reactions.ts +118 -0
- package/src/router.ts +55 -0
- package/src/scenes/base.ts +52 -0
- package/src/scenes/context.ts +136 -0
- package/src/scenes/index.ts +21 -0
- package/src/scenes/stage.ts +71 -0
- package/src/scenes/wizard/context.ts +58 -0
- package/src/scenes/wizard/index.ts +63 -0
- package/src/scenes.ts +1 -0
- package/src/session.ts +204 -0
- package/src/telegraf.ts +354 -0
- package/src/telegram-types.ts +219 -0
- package/src/telegram.ts +1635 -0
- package/src/types.ts +2 -0
- package/src/utils.ts +1 -0
- package/types.d.ts +1 -0
- package/types.js +1 -0
- package/typings/button.d.ts +36 -0
- package/typings/button.d.ts.map +1 -0
- package/typings/composer.d.ts +227 -0
- package/typings/composer.d.ts.map +1 -0
- package/typings/context.d.ts +655 -0
- package/typings/context.d.ts.map +1 -0
- package/typings/core/helpers/args.d.ts +11 -0
- package/typings/core/helpers/args.d.ts.map +1 -0
- package/typings/core/helpers/check.d.ts +56 -0
- package/typings/core/helpers/check.d.ts.map +1 -0
- package/typings/core/helpers/compact.d.ts +4 -0
- package/typings/core/helpers/compact.d.ts.map +1 -0
- package/typings/core/helpers/deunionize.d.ts +18 -0
- package/typings/core/helpers/deunionize.d.ts.map +1 -0
- package/typings/core/helpers/formatting.d.ts +30 -0
- package/typings/core/helpers/formatting.d.ts.map +1 -0
- package/typings/core/helpers/util.d.ts +26 -0
- package/typings/core/helpers/util.d.ts.map +1 -0
- package/typings/core/network/client.d.ts +53 -0
- package/typings/core/network/client.d.ts.map +1 -0
- package/typings/core/network/error.d.ts +16 -0
- package/typings/core/network/error.d.ts.map +1 -0
- package/typings/core/network/multipart-stream.d.ts +16 -0
- package/typings/core/network/multipart-stream.d.ts.map +1 -0
- package/typings/core/network/polling.d.ts +16 -0
- package/typings/core/network/polling.d.ts.map +1 -0
- package/typings/core/network/webhook.d.ts +6 -0
- package/typings/core/network/webhook.d.ts.map +1 -0
- package/typings/core/types/typegram.d.ts +42 -0
- package/typings/core/types/typegram.d.ts.map +1 -0
- package/typings/filters.d.ts +18 -0
- package/typings/filters.d.ts.map +1 -0
- package/typings/format.d.ts +22 -0
- package/typings/format.d.ts.map +1 -0
- package/typings/future.d.ts +12 -0
- package/typings/future.d.ts.map +1 -0
- package/typings/index.d.ts +15 -0
- package/typings/index.d.ts.map +1 -0
- package/typings/input.d.ts +50 -0
- package/typings/input.d.ts.map +1 -0
- package/typings/markup.d.ts +27 -0
- package/typings/markup.d.ts.map +1 -0
- package/typings/middleware.d.ts +8 -0
- package/typings/middleware.d.ts.map +1 -0
- package/typings/reactions.d.ts +32 -0
- package/typings/reactions.d.ts.map +1 -0
- package/typings/router.d.ts +21 -0
- package/typings/router.d.ts.map +1 -0
- package/typings/scenes/base.d.ts +22 -0
- package/typings/scenes/base.d.ts.map +1 -0
- package/typings/scenes/context.d.ts +36 -0
- package/typings/scenes/context.d.ts.map +1 -0
- package/typings/scenes/index.d.ts +11 -0
- package/typings/scenes/index.d.ts.map +1 -0
- package/typings/scenes/stage.d.ts +24 -0
- package/typings/scenes/stage.d.ts.map +1 -0
- package/typings/scenes/wizard/context.d.ts +29 -0
- package/typings/scenes/wizard/context.d.ts.map +1 -0
- package/typings/scenes/wizard/index.d.ts +16 -0
- package/typings/scenes/wizard/index.d.ts.map +1 -0
- package/typings/scenes.d.ts +2 -0
- package/typings/scenes.d.ts.map +1 -0
- package/typings/session.d.ts +55 -0
- package/typings/session.d.ts.map +1 -0
- package/typings/telegraf.d.ts +115 -0
- package/typings/telegraf.d.ts.map +1 -0
- package/typings/telegram-types.d.ts +117 -0
- package/typings/telegram-types.d.ts.map +1 -0
- package/typings/telegram.d.ts +675 -0
- package/typings/telegram.d.ts.map +1 -0
- package/typings/types.d.ts +3 -0
- package/typings/types.d.ts.map +1 -0
- package/typings/utils.d.ts +2 -0
- package/typings/utils.d.ts.map +1 -0
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import { Expand } from './core/helpers/util'
|
|
4
|
+
import {
|
|
5
|
+
Message,
|
|
6
|
+
Opts,
|
|
7
|
+
Telegram,
|
|
8
|
+
Update,
|
|
9
|
+
InputMediaAudio,
|
|
10
|
+
InputMediaDocument,
|
|
11
|
+
InputMediaPhoto,
|
|
12
|
+
InputMediaVideo,
|
|
13
|
+
} from './core/types/typegram'
|
|
14
|
+
|
|
15
|
+
import { UnionKeys } from './core/helpers/deunionize'
|
|
16
|
+
import { FmtString } from './format'
|
|
17
|
+
|
|
18
|
+
export { Markup } from './markup'
|
|
19
|
+
|
|
20
|
+
// tiny helper types
|
|
21
|
+
export type ChatAction = Opts<'sendChatAction'>['action']
|
|
22
|
+
|
|
23
|
+
// Modify type so caption, if exists, can be FmtString
|
|
24
|
+
export type WrapCaption<T> = T extends { caption?: string }
|
|
25
|
+
? Expand<Omit<T, 'caption'> & { caption?: string | FmtString }>
|
|
26
|
+
: T
|
|
27
|
+
|
|
28
|
+
// extra types
|
|
29
|
+
/**
|
|
30
|
+
* Create an `Extra*` type from the arguments of a given method `M extends keyof Telegram` but `Omit`ting fields with key `K` from it.
|
|
31
|
+
*
|
|
32
|
+
* Note that `chat_id` may not be specified in `K` because it is `Omit`ted by default.
|
|
33
|
+
*/
|
|
34
|
+
type MakeExtra<
|
|
35
|
+
M extends keyof Telegram,
|
|
36
|
+
K extends keyof Omit<Opts<M>, 'chat_id'> = never,
|
|
37
|
+
> = WrapCaption<Omit<Opts<M>, 'chat_id' | K>>
|
|
38
|
+
|
|
39
|
+
export type ExtraAddStickerToSet = MakeExtra<
|
|
40
|
+
'addStickerToSet',
|
|
41
|
+
'name' | 'user_id'
|
|
42
|
+
>
|
|
43
|
+
export type ExtraAnimation = MakeExtra<'sendAnimation', 'animation'>
|
|
44
|
+
export type ExtraAnswerCbQuery = MakeExtra<
|
|
45
|
+
'answerCallbackQuery',
|
|
46
|
+
'text' | 'callback_query_id'
|
|
47
|
+
>
|
|
48
|
+
export type ExtraAnswerInlineQuery = MakeExtra<
|
|
49
|
+
'answerInlineQuery',
|
|
50
|
+
'inline_query_id' | 'results'
|
|
51
|
+
>
|
|
52
|
+
export type ExtraSetChatPermissions = MakeExtra<
|
|
53
|
+
'setChatPermissions',
|
|
54
|
+
'permissions'
|
|
55
|
+
>
|
|
56
|
+
export type ExtraAudio = MakeExtra<'sendAudio', 'audio'>
|
|
57
|
+
export type ExtraContact = MakeExtra<
|
|
58
|
+
'sendContact',
|
|
59
|
+
'phone_number' | 'first_name'
|
|
60
|
+
>
|
|
61
|
+
export type ExtraCopyMessage = MakeExtra<
|
|
62
|
+
'copyMessage',
|
|
63
|
+
'from_chat_id' | 'message_id'
|
|
64
|
+
>
|
|
65
|
+
export type ExtraCopyMessages = MakeExtra<
|
|
66
|
+
'copyMessages',
|
|
67
|
+
'from_chat_id' | 'message_ids'
|
|
68
|
+
>
|
|
69
|
+
export type ExtraCreateChatInviteLink = MakeExtra<'createChatInviteLink'>
|
|
70
|
+
export type NewInvoiceLinkParameters = MakeExtra<'createInvoiceLink'>
|
|
71
|
+
export type ExtraCreateNewStickerSet = MakeExtra<
|
|
72
|
+
'createNewStickerSet',
|
|
73
|
+
'name' | 'title' | 'user_id'
|
|
74
|
+
>
|
|
75
|
+
export type ExtraDice = MakeExtra<'sendDice'>
|
|
76
|
+
export type ExtraDocument = MakeExtra<'sendDocument', 'document'>
|
|
77
|
+
export type ExtraEditChatInviteLink = MakeExtra<
|
|
78
|
+
'editChatInviteLink',
|
|
79
|
+
'invite_link'
|
|
80
|
+
>
|
|
81
|
+
export type ExtraEditMessageCaption = MakeExtra<
|
|
82
|
+
'editMessageCaption',
|
|
83
|
+
'message_id' | 'inline_message_id' | 'caption'
|
|
84
|
+
>
|
|
85
|
+
export type ExtraEditMessageLiveLocation = MakeExtra<
|
|
86
|
+
'editMessageLiveLocation',
|
|
87
|
+
'message_id' | 'inline_message_id' | 'latitude' | 'longitude'
|
|
88
|
+
>
|
|
89
|
+
export type ExtraEditMessageMedia = MakeExtra<
|
|
90
|
+
'editMessageMedia',
|
|
91
|
+
'message_id' | 'inline_message_id' | 'media'
|
|
92
|
+
>
|
|
93
|
+
export type ExtraEditMessageText = MakeExtra<
|
|
94
|
+
'editMessageText',
|
|
95
|
+
'message_id' | 'inline_message_id' | 'text'
|
|
96
|
+
>
|
|
97
|
+
export type ExtraGame = MakeExtra<'sendGame', 'game_short_name'>
|
|
98
|
+
export type NewInvoiceParameters = MakeExtra<
|
|
99
|
+
'sendInvoice',
|
|
100
|
+
| 'disable_notification'
|
|
101
|
+
| 'reply_parameters'
|
|
102
|
+
| 'reply_markup'
|
|
103
|
+
| 'message_thread_id'
|
|
104
|
+
>
|
|
105
|
+
export type ExtraInvoice = MakeExtra<'sendInvoice', keyof NewInvoiceParameters>
|
|
106
|
+
export type ExtraBanChatMember = MakeExtra<
|
|
107
|
+
'banChatMember',
|
|
108
|
+
'user_id' | 'until_date'
|
|
109
|
+
>
|
|
110
|
+
export type ExtraKickChatMember = ExtraBanChatMember
|
|
111
|
+
export type ExtraLocation = MakeExtra<'sendLocation', 'latitude' | 'longitude'>
|
|
112
|
+
export type ExtraMediaGroup = MakeExtra<'sendMediaGroup', 'media'>
|
|
113
|
+
export type ExtraPhoto = MakeExtra<'sendPhoto', 'photo'>
|
|
114
|
+
export type ExtraPoll = MakeExtra<'sendPoll', 'question' | 'options' | 'type'>
|
|
115
|
+
export type ExtraPromoteChatMember = MakeExtra<'promoteChatMember', 'user_id'>
|
|
116
|
+
export type ExtraReplyMessage = MakeExtra<'sendMessage', 'text'>
|
|
117
|
+
export type ExtraForwardMessage = MakeExtra<
|
|
118
|
+
'forwardMessage',
|
|
119
|
+
'from_chat_id' | 'message_id'
|
|
120
|
+
>
|
|
121
|
+
export type ExtraForwardMessages = MakeExtra<
|
|
122
|
+
'forwardMessages',
|
|
123
|
+
'from_chat_id' | 'message_ids'
|
|
124
|
+
>
|
|
125
|
+
export type ExtraSendChatAction = MakeExtra<'sendChatAction', 'action'>
|
|
126
|
+
export type ExtraRestrictChatMember = MakeExtra<'restrictChatMember', 'user_id'>
|
|
127
|
+
export type ExtraSetMyCommands = MakeExtra<'setMyCommands', 'commands'>
|
|
128
|
+
export type ExtraSetWebhook = MakeExtra<'setWebhook', 'url'>
|
|
129
|
+
export type ExtraSticker = MakeExtra<'sendSticker', 'sticker'>
|
|
130
|
+
export type ExtraStopPoll = MakeExtra<'stopPoll', 'message_id'>
|
|
131
|
+
export type ExtraVenue = MakeExtra<
|
|
132
|
+
'sendVenue',
|
|
133
|
+
'latitude' | 'longitude' | 'title' | 'address'
|
|
134
|
+
>
|
|
135
|
+
export type ExtraVideo = MakeExtra<'sendVideo', 'video'>
|
|
136
|
+
export type ExtraVideoNote = MakeExtra<'sendVideoNote', 'video_note'>
|
|
137
|
+
export type ExtraVoice = MakeExtra<'sendVoice', 'voice'>
|
|
138
|
+
export type ExtraBanChatSenderChat = MakeExtra<
|
|
139
|
+
'banChatSenderChat',
|
|
140
|
+
'sender_chat_id'
|
|
141
|
+
>
|
|
142
|
+
export type ExtraCreateForumTopic = MakeExtra<'createForumTopic', 'name'>
|
|
143
|
+
export type ExtraEditForumTopic = MakeExtra<
|
|
144
|
+
'editForumTopic',
|
|
145
|
+
'message_thread_id'
|
|
146
|
+
>
|
|
147
|
+
|
|
148
|
+
export type MediaGroup =
|
|
149
|
+
| readonly (InputMediaPhoto | InputMediaVideo)[]
|
|
150
|
+
| readonly InputMediaAudio[]
|
|
151
|
+
| readonly InputMediaDocument[]
|
|
152
|
+
|
|
153
|
+
// types used for inference of ctx object
|
|
154
|
+
|
|
155
|
+
/** Possible update types */
|
|
156
|
+
export type UpdateType = Exclude<UnionKeys<Update>, keyof Update>
|
|
157
|
+
|
|
158
|
+
/** Possible message subtypes. Same as the properties on a message object */
|
|
159
|
+
export type MessageSubType =
|
|
160
|
+
| 'forward_date'
|
|
161
|
+
| Exclude<
|
|
162
|
+
UnionKeys<Message>,
|
|
163
|
+
keyof Message.CaptionableMessage | 'entities' | 'media_group_id'
|
|
164
|
+
>
|
|
165
|
+
|
|
166
|
+
type ExtractPartial<T extends object, U extends object> = T extends unknown
|
|
167
|
+
? Required<T> extends U
|
|
168
|
+
? T
|
|
169
|
+
: never
|
|
170
|
+
: never
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Maps [[`Composer.on`]]'s `updateType` or `messageSubType` to a `tt.Update` subtype.
|
|
174
|
+
* @deprecated
|
|
175
|
+
*/
|
|
176
|
+
export type MountMap = {
|
|
177
|
+
[T in UpdateType]: Extract<Update, Record<T, object>>
|
|
178
|
+
} & {
|
|
179
|
+
[T in MessageSubType]: {
|
|
180
|
+
message: ExtractPartial<Update.MessageUpdate['message'], Record<T, unknown>>
|
|
181
|
+
update_id: number
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface CommandContextExtn {
|
|
186
|
+
match: RegExpExecArray
|
|
187
|
+
/**
|
|
188
|
+
* Matched command. This will always be the actual command, excluding preceeding slash and `@botname`
|
|
189
|
+
*
|
|
190
|
+
* Examples:
|
|
191
|
+
* ```
|
|
192
|
+
* /command abc -> command
|
|
193
|
+
* /command@xyzbot abc -> command
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
command: string
|
|
197
|
+
/**
|
|
198
|
+
* The unparsed payload part of the command
|
|
199
|
+
*
|
|
200
|
+
* Examples:
|
|
201
|
+
* ```
|
|
202
|
+
* /command abc def -> "abc def"
|
|
203
|
+
* /command "token1 token2" -> "\"token1 token2\""
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
payload: string
|
|
207
|
+
/**
|
|
208
|
+
* Command args parsed into an array.
|
|
209
|
+
*
|
|
210
|
+
* Examples:
|
|
211
|
+
* ```
|
|
212
|
+
* /command token1 token2 -> [ "token1", "token2" ]
|
|
213
|
+
* /command "token1 token2" -> [ "token1 token2" ]
|
|
214
|
+
* /command token1 "token2 token3" -> [ "token1" "token2 token3" ]
|
|
215
|
+
* ```
|
|
216
|
+
* @unstable Parser implementation might vary until considered stable
|
|
217
|
+
* */
|
|
218
|
+
args: string[]
|
|
219
|
+
}
|