teledzik 1.0.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.
Files changed (198) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +1126 -0
  3. package/filters.d.ts +1 -0
  4. package/filters.js +1 -0
  5. package/format.d.ts +1 -0
  6. package/format.js +1 -0
  7. package/future.d.ts +1 -0
  8. package/future.js +1 -0
  9. package/lib/button.js +101 -0
  10. package/lib/cli.mjs +105 -0
  11. package/lib/composer.js +581 -0
  12. package/lib/context.js +1300 -0
  13. package/lib/core/helpers/ai-stream.js +69 -0
  14. package/lib/core/helpers/args.js +58 -0
  15. package/lib/core/helpers/check.js +56 -0
  16. package/lib/core/helpers/compact.js +17 -0
  17. package/lib/core/helpers/deunionize.js +13 -0
  18. package/lib/core/helpers/formatting.js +89 -0
  19. package/lib/core/helpers/input-box.js +87 -0
  20. package/lib/core/helpers/rich-sanitizer.js +31 -0
  21. package/lib/core/helpers/smart-queue.js +70 -0
  22. package/lib/core/helpers/util.js +50 -0
  23. package/lib/core/network/client.js +318 -0
  24. package/lib/core/network/error.js +21 -0
  25. package/lib/core/network/multipart-stream.js +61 -0
  26. package/lib/core/network/polling.js +86 -0
  27. package/lib/core/network/webhook.js +54 -0
  28. package/lib/core/types/rich-message.js +287 -0
  29. package/lib/core/types/typegram.js +18 -0
  30. package/lib/filters.js +69 -0
  31. package/lib/format.js +38 -0
  32. package/lib/future.js +166 -0
  33. package/lib/index.js +61 -0
  34. package/lib/input.js +61 -0
  35. package/lib/markup.js +111 -0
  36. package/lib/middleware.js +2 -0
  37. package/lib/paginated.js +76 -0
  38. package/lib/reactions.js +81 -0
  39. package/lib/router.js +45 -0
  40. package/lib/scenes/base.js +39 -0
  41. package/lib/scenes/context.js +99 -0
  42. package/lib/scenes/form-scene.js +23 -0
  43. package/lib/scenes/index.js +21 -0
  44. package/lib/scenes/stage.js +49 -0
  45. package/lib/scenes/wizard/context.js +30 -0
  46. package/lib/scenes/wizard/index.js +45 -0
  47. package/lib/scenes.js +17 -0
  48. package/lib/session.js +163 -0
  49. package/lib/telegraf.js +274 -0
  50. package/lib/telegram-types.js +6 -0
  51. package/lib/telegram.js +1286 -0
  52. package/lib/types.js +2 -0
  53. package/lib/utils.js +5 -0
  54. package/markup.d.ts +1 -0
  55. package/markup.js +1 -0
  56. package/package.json +141 -0
  57. package/scenes.d.ts +1 -0
  58. package/scenes.js +1 -0
  59. package/session.d.ts +1 -0
  60. package/session.js +1 -0
  61. package/src/button.ts +182 -0
  62. package/src/composer.ts +1008 -0
  63. package/src/context.ts +1778 -0
  64. package/src/core/helpers/ai-stream.ts +96 -0
  65. package/src/core/helpers/args.ts +63 -0
  66. package/src/core/helpers/check.ts +71 -0
  67. package/src/core/helpers/compact.ts +18 -0
  68. package/src/core/helpers/deunionize.ts +26 -0
  69. package/src/core/helpers/formatting.ts +119 -0
  70. package/src/core/helpers/input-box.ts +86 -0
  71. package/src/core/helpers/rich-sanitizer.ts +36 -0
  72. package/src/core/helpers/smart-queue.ts +89 -0
  73. package/src/core/helpers/util.ts +96 -0
  74. package/src/core/network/client.ts +396 -0
  75. package/src/core/network/error.ts +29 -0
  76. package/src/core/network/multipart-stream.ts +45 -0
  77. package/src/core/network/polling.ts +94 -0
  78. package/src/core/network/webhook.ts +58 -0
  79. package/src/core/types/rich-message.ts +375 -0
  80. package/src/core/types/typegram.ts +44 -0
  81. package/src/filters.js +69 -0
  82. package/src/filters.ts +109 -0
  83. package/src/format.js +38 -0
  84. package/src/format.ts +110 -0
  85. package/src/future.js +147 -0
  86. package/src/future.ts +231 -0
  87. package/src/index.ts +27 -0
  88. package/src/input.ts +59 -0
  89. package/src/markup.js +93 -0
  90. package/src/markup.ts +142 -0
  91. package/src/middleware.ts +24 -0
  92. package/src/paginated.ts +75 -0
  93. package/src/reactions.ts +118 -0
  94. package/src/router.ts +55 -0
  95. package/src/scenes/base.ts +52 -0
  96. package/src/scenes/context.ts +136 -0
  97. package/src/scenes/form-scene.ts +34 -0
  98. package/src/scenes/index.ts +21 -0
  99. package/src/scenes/stage.ts +71 -0
  100. package/src/scenes/wizard/context.ts +58 -0
  101. package/src/scenes/wizard/index.ts +63 -0
  102. package/src/scenes.js +17 -0
  103. package/src/scenes.ts +1 -0
  104. package/src/session.js +175 -0
  105. package/src/session.ts +204 -0
  106. package/src/telegraf.ts +385 -0
  107. package/src/telegram-types.ts +256 -0
  108. package/src/telegram.ts +1700 -0
  109. package/src/types.js +2 -0
  110. package/src/types.ts +2 -0
  111. package/src/utils.js +5 -0
  112. package/src/utils.ts +1 -0
  113. package/types.d.ts +1 -0
  114. package/types.js +1 -0
  115. package/typings/button.d.ts +35 -0
  116. package/typings/button.d.ts.map +1 -0
  117. package/typings/composer.d.ts +226 -0
  118. package/typings/composer.d.ts.map +1 -0
  119. package/typings/context.d.ts +711 -0
  120. package/typings/context.d.ts.map +1 -0
  121. package/typings/core/helpers/ai-stream.d.ts +33 -0
  122. package/typings/core/helpers/args.d.ts +10 -0
  123. package/typings/core/helpers/args.d.ts.map +1 -0
  124. package/typings/core/helpers/check.d.ts +55 -0
  125. package/typings/core/helpers/check.d.ts.map +1 -0
  126. package/typings/core/helpers/compact.d.ts +3 -0
  127. package/typings/core/helpers/compact.d.ts.map +1 -0
  128. package/typings/core/helpers/deunionize.d.ts +17 -0
  129. package/typings/core/helpers/deunionize.d.ts.map +1 -0
  130. package/typings/core/helpers/formatting.d.ts +29 -0
  131. package/typings/core/helpers/formatting.d.ts.map +1 -0
  132. package/typings/core/helpers/input-box.d.ts +32 -0
  133. package/typings/core/helpers/rich-sanitizer.d.ts +5 -0
  134. package/typings/core/helpers/smart-queue.d.ts +18 -0
  135. package/typings/core/helpers/util.d.ts +26 -0
  136. package/typings/core/helpers/util.d.ts.map +1 -0
  137. package/typings/core/network/client.d.ts +54 -0
  138. package/typings/core/network/client.d.ts.map +1 -0
  139. package/typings/core/network/error.d.ts +15 -0
  140. package/typings/core/network/error.d.ts.map +1 -0
  141. package/typings/core/network/multipart-stream.d.ts +19 -0
  142. package/typings/core/network/multipart-stream.d.ts.map +1 -0
  143. package/typings/core/network/polling.d.ts +15 -0
  144. package/typings/core/network/polling.d.ts.map +1 -0
  145. package/typings/core/network/webhook.d.ts +6 -0
  146. package/typings/core/network/webhook.d.ts.map +1 -0
  147. package/typings/core/types/rich-message.d.ts +143 -0
  148. package/typings/core/types/rich-message.d.ts.map +1 -0
  149. package/typings/core/types/typegram.d.ts +36 -0
  150. package/typings/core/types/typegram.d.ts.map +1 -0
  151. package/typings/filters.d.ts +17 -0
  152. package/typings/filters.d.ts.map +1 -0
  153. package/typings/format.d.ts +21 -0
  154. package/typings/format.d.ts.map +1 -0
  155. package/typings/future.d.ts +11 -0
  156. package/typings/future.d.ts.map +1 -0
  157. package/typings/index.d.ts +21 -0
  158. package/typings/index.d.ts.map +1 -0
  159. package/typings/input.d.ts +58 -0
  160. package/typings/input.d.ts.map +1 -0
  161. package/typings/markup.d.ts +26 -0
  162. package/typings/markup.d.ts.map +1 -0
  163. package/typings/middleware.d.ts +7 -0
  164. package/typings/middleware.d.ts.map +1 -0
  165. package/typings/paginated.d.ts +20 -0
  166. package/typings/reactions.d.ts +31 -0
  167. package/typings/reactions.d.ts.map +1 -0
  168. package/typings/router.d.ts +20 -0
  169. package/typings/router.d.ts.map +1 -0
  170. package/typings/scenes/base.d.ts +21 -0
  171. package/typings/scenes/base.d.ts.map +1 -0
  172. package/typings/scenes/context.d.ts +35 -0
  173. package/typings/scenes/context.d.ts.map +1 -0
  174. package/typings/scenes/form-scene.d.ts +17 -0
  175. package/typings/scenes/index.d.ts +10 -0
  176. package/typings/scenes/index.d.ts.map +1 -0
  177. package/typings/scenes/stage.d.ts +23 -0
  178. package/typings/scenes/stage.d.ts.map +1 -0
  179. package/typings/scenes/wizard/context.d.ts +28 -0
  180. package/typings/scenes/wizard/context.d.ts.map +1 -0
  181. package/typings/scenes/wizard/index.d.ts +15 -0
  182. package/typings/scenes/wizard/index.d.ts.map +1 -0
  183. package/typings/scenes.d.ts +1 -0
  184. package/typings/scenes.d.ts.map +1 -0
  185. package/typings/session.d.ts +54 -0
  186. package/typings/session.d.ts.map +1 -0
  187. package/typings/telegraf.d.ts +118 -0
  188. package/typings/telegraf.d.ts.map +1 -0
  189. package/typings/telegram-types.d.ts +140 -0
  190. package/typings/telegram-types.d.ts.map +1 -0
  191. package/typings/telegram.d.ts +697 -0
  192. package/typings/telegram.d.ts.map +1 -0
  193. package/typings/types.d.ts +2 -0
  194. package/typings/types.d.ts.map +1 -0
  195. package/typings/utils.d.ts +1 -0
  196. package/typings/utils.d.ts.map +1 -0
  197. package/utils.d.ts +1 -0
  198. package/utils.js +1 -0
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.argsParser = void 0;
4
+ var args_1 = require("./core/helpers/args");
5
+ Object.defineProperty(exports, "argsParser", { enumerable: true, get: function () { return args_1.argsParser; } });
package/markup.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './typings/markup'
package/markup.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./lib/markup')
package/package.json ADDED
@@ -0,0 +1,141 @@
1
+ {
2
+ "name": "teledzik",
3
+ "version": "1.0.0",
4
+ "description": "Modern Telegram Bot Framework (Bot API 10.1 + Rich Messages)",
5
+ "keywords": [
6
+ "telekaf",
7
+ "telegraf",
8
+ "telegram",
9
+ "telegram bot api",
10
+ "bot",
11
+ "botapi",
12
+ "bot framework",
13
+ "rich messages",
14
+ "bot api 10.1"
15
+ ],
16
+ "homepage": "https://telegraf.js.org",
17
+ "bugs": {
18
+ "url": "https://github.com/telegraf/telegraf/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+ssh://git@github.com/telegraf/telegraf.git"
23
+ },
24
+ "license": "MIT",
25
+ "author": "The Telegraf Contributors",
26
+ "type": "commonjs",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./typings/index.d.ts",
30
+ "default": "./lib/index.js"
31
+ },
32
+ "./filters": {
33
+ "types": "./filters.d.ts",
34
+ "default": "./filters.js"
35
+ },
36
+ "./future": {
37
+ "types": "./future.d.ts",
38
+ "default": "./future.js"
39
+ },
40
+ "./scenes": {
41
+ "types": "./scenes.d.ts",
42
+ "default": "./scenes.js"
43
+ },
44
+ "./types": {
45
+ "types": "./types.d.ts",
46
+ "default": "./types.js"
47
+ },
48
+ "./format": {
49
+ "types": "./format.d.ts",
50
+ "default": "./format.js"
51
+ },
52
+ "./utils": {
53
+ "types": "./utils.d.ts",
54
+ "default": "./utils.js"
55
+ },
56
+ "./markup": {
57
+ "types": "./markup.d.ts",
58
+ "default": "./markup.js"
59
+ },
60
+ "./session": {
61
+ "types": "./session.d.ts",
62
+ "default": "./session.js"
63
+ }
64
+ },
65
+ "main": "lib/index.js",
66
+ "types": "./typings/index.d.ts",
67
+ "bin": {
68
+ "telekaf": "lib/cli.mjs"
69
+ },
70
+ "directories": {
71
+ "lib": "lib"
72
+ },
73
+ "files": [
74
+ "bin/*",
75
+ "src/**/*.ts",
76
+ "lib/**/*.js",
77
+ "typings/**/*.d.ts",
78
+ "typings/**/*.d.ts.map",
79
+ "types.*",
80
+ "format.*",
81
+ "filters.*",
82
+ "future.*",
83
+ "scenes.*",
84
+ "utils.*",
85
+ "markup.*",
86
+ "session.*"
87
+ ],
88
+ "scripts": {
89
+ "prepare": "npm run --silent build",
90
+ "build": "npx tsc",
91
+ "expose": "tsx build/expose.ts types scenes filters format future utils markup session",
92
+ "build:docs": "typedoc src/index.ts",
93
+ "pretest": "npm run build",
94
+ "test": "ava",
95
+ "lint": "eslint .",
96
+ "lint:fix": "npm run lint -- --fix",
97
+ "checks": "npm test && npm run lint",
98
+ "refresh": "npm run clean && npm ci",
99
+ "clean": "git clean -fX .eslintcache docs/build/ lib/ typings/"
100
+ },
101
+ "dependencies": {
102
+ "@telegraf/types": "^7.1.0",
103
+ "abort-controller": "^3.0.0",
104
+ "debug": "^4.3.5",
105
+ "mri": "^1.2.0",
106
+ "node-fetch": "^2.7.0",
107
+ "p-timeout": "^4.1.0",
108
+ "safe-compare": "^1.1.4",
109
+ "sandwich-stream": "^2.0.2"
110
+ },
111
+ "devDependencies": {
112
+ "@types/debug": "^4.1.8",
113
+ "@types/node": "^20.4.2",
114
+ "@types/node-fetch": "^2.6.2",
115
+ "@types/safe-compare": "^1.1.0",
116
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
117
+ "@typescript-eslint/parser": "^6.21.0",
118
+ "ava": "^5.3.1",
119
+ "eslint": "^8.57.0",
120
+ "eslint-config-prettier": "^9.1.0",
121
+ "eslint-plugin-ava": "^14.0.0",
122
+ "eslint-plugin-import": "^2.29.1",
123
+ "eslint-plugin-node": "^11.1.0",
124
+ "eslint-plugin-prettier": "^5.1.3",
125
+ "eslint-plugin-promise": "^6.1.1",
126
+ "fast-check": "^3.12.0",
127
+ "prettier": "^3.0.3",
128
+ "tsx": "^4.7.1",
129
+ "typedoc": "^0.25.0",
130
+ "typescript": "^5.4.5"
131
+ },
132
+ "engines": {
133
+ "node": "^12.20.0 || >=14.13.1"
134
+ },
135
+ "ava": {
136
+ "files": [
137
+ "test/*",
138
+ "!test/_*"
139
+ ]
140
+ }
141
+ }
package/scenes.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './typings/scenes'
package/scenes.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./lib/scenes')
package/session.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './typings/session'
package/session.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./lib/session')
package/src/button.ts ADDED
@@ -0,0 +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
+ }