@tgify/tgify 0.1.0 → 0.1.4

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.
Files changed (42) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +356 -356
  3. package/lib/cli.mjs +9 -9
  4. package/package.json +1 -1
  5. package/src/button.ts +182 -182
  6. package/src/composer.ts +1008 -1008
  7. package/src/context.ts +1661 -1661
  8. package/src/core/helpers/args.ts +63 -63
  9. package/src/core/helpers/check.ts +71 -71
  10. package/src/core/helpers/compact.ts +18 -18
  11. package/src/core/helpers/deunionize.ts +26 -26
  12. package/src/core/helpers/formatting.ts +119 -119
  13. package/src/core/helpers/util.ts +96 -96
  14. package/src/core/network/client.ts +396 -396
  15. package/src/core/network/error.ts +29 -29
  16. package/src/core/network/multipart-stream.ts +45 -45
  17. package/src/core/network/polling.ts +94 -94
  18. package/src/core/network/webhook.ts +58 -58
  19. package/src/core/types/typegram.ts +54 -54
  20. package/src/filters.ts +109 -109
  21. package/src/format.ts +110 -110
  22. package/src/future.ts +213 -213
  23. package/src/index.ts +17 -17
  24. package/src/input.ts +59 -59
  25. package/src/markup.ts +142 -142
  26. package/src/middleware.ts +24 -24
  27. package/src/reactions.ts +118 -118
  28. package/src/router.ts +55 -55
  29. package/src/scenes/base.ts +52 -52
  30. package/src/scenes/context.ts +136 -136
  31. package/src/scenes/index.ts +21 -21
  32. package/src/scenes/stage.ts +71 -71
  33. package/src/scenes/wizard/context.ts +58 -58
  34. package/src/scenes/wizard/index.ts +63 -63
  35. package/src/scenes.ts +1 -1
  36. package/src/session.ts +204 -204
  37. package/src/telegraf.ts +354 -354
  38. package/src/telegram-types.ts +219 -219
  39. package/src/telegram.ts +1635 -1635
  40. package/src/types.ts +2 -2
  41. package/src/utils.ts +1 -1
  42. package/typings/telegraf.d.ts.map +1 -1
package/lib/cli.mjs CHANGED
@@ -4,15 +4,15 @@ import parse from 'mri';
4
4
  import path from 'path';
5
5
  import { Telegraf } from './index.js';
6
6
  const debug = d('telegraf:cli');
7
- const helpMsg = `Usage: telegraf [opts] <bot-file>
8
-
9
- -t Bot token [$BOT_TOKEN]
10
- -d Webhook domain [$BOT_DOMAIN]
11
- -H Webhook host [0.0.0.0]
12
- -p Webhook port [$PORT or 3000]
13
- -l Enable logs
14
- -h Show this help message
15
- -m Bot API method to run directly
7
+ const helpMsg = `Usage: telegraf [opts] <bot-file>
8
+
9
+ -t Bot token [$BOT_TOKEN]
10
+ -d Webhook domain [$BOT_DOMAIN]
11
+ -H Webhook host [0.0.0.0]
12
+ -p Webhook port [$PORT or 3000]
13
+ -l Enable logs
14
+ -h Show this help message
15
+ -m Bot API method to run directly
16
16
  -D Data to pass to the Bot API method`;
17
17
  const help = () => console.log(helpMsg);
18
18
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tgify/tgify",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "description": "Modern Telegram Bot Framework",
5
5
  "license": "MIT",
6
6
  "author": "IATNAOD",
package/src/button.ts CHANGED
@@ -1,182 +1,182 @@
1
- import {
2
- InlineKeyboardButton,
3
- KeyboardButton,
4
- KeyboardButtonRequestChat,
5
- KeyboardButtonRequestUsers,
6
- } from './core/types/typegram'
7
-
8
- type Hideable<B> = B & { hide: boolean }
9
-
10
- export function text(
11
- text: string,
12
- hide = false
13
- ): Hideable<KeyboardButton.CommonButton> {
14
- return { text, hide }
15
- }
16
-
17
- export function contactRequest(
18
- text: string,
19
- hide = false
20
- ): Hideable<KeyboardButton.RequestContactButton> {
21
- return { text, request_contact: true, hide }
22
- }
23
-
24
- export function locationRequest(
25
- text: string,
26
- hide = false
27
- ): Hideable<KeyboardButton.RequestLocationButton> {
28
- return { text, request_location: true, hide }
29
- }
30
-
31
- export function pollRequest(
32
- text: string,
33
- type?: 'quiz' | 'regular',
34
- hide = false
35
- ): Hideable<KeyboardButton.RequestPollButton> {
36
- return { text, request_poll: { type }, hide }
37
- }
38
-
39
- export function userRequest(
40
- text: string,
41
- /** Must fit in a signed 32 bit int */
42
- request_id: number,
43
- extra?: Omit<KeyboardButtonRequestUsers, 'request_id' | 'text'>,
44
- hide = false
45
- ): Hideable<KeyboardButton.RequestUsersButton> {
46
- return {
47
- text,
48
- request_users: { request_id, ...extra },
49
- hide,
50
- }
51
- }
52
-
53
- export function botRequest(
54
- text: string,
55
- /** Must fit in a signed 32 bit int */
56
- request_id: number,
57
- extra?: Omit<
58
- KeyboardButtonRequestUsers,
59
- 'request_id' | 'user_is_bot' | 'text'
60
- >,
61
- hide = false
62
- ): Hideable<KeyboardButton.RequestUsersButton> {
63
- return {
64
- text,
65
- request_users: { request_id, user_is_bot: true, ...extra },
66
- hide,
67
- }
68
- }
69
-
70
- type KeyboardButtonRequestGroup = Omit<
71
- KeyboardButtonRequestChat,
72
- 'request_id' | 'chat_is_channel'
73
- >
74
-
75
- export function groupRequest(
76
- text: string,
77
- /** Must fit in a signed 32 bit int */
78
- request_id: number,
79
- extra?: KeyboardButtonRequestGroup,
80
- hide = false
81
- ): Hideable<KeyboardButton.RequestChatButton> {
82
- return {
83
- text,
84
- request_chat: { request_id, chat_is_channel: false, ...extra },
85
- hide,
86
- }
87
- }
88
-
89
- type KeyboardButtonRequestChannel = Omit<
90
- KeyboardButtonRequestChat,
91
- 'request_id' | 'chat_is_channel' | 'chat_is_forum'
92
- >
93
-
94
- export function channelRequest(
95
- text: string,
96
- /** Must fit in a signed 32 bit int */
97
- request_id: number,
98
- extra?: KeyboardButtonRequestChannel,
99
- hide = false
100
- ): Hideable<KeyboardButton.RequestChatButton> {
101
- return {
102
- text,
103
- request_chat: { request_id, chat_is_channel: true, ...extra },
104
- hide,
105
- }
106
- }
107
-
108
- export function url(
109
- text: string,
110
- url: string,
111
- hide = false
112
- ): Hideable<InlineKeyboardButton.UrlButton> {
113
- return { text, url, hide }
114
- }
115
-
116
- export function callback(
117
- text: string,
118
- data: string,
119
- hide = false
120
- ): Hideable<InlineKeyboardButton.CallbackButton> {
121
- return { text, callback_data: data, hide }
122
- }
123
-
124
- export function switchToChat(
125
- text: string,
126
- value: string,
127
- hide = false
128
- ): Hideable<InlineKeyboardButton.SwitchInlineButton> {
129
- return { text, switch_inline_query: value, hide }
130
- }
131
-
132
- export function switchToCurrentChat(
133
- text: string,
134
- value: string,
135
- hide = false
136
- ): Hideable<InlineKeyboardButton.SwitchInlineCurrentChatButton> {
137
- return { text, switch_inline_query_current_chat: value, hide }
138
- }
139
-
140
- export function game(
141
- text: string,
142
- hide = false
143
- ): Hideable<InlineKeyboardButton.GameButton> {
144
- return { text, callback_game: {}, hide }
145
- }
146
-
147
- export function pay(
148
- text: string,
149
- hide = false
150
- ): Hideable<InlineKeyboardButton.PayButton> {
151
- return { text, pay: true, hide }
152
- }
153
-
154
- export function login(
155
- text: string,
156
- url: string,
157
- opts: {
158
- forward_text?: string
159
- bot_username?: string
160
- request_write_access?: boolean
161
- } = {},
162
- hide = false
163
- ): Hideable<InlineKeyboardButton.LoginButton> {
164
- return {
165
- text,
166
- login_url: { ...opts, url },
167
- hide,
168
- }
169
- }
170
-
171
- export function webApp(
172
- text: string,
173
- url: string,
174
- hide = false
175
- // works as both InlineKeyboardButton and KeyboardButton
176
- ): Hideable<InlineKeyboardButton.WebAppButton> {
177
- return {
178
- text,
179
- web_app: { url },
180
- hide,
181
- }
182
- }
1
+ import {
2
+ InlineKeyboardButton,
3
+ KeyboardButton,
4
+ KeyboardButtonRequestChat,
5
+ KeyboardButtonRequestUsers,
6
+ } from './core/types/typegram'
7
+
8
+ type Hideable<B> = B & { hide: boolean }
9
+
10
+ export function text(
11
+ text: string,
12
+ hide = false
13
+ ): Hideable<KeyboardButton.CommonButton> {
14
+ return { text, hide }
15
+ }
16
+
17
+ export function contactRequest(
18
+ text: string,
19
+ hide = false
20
+ ): Hideable<KeyboardButton.RequestContactButton> {
21
+ return { text, request_contact: true, hide }
22
+ }
23
+
24
+ export function locationRequest(
25
+ text: string,
26
+ hide = false
27
+ ): Hideable<KeyboardButton.RequestLocationButton> {
28
+ return { text, request_location: true, hide }
29
+ }
30
+
31
+ export function pollRequest(
32
+ text: string,
33
+ type?: 'quiz' | 'regular',
34
+ hide = false
35
+ ): Hideable<KeyboardButton.RequestPollButton> {
36
+ return { text, request_poll: { type }, hide }
37
+ }
38
+
39
+ export function userRequest(
40
+ text: string,
41
+ /** Must fit in a signed 32 bit int */
42
+ request_id: number,
43
+ extra?: Omit<KeyboardButtonRequestUsers, 'request_id' | 'text'>,
44
+ hide = false
45
+ ): Hideable<KeyboardButton.RequestUsersButton> {
46
+ return {
47
+ text,
48
+ request_users: { request_id, ...extra },
49
+ hide,
50
+ }
51
+ }
52
+
53
+ export function botRequest(
54
+ text: string,
55
+ /** Must fit in a signed 32 bit int */
56
+ request_id: number,
57
+ extra?: Omit<
58
+ KeyboardButtonRequestUsers,
59
+ 'request_id' | 'user_is_bot' | 'text'
60
+ >,
61
+ hide = false
62
+ ): Hideable<KeyboardButton.RequestUsersButton> {
63
+ return {
64
+ text,
65
+ request_users: { request_id, user_is_bot: true, ...extra },
66
+ hide,
67
+ }
68
+ }
69
+
70
+ type KeyboardButtonRequestGroup = Omit<
71
+ KeyboardButtonRequestChat,
72
+ 'request_id' | 'chat_is_channel'
73
+ >
74
+
75
+ export function groupRequest(
76
+ text: string,
77
+ /** Must fit in a signed 32 bit int */
78
+ request_id: number,
79
+ extra?: KeyboardButtonRequestGroup,
80
+ hide = false
81
+ ): Hideable<KeyboardButton.RequestChatButton> {
82
+ return {
83
+ text,
84
+ request_chat: { request_id, chat_is_channel: false, ...extra },
85
+ hide,
86
+ }
87
+ }
88
+
89
+ type KeyboardButtonRequestChannel = Omit<
90
+ KeyboardButtonRequestChat,
91
+ 'request_id' | 'chat_is_channel' | 'chat_is_forum'
92
+ >
93
+
94
+ export function channelRequest(
95
+ text: string,
96
+ /** Must fit in a signed 32 bit int */
97
+ request_id: number,
98
+ extra?: KeyboardButtonRequestChannel,
99
+ hide = false
100
+ ): Hideable<KeyboardButton.RequestChatButton> {
101
+ return {
102
+ text,
103
+ request_chat: { request_id, chat_is_channel: true, ...extra },
104
+ hide,
105
+ }
106
+ }
107
+
108
+ export function url(
109
+ text: string,
110
+ url: string,
111
+ hide = false
112
+ ): Hideable<InlineKeyboardButton.UrlButton> {
113
+ return { text, url, hide }
114
+ }
115
+
116
+ export function callback(
117
+ text: string,
118
+ data: string,
119
+ hide = false
120
+ ): Hideable<InlineKeyboardButton.CallbackButton> {
121
+ return { text, callback_data: data, hide }
122
+ }
123
+
124
+ export function switchToChat(
125
+ text: string,
126
+ value: string,
127
+ hide = false
128
+ ): Hideable<InlineKeyboardButton.SwitchInlineButton> {
129
+ return { text, switch_inline_query: value, hide }
130
+ }
131
+
132
+ export function switchToCurrentChat(
133
+ text: string,
134
+ value: string,
135
+ hide = false
136
+ ): Hideable<InlineKeyboardButton.SwitchInlineCurrentChatButton> {
137
+ return { text, switch_inline_query_current_chat: value, hide }
138
+ }
139
+
140
+ export function game(
141
+ text: string,
142
+ hide = false
143
+ ): Hideable<InlineKeyboardButton.GameButton> {
144
+ return { text, callback_game: {}, hide }
145
+ }
146
+
147
+ export function pay(
148
+ text: string,
149
+ hide = false
150
+ ): Hideable<InlineKeyboardButton.PayButton> {
151
+ return { text, pay: true, hide }
152
+ }
153
+
154
+ export function login(
155
+ text: string,
156
+ url: string,
157
+ opts: {
158
+ forward_text?: string
159
+ bot_username?: string
160
+ request_write_access?: boolean
161
+ } = {},
162
+ hide = false
163
+ ): Hideable<InlineKeyboardButton.LoginButton> {
164
+ return {
165
+ text,
166
+ login_url: { ...opts, url },
167
+ hide,
168
+ }
169
+ }
170
+
171
+ export function webApp(
172
+ text: string,
173
+ url: string,
174
+ hide = false
175
+ // works as both InlineKeyboardButton and KeyboardButton
176
+ ): Hideable<InlineKeyboardButton.WebAppButton> {
177
+ return {
178
+ text,
179
+ web_app: { url },
180
+ hide,
181
+ }
182
+ }