@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.
Files changed (168) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +356 -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 +100 -0
  10. package/lib/cli.mjs +105 -0
  11. package/lib/composer.js +582 -0
  12. package/lib/context.js +1219 -0
  13. package/lib/core/helpers/args.js +57 -0
  14. package/lib/core/helpers/check.js +55 -0
  15. package/lib/core/helpers/compact.js +16 -0
  16. package/lib/core/helpers/deunionize.js +12 -0
  17. package/lib/core/helpers/formatting.js +91 -0
  18. package/lib/core/helpers/util.js +50 -0
  19. package/lib/core/network/client.js +330 -0
  20. package/lib/core/network/error.js +21 -0
  21. package/lib/core/network/multipart-stream.js +71 -0
  22. package/lib/core/network/polling.js +87 -0
  23. package/lib/core/network/webhook.js +54 -0
  24. package/lib/core/types/typegram.js +27 -0
  25. package/lib/filters.js +69 -0
  26. package/lib/format.js +38 -0
  27. package/lib/future.js +149 -0
  28. package/lib/index.js +58 -0
  29. package/lib/input.js +61 -0
  30. package/lib/markup.js +121 -0
  31. package/lib/middleware.js +2 -0
  32. package/lib/reactions.js +84 -0
  33. package/lib/router.js +46 -0
  34. package/lib/scenes/base.js +39 -0
  35. package/lib/scenes/context.js +104 -0
  36. package/lib/scenes/index.js +21 -0
  37. package/lib/scenes/stage.js +49 -0
  38. package/lib/scenes/wizard/context.js +31 -0
  39. package/lib/scenes/wizard/index.js +45 -0
  40. package/lib/scenes.js +17 -0
  41. package/lib/session.js +166 -0
  42. package/lib/telegraf.js +256 -0
  43. package/lib/telegram-types.js +6 -0
  44. package/lib/telegram.js +1240 -0
  45. package/lib/types.js +2 -0
  46. package/lib/utils.js +5 -0
  47. package/markup.d.ts +1 -0
  48. package/markup.js +1 -0
  49. package/package.json +140 -0
  50. package/scenes.d.ts +1 -0
  51. package/scenes.js +1 -0
  52. package/session.d.ts +1 -0
  53. package/session.js +1 -0
  54. package/src/button.ts +182 -0
  55. package/src/composer.ts +1008 -0
  56. package/src/context.ts +1661 -0
  57. package/src/core/helpers/args.ts +63 -0
  58. package/src/core/helpers/check.ts +71 -0
  59. package/src/core/helpers/compact.ts +18 -0
  60. package/src/core/helpers/deunionize.ts +26 -0
  61. package/src/core/helpers/formatting.ts +119 -0
  62. package/src/core/helpers/util.ts +96 -0
  63. package/src/core/network/client.ts +396 -0
  64. package/src/core/network/error.ts +29 -0
  65. package/src/core/network/multipart-stream.ts +45 -0
  66. package/src/core/network/polling.ts +94 -0
  67. package/src/core/network/webhook.ts +58 -0
  68. package/src/core/types/typegram.ts +54 -0
  69. package/src/filters.ts +109 -0
  70. package/src/format.ts +110 -0
  71. package/src/future.ts +213 -0
  72. package/src/index.ts +17 -0
  73. package/src/input.ts +59 -0
  74. package/src/markup.ts +142 -0
  75. package/src/middleware.ts +24 -0
  76. package/src/reactions.ts +118 -0
  77. package/src/router.ts +55 -0
  78. package/src/scenes/base.ts +52 -0
  79. package/src/scenes/context.ts +136 -0
  80. package/src/scenes/index.ts +21 -0
  81. package/src/scenes/stage.ts +71 -0
  82. package/src/scenes/wizard/context.ts +58 -0
  83. package/src/scenes/wizard/index.ts +63 -0
  84. package/src/scenes.ts +1 -0
  85. package/src/session.ts +204 -0
  86. package/src/telegraf.ts +354 -0
  87. package/src/telegram-types.ts +219 -0
  88. package/src/telegram.ts +1635 -0
  89. package/src/types.ts +2 -0
  90. package/src/utils.ts +1 -0
  91. package/types.d.ts +1 -0
  92. package/types.js +1 -0
  93. package/typings/button.d.ts +36 -0
  94. package/typings/button.d.ts.map +1 -0
  95. package/typings/composer.d.ts +227 -0
  96. package/typings/composer.d.ts.map +1 -0
  97. package/typings/context.d.ts +655 -0
  98. package/typings/context.d.ts.map +1 -0
  99. package/typings/core/helpers/args.d.ts +11 -0
  100. package/typings/core/helpers/args.d.ts.map +1 -0
  101. package/typings/core/helpers/check.d.ts +56 -0
  102. package/typings/core/helpers/check.d.ts.map +1 -0
  103. package/typings/core/helpers/compact.d.ts +4 -0
  104. package/typings/core/helpers/compact.d.ts.map +1 -0
  105. package/typings/core/helpers/deunionize.d.ts +18 -0
  106. package/typings/core/helpers/deunionize.d.ts.map +1 -0
  107. package/typings/core/helpers/formatting.d.ts +30 -0
  108. package/typings/core/helpers/formatting.d.ts.map +1 -0
  109. package/typings/core/helpers/util.d.ts +26 -0
  110. package/typings/core/helpers/util.d.ts.map +1 -0
  111. package/typings/core/network/client.d.ts +53 -0
  112. package/typings/core/network/client.d.ts.map +1 -0
  113. package/typings/core/network/error.d.ts +16 -0
  114. package/typings/core/network/error.d.ts.map +1 -0
  115. package/typings/core/network/multipart-stream.d.ts +16 -0
  116. package/typings/core/network/multipart-stream.d.ts.map +1 -0
  117. package/typings/core/network/polling.d.ts +16 -0
  118. package/typings/core/network/polling.d.ts.map +1 -0
  119. package/typings/core/network/webhook.d.ts +6 -0
  120. package/typings/core/network/webhook.d.ts.map +1 -0
  121. package/typings/core/types/typegram.d.ts +42 -0
  122. package/typings/core/types/typegram.d.ts.map +1 -0
  123. package/typings/filters.d.ts +18 -0
  124. package/typings/filters.d.ts.map +1 -0
  125. package/typings/format.d.ts +22 -0
  126. package/typings/format.d.ts.map +1 -0
  127. package/typings/future.d.ts +12 -0
  128. package/typings/future.d.ts.map +1 -0
  129. package/typings/index.d.ts +15 -0
  130. package/typings/index.d.ts.map +1 -0
  131. package/typings/input.d.ts +50 -0
  132. package/typings/input.d.ts.map +1 -0
  133. package/typings/markup.d.ts +27 -0
  134. package/typings/markup.d.ts.map +1 -0
  135. package/typings/middleware.d.ts +8 -0
  136. package/typings/middleware.d.ts.map +1 -0
  137. package/typings/reactions.d.ts +32 -0
  138. package/typings/reactions.d.ts.map +1 -0
  139. package/typings/router.d.ts +21 -0
  140. package/typings/router.d.ts.map +1 -0
  141. package/typings/scenes/base.d.ts +22 -0
  142. package/typings/scenes/base.d.ts.map +1 -0
  143. package/typings/scenes/context.d.ts +36 -0
  144. package/typings/scenes/context.d.ts.map +1 -0
  145. package/typings/scenes/index.d.ts +11 -0
  146. package/typings/scenes/index.d.ts.map +1 -0
  147. package/typings/scenes/stage.d.ts +24 -0
  148. package/typings/scenes/stage.d.ts.map +1 -0
  149. package/typings/scenes/wizard/context.d.ts +29 -0
  150. package/typings/scenes/wizard/context.d.ts.map +1 -0
  151. package/typings/scenes/wizard/index.d.ts +16 -0
  152. package/typings/scenes/wizard/index.d.ts.map +1 -0
  153. package/typings/scenes.d.ts +2 -0
  154. package/typings/scenes.d.ts.map +1 -0
  155. package/typings/session.d.ts +55 -0
  156. package/typings/session.d.ts.map +1 -0
  157. package/typings/telegraf.d.ts +115 -0
  158. package/typings/telegraf.d.ts.map +1 -0
  159. package/typings/telegram-types.d.ts +117 -0
  160. package/typings/telegram-types.d.ts.map +1 -0
  161. package/typings/telegram.d.ts +675 -0
  162. package/typings/telegram.d.ts.map +1 -0
  163. package/typings/types.d.ts +3 -0
  164. package/typings/types.d.ts.map +1 -0
  165. package/typings/utils.d.ts +2 -0
  166. package/typings/utils.d.ts.map +1 -0
  167. package/utils.d.ts +1 -0
  168. 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,140 @@
1
+ {
2
+ "name": "@tgify/tgify",
3
+ "version": "0.1.0",
4
+ "description": "Modern Telegram Bot Framework",
5
+ "license": "MIT",
6
+ "author": "IATNAOD",
7
+ "homepage": "https://tgify.iatnaod.space",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+ssh://git@github.com/IATNAOD/tgify.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/IATNAOD/tgify/issues"
14
+ },
15
+ "main": "lib/index.js",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./typings/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./filters": {
22
+ "types": "./filters.d.ts",
23
+ "default": "./filters.js"
24
+ },
25
+ "./future": {
26
+ "types": "./future.d.ts",
27
+ "default": "./future.js"
28
+ },
29
+ "./scenes": {
30
+ "types": "./scenes.d.ts",
31
+ "default": "./scenes.js"
32
+ },
33
+ "./types": {
34
+ "types": "./types.d.ts",
35
+ "default": "./types.js"
36
+ },
37
+ "./format": {
38
+ "types": "./format.d.ts",
39
+ "default": "./format.js"
40
+ },
41
+ "./utils": {
42
+ "types": "./utils.d.ts",
43
+ "default": "./utils.js"
44
+ },
45
+ "./markup": {
46
+ "types": "./markup.d.ts",
47
+ "default": "./markup.js"
48
+ },
49
+ "./session": {
50
+ "types": "./session.d.ts",
51
+ "default": "./session.js"
52
+ }
53
+ },
54
+ "files": [
55
+ "bin/*",
56
+ "src/**/*.ts",
57
+ "lib/**/*.js",
58
+ "typings/**/*.d.ts",
59
+ "typings/**/*.d.ts.map",
60
+ "types.*",
61
+ "format.*",
62
+ "filters.*",
63
+ "future.*",
64
+ "scenes.*",
65
+ "utils.*",
66
+ "markup.*",
67
+ "session.*"
68
+ ],
69
+ "bin": {
70
+ "tgify": "lib/cli.mjs"
71
+ },
72
+ "scripts": {
73
+ "prepare": "npm run --silent build",
74
+ "build": "tsc && npm run expose",
75
+ "expose": "tsx build/expose.ts types scenes filters format future utils markup session",
76
+ "build:docs": "typedoc src/index.ts",
77
+ "pretest": "npm run build",
78
+ "test": "ava",
79
+ "lint": "eslint .",
80
+ "lint:fix": "npm run lint -- --fix",
81
+ "checks": "npm test && npm run lint",
82
+ "refresh": "npm run clean && npm ci",
83
+ "clean": "git clean -fX .eslintcache docs/build/ lib/ typings/"
84
+ },
85
+ "ava": {
86
+ "files": [
87
+ "test/*",
88
+ "!test/_*"
89
+ ]
90
+ },
91
+ "type": "commonjs",
92
+ "engines": {
93
+ "node": "^12.20.0 || >=14.13.1"
94
+ },
95
+ "types": "./typings/index.d.ts",
96
+ "dependencies": {
97
+ "@telegraf/types": "^7.1.0",
98
+ "abort-controller": "^3.0.0",
99
+ "debug": "^4.3.5",
100
+ "mri": "^1.2.0",
101
+ "node-fetch": "^2.7.0",
102
+ "p-timeout": "^4.1.0",
103
+ "safe-compare": "^1.1.4",
104
+ "sandwich-stream": "^2.0.2"
105
+ },
106
+ "devDependencies": {
107
+ "@types/debug": "^4.1.8",
108
+ "@types/node": "^20.4.2",
109
+ "@types/node-fetch": "^2.6.2",
110
+ "@types/safe-compare": "^1.1.0",
111
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
112
+ "@typescript-eslint/parser": "^6.21.0",
113
+ "ava": "^5.3.1",
114
+ "eslint": "^8.57.0",
115
+ "eslint-config-prettier": "^9.1.0",
116
+ "eslint-plugin-ava": "^14.0.0",
117
+ "eslint-plugin-import": "^2.29.1",
118
+ "eslint-plugin-node": "^11.1.0",
119
+ "eslint-plugin-prettier": "^5.1.3",
120
+ "eslint-plugin-promise": "^6.1.1",
121
+ "fast-check": "^3.12.0",
122
+ "prettier": "^3.0.3",
123
+ "tsx": "^4.7.1",
124
+ "typedoc": "^0.25.0",
125
+ "typescript": "^5.2.2"
126
+ },
127
+ "keywords": [
128
+ "tgify",
129
+ "telegram",
130
+ "telegram bot api",
131
+ "bot",
132
+ "botapi",
133
+ "bot framework"
134
+ ],
135
+ "directories": {
136
+ "doc": "docs",
137
+ "lib": "lib",
138
+ "test": "test"
139
+ }
140
+ }
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
+ }