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/src/format.ts ADDED
@@ -0,0 +1,110 @@
1
+ import { User } from '@telegraf/types'
2
+ import {
3
+ FmtString,
4
+ createFmt,
5
+ linkOrMention,
6
+ join as _join,
7
+ } from './core/helpers/formatting'
8
+
9
+ export { FmtString }
10
+
11
+ type Nestable<Kind extends string> = string | number | boolean | FmtString<Kind>
12
+ type Nesting<Kind extends string> = [
13
+ parts: Nestable<Kind> | readonly Nestable<Kind>[],
14
+ ...items: Nestable<Kind>[],
15
+ ]
16
+ type Nests<Is extends string, Kind extends string> = (
17
+ ...args: Nesting<Kind>
18
+ ) => FmtString<Is>
19
+
20
+ // Nests<A, B> means the function will return A, and it can nest B
21
+ // Nests<'fmt', string> means it will nest anything
22
+ // Nests<'code', never> means it will not nest anything
23
+
24
+ // Allowing everything to nest 'fmt' is a necessary evil; it allows to indirectly nest illegal entities
25
+ // Except for 'code' and 'pre', which don't nest anything anyway, so they only deal with strings
26
+
27
+ export const join = _join as Nests<'fmt', string>
28
+
29
+ export const fmt = createFmt() as Nests<'fmt', string>
30
+
31
+ export const bold = createFmt('bold') as Nests<
32
+ 'bold',
33
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
34
+ >
35
+
36
+ export const italic = createFmt('italic') as Nests<
37
+ 'italic',
38
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
39
+ >
40
+
41
+ export const spoiler = createFmt('spoiler') as Nests<
42
+ 'spoiler',
43
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
44
+ >
45
+
46
+ export const strikethrough =
47
+ //
48
+ createFmt('strikethrough') as Nests<
49
+ 'strikethrough',
50
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
51
+ >
52
+
53
+ export const underline =
54
+ //
55
+ createFmt('underline') as Nests<
56
+ 'underline',
57
+ 'fmt' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler'
58
+ >
59
+
60
+ export const quote =
61
+ //
62
+ createFmt('blockquote') as Nests<
63
+ 'blockquote',
64
+ | 'fmt'
65
+ | 'bold'
66
+ | 'italic'
67
+ | 'underline'
68
+ | 'strikethrough'
69
+ | 'spoiler'
70
+ | 'code'
71
+ >
72
+
73
+ export const code = createFmt('code') as Nests<'code', never>
74
+
75
+ export const pre = (language: string) =>
76
+ createFmt('pre', { language }) as Nests<'pre', never>
77
+
78
+ export const link = (
79
+ content: Nestable<
80
+ | 'fmt'
81
+ | 'bold'
82
+ | 'italic'
83
+ | 'underline'
84
+ | 'strikethrough'
85
+ | 'spoiler'
86
+ | 'code'
87
+ >,
88
+ url: string
89
+ ) =>
90
+ //
91
+ linkOrMention(content, { type: 'text_link', url }) as FmtString<'text_link'>
92
+
93
+ export const mention = (
94
+ name: Nestable<
95
+ | 'fmt'
96
+ | 'bold'
97
+ | 'italic'
98
+ | 'underline'
99
+ | 'strikethrough'
100
+ | 'spoiler'
101
+ | 'code'
102
+ >,
103
+ user: number | User
104
+ ) =>
105
+ typeof user === 'number'
106
+ ? link(name, 'tg://user?id=' + user)
107
+ : (linkOrMention(name, {
108
+ type: 'text_mention',
109
+ user,
110
+ }) as FmtString<'text_mention'>)
package/src/future.js ADDED
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useNewReplies = void 0;
4
+ function makeReply(ctx, extra) {
5
+ if (ctx.msgId)
6
+ return Object.assign({
7
+ // overrides in this order so user can override all properties
8
+ reply_parameters: Object.assign({ message_id: ctx.msgId }, extra === null || extra === void 0 ? void 0 : extra.reply_parameters) }, extra);
9
+ else
10
+ return extra;
11
+ }
12
+ const replyContext = {
13
+ replyWithChatAction: function () {
14
+ throw new TypeError('ctx.replyWithChatAction has been removed, use ctx.sendChatAction instead');
15
+ },
16
+ reply(text, extra) {
17
+ this.assert(this.chat, 'reply');
18
+ return this.telegram.sendMessage(this.chat.id, text, makeReply(this, extra));
19
+ },
20
+ replyWithAnimation(animation, extra) {
21
+ this.assert(this.chat, 'replyWithAnimation');
22
+ return this.telegram.sendAnimation(this.chat.id, animation, makeReply(this, extra));
23
+ },
24
+ replyWithAudio(audio, extra) {
25
+ this.assert(this.chat, 'replyWithAudio');
26
+ return this.telegram.sendAudio(this.chat.id, audio, makeReply(this, extra));
27
+ },
28
+ replyWithContact(phoneNumber, firstName, extra) {
29
+ this.assert(this.chat, 'replyWithContact');
30
+ return this.telegram.sendContact(this.chat.id, phoneNumber, firstName, makeReply(this, extra));
31
+ },
32
+ replyWithDice(extra) {
33
+ this.assert(this.chat, 'replyWithDice');
34
+ return this.telegram.sendDice(this.chat.id, makeReply(this, extra));
35
+ },
36
+ replyWithDocument(document, extra) {
37
+ this.assert(this.chat, 'replyWithDocument');
38
+ return this.telegram.sendDocument(this.chat.id, document, makeReply(this, extra));
39
+ },
40
+ replyWithGame(gameName, extra) {
41
+ this.assert(this.chat, 'replyWithGame');
42
+ return this.telegram.sendGame(this.chat.id, gameName, makeReply(this, extra));
43
+ },
44
+ replyWithHTML(html, extra) {
45
+ this.assert(this.chat, 'replyWithHTML');
46
+ return this.telegram.sendMessage(this.chat.id, html, Object.assign({ parse_mode: 'HTML' }, makeReply(this, extra)));
47
+ },
48
+ replyWithInvoice(invoice, extra) {
49
+ this.assert(this.chat, 'replyWithInvoice');
50
+ return this.telegram.sendInvoice(this.chat.id, invoice, makeReply(this, extra));
51
+ },
52
+ replyWithLocation(latitude, longitude, extra) {
53
+ this.assert(this.chat, 'replyWithLocation');
54
+ return this.telegram.sendLocation(this.chat.id, latitude, longitude, makeReply(this, extra));
55
+ },
56
+ replyWithMarkdown(markdown, extra) {
57
+ this.assert(this.chat, 'replyWithMarkdown');
58
+ return this.telegram.sendMessage(this.chat.id, markdown, Object.assign({ parse_mode: 'Markdown' }, makeReply(this, extra)));
59
+ },
60
+ replyWithMarkdownV2(markdown, extra) {
61
+ this.assert(this.chat, 'replyWithMarkdownV2');
62
+ return this.telegram.sendMessage(this.chat.id, markdown, Object.assign({ parse_mode: 'MarkdownV2' }, makeReply(this, extra)));
63
+ },
64
+ replyWithMediaGroup(media, extra) {
65
+ this.assert(this.chat, 'replyWithMediaGroup');
66
+ return this.telegram.sendMediaGroup(this.chat.id, media, makeReply(this, extra));
67
+ },
68
+ replyWithPhoto(photo, extra) {
69
+ this.assert(this.chat, 'replyWithPhoto');
70
+ return this.telegram.sendPhoto(this.chat.id, photo, makeReply(this, extra));
71
+ },
72
+ replyWithPoll(question, options, extra) {
73
+ this.assert(this.chat, 'replyWithPoll');
74
+ return this.telegram.sendPoll(this.chat.id, question, options, makeReply(this, extra));
75
+ },
76
+ replyWithQuiz(question, options, extra) {
77
+ this.assert(this.chat, 'replyWithQuiz');
78
+ return this.telegram.sendQuiz(this.chat.id, question, options, makeReply(this, extra));
79
+ },
80
+ replyWithSticker(sticker, extra) {
81
+ this.assert(this.chat, 'replyWithSticker');
82
+ return this.telegram.sendSticker(this.chat.id, sticker, makeReply(this, extra));
83
+ },
84
+ replyWithVenue(latitude, longitude, title, address, extra) {
85
+ this.assert(this.chat, 'replyWithVenue');
86
+ return this.telegram.sendVenue(this.chat.id, latitude, longitude, title, address, makeReply(this, extra));
87
+ },
88
+ replyWithVideo(video, extra) {
89
+ this.assert(this.chat, 'replyWithVideo');
90
+ return this.telegram.sendVideo(this.chat.id, video, makeReply(this, extra));
91
+ },
92
+ replyWithVideoNote(videoNote, extra) {
93
+ this.assert(this.chat, 'replyWithVideoNote');
94
+ return this.telegram.sendVideoNote(this.chat.id, videoNote, makeReply(this, extra));
95
+ },
96
+ replyWithVoice(voice, extra) {
97
+ this.assert(this.chat, 'replyWithVoice');
98
+ return this.telegram.sendVoice(this.chat.id, voice, makeReply(this, extra));
99
+ },
100
+ replyWithRichMessage(options) {
101
+ this.assert(this.chat, 'replyWithRichMessage');
102
+ const { text, parseMode = 'HTML', buttons, disableLinkPreview, extra } = options;
103
+ return this.telegram.sendMessage(this.chat.id, text, makeReply(this, Object.assign({ parse_mode: parseMode, link_preview_options: disableLinkPreview ? { is_disabled: true } : undefined, reply_markup: (buttons === null || buttons === void 0 ? void 0 : buttons.length) ? { inline_keyboard: buttons } : undefined }, extra)));
104
+ },
105
+ replyWithRichMessageContent(richMessage, extra) {
106
+ this.assert(this.chat, 'replyWithRichMessageContent');
107
+ return this.telegram.sendRichMessage(this.chat.id, richMessage, makeReply(this, extra));
108
+ },
109
+ };
110
+ /**
111
+ * Sets up Context to use the new reply methods.
112
+ * This middleware makes `ctx.reply()` and `ctx.replyWith*()` methods will actually reply to the message they are replying to.
113
+ * Use `ctx.sendMessage()` to send a message in chat without replying to it.
114
+ *
115
+ * If the message to reply is deleted, `reply()` will send a normal message.
116
+ * If the update is not a message and we are unable to reply, `reply()` will send a normal message.
117
+ */
118
+ function useNewReplies() {
119
+ return (ctx, next) => {
120
+ ctx.reply = replyContext.reply;
121
+ ctx.replyWithPhoto = replyContext.replyWithPhoto;
122
+ ctx.replyWithMediaGroup = replyContext.replyWithMediaGroup;
123
+ ctx.replyWithAudio = replyContext.replyWithAudio;
124
+ ctx.replyWithDice = replyContext.replyWithDice;
125
+ ctx.replyWithDocument = replyContext.replyWithDocument;
126
+ ctx.replyWithSticker = replyContext.replyWithSticker;
127
+ ctx.replyWithVideo = replyContext.replyWithVideo;
128
+ ctx.replyWithAnimation = replyContext.replyWithAnimation;
129
+ ctx.replyWithVideoNote = replyContext.replyWithVideoNote;
130
+ ctx.replyWithInvoice = replyContext.replyWithInvoice;
131
+ ctx.replyWithGame = replyContext.replyWithGame;
132
+ ctx.replyWithVoice = replyContext.replyWithVoice;
133
+ ctx.replyWithPoll = replyContext.replyWithPoll;
134
+ ctx.replyWithQuiz = replyContext.replyWithQuiz;
135
+ ctx.replyWithChatAction = replyContext.replyWithChatAction;
136
+ ctx.replyWithLocation = replyContext.replyWithLocation;
137
+ ctx.replyWithVenue = replyContext.replyWithVenue;
138
+ ctx.replyWithContact = replyContext.replyWithContact;
139
+ ctx.replyWithMarkdown = replyContext.replyWithMarkdown;
140
+ ctx.replyWithMarkdownV2 = replyContext.replyWithMarkdownV2;
141
+ ctx.replyWithHTML = replyContext.replyWithHTML;
142
+ ctx.replyWithRichMessage = replyContext.replyWithRichMessage;
143
+ ctx.replyWithRichMessageContent = replyContext.replyWithRichMessageContent;
144
+ return next();
145
+ };
146
+ }
147
+ exports.useNewReplies = useNewReplies;
package/src/future.ts ADDED
@@ -0,0 +1,231 @@
1
+ import { ReplyParameters } from '@telegraf/types'
2
+ import Context from './context'
3
+ import { Middleware } from './middleware'
4
+ import type { InputRichMessage } from './core/types/rich-message'
5
+ import type { ExtraSendRichMessage } from './telegram-types'
6
+
7
+ type ReplyContext = { [key in keyof Context & `reply${string}`]: Context[key] }
8
+
9
+ function makeReply<
10
+ C extends Context,
11
+ E extends { reply_parameters?: ReplyParameters },
12
+ >(ctx: C, extra?: E) {
13
+ if (ctx.msgId)
14
+ return {
15
+ // overrides in this order so user can override all properties
16
+ reply_parameters: {
17
+ message_id: ctx.msgId,
18
+ ...extra?.reply_parameters,
19
+ },
20
+ ...extra,
21
+ }
22
+ else return extra
23
+ }
24
+
25
+ const replyContext: ReplyContext = {
26
+ replyWithChatAction: function () {
27
+ throw new TypeError(
28
+ 'ctx.replyWithChatAction has been removed, use ctx.sendChatAction instead'
29
+ )
30
+ },
31
+ reply(this: Context, text, extra) {
32
+ this.assert(this.chat, 'reply')
33
+ return this.telegram.sendMessage(this.chat.id, text, makeReply(this, extra))
34
+ },
35
+ replyWithAnimation(this: Context, animation, extra) {
36
+ this.assert(this.chat, 'replyWithAnimation')
37
+ return this.telegram.sendAnimation(
38
+ this.chat.id,
39
+ animation,
40
+ makeReply(this, extra)
41
+ )
42
+ },
43
+ replyWithAudio(this: Context, audio, extra) {
44
+ this.assert(this.chat, 'replyWithAudio')
45
+ return this.telegram.sendAudio(this.chat.id, audio, makeReply(this, extra))
46
+ },
47
+ replyWithContact(this: Context, phoneNumber, firstName, extra) {
48
+ this.assert(this.chat, 'replyWithContact')
49
+ return this.telegram.sendContact(
50
+ this.chat.id,
51
+ phoneNumber,
52
+ firstName,
53
+ makeReply(this, extra)
54
+ )
55
+ },
56
+ replyWithDice(this: Context, extra) {
57
+ this.assert(this.chat, 'replyWithDice')
58
+ return this.telegram.sendDice(this.chat.id, makeReply(this, extra))
59
+ },
60
+ replyWithDocument(this: Context, document, extra) {
61
+ this.assert(this.chat, 'replyWithDocument')
62
+ return this.telegram.sendDocument(
63
+ this.chat.id,
64
+ document,
65
+ makeReply(this, extra)
66
+ )
67
+ },
68
+ replyWithGame(this: Context, gameName, extra) {
69
+ this.assert(this.chat, 'replyWithGame')
70
+ return this.telegram.sendGame(
71
+ this.chat.id,
72
+ gameName,
73
+ makeReply(this, extra)
74
+ )
75
+ },
76
+ replyWithHTML(this: Context, html, extra) {
77
+ this.assert(this.chat, 'replyWithHTML')
78
+ return this.telegram.sendMessage(this.chat.id, html, {
79
+ parse_mode: 'HTML',
80
+ ...makeReply(this, extra),
81
+ })
82
+ },
83
+ replyWithInvoice(this: Context, invoice, extra) {
84
+ this.assert(this.chat, 'replyWithInvoice')
85
+ return this.telegram.sendInvoice(
86
+ this.chat.id,
87
+ invoice,
88
+ makeReply(this, extra)
89
+ )
90
+ },
91
+ replyWithLocation(this: Context, latitude, longitude, extra) {
92
+ this.assert(this.chat, 'replyWithLocation')
93
+ return this.telegram.sendLocation(
94
+ this.chat.id,
95
+ latitude,
96
+ longitude,
97
+ makeReply(this, extra)
98
+ )
99
+ },
100
+ replyWithMarkdown(this: Context, markdown, extra) {
101
+ this.assert(this.chat, 'replyWithMarkdown')
102
+ return this.telegram.sendMessage(this.chat.id, markdown, {
103
+ parse_mode: 'Markdown',
104
+ ...makeReply(this, extra),
105
+ })
106
+ },
107
+ replyWithMarkdownV2(this: Context, markdown, extra) {
108
+ this.assert(this.chat, 'replyWithMarkdownV2')
109
+ return this.telegram.sendMessage(this.chat.id, markdown, {
110
+ parse_mode: 'MarkdownV2',
111
+ ...makeReply(this, extra),
112
+ })
113
+ },
114
+ replyWithMediaGroup(this: Context, media, extra) {
115
+ this.assert(this.chat, 'replyWithMediaGroup')
116
+ return this.telegram.sendMediaGroup(
117
+ this.chat.id,
118
+ media,
119
+ makeReply(this, extra)
120
+ )
121
+ },
122
+ replyWithPhoto(this: Context, photo, extra) {
123
+ this.assert(this.chat, 'replyWithPhoto')
124
+ return this.telegram.sendPhoto(this.chat.id, photo, makeReply(this, extra))
125
+ },
126
+ replyWithPoll(this: Context, question, options, extra) {
127
+ this.assert(this.chat, 'replyWithPoll')
128
+ return this.telegram.sendPoll(
129
+ this.chat.id,
130
+ question,
131
+ options,
132
+ makeReply(this, extra)
133
+ )
134
+ },
135
+ replyWithQuiz(this: Context, question, options, extra) {
136
+ this.assert(this.chat, 'replyWithQuiz')
137
+ return this.telegram.sendQuiz(
138
+ this.chat.id,
139
+ question,
140
+ options,
141
+ makeReply(this, extra)
142
+ )
143
+ },
144
+ replyWithSticker(this: Context, sticker, extra) {
145
+ this.assert(this.chat, 'replyWithSticker')
146
+ return this.telegram.sendSticker(
147
+ this.chat.id,
148
+ sticker,
149
+ makeReply(this, extra)
150
+ )
151
+ },
152
+ replyWithVenue(this: Context, latitude, longitude, title, address, extra) {
153
+ this.assert(this.chat, 'replyWithVenue')
154
+ return this.telegram.sendVenue(
155
+ this.chat.id,
156
+ latitude,
157
+ longitude,
158
+ title,
159
+ address,
160
+ makeReply(this, extra)
161
+ )
162
+ },
163
+ replyWithVideo(this: Context, video, extra) {
164
+ this.assert(this.chat, 'replyWithVideo')
165
+ return this.telegram.sendVideo(this.chat.id, video, makeReply(this, extra))
166
+ },
167
+ replyWithVideoNote(this: Context, videoNote, extra) {
168
+ this.assert(this.chat, 'replyWithVideoNote')
169
+ return this.telegram.sendVideoNote(
170
+ this.chat.id,
171
+ videoNote,
172
+ makeReply(this, extra)
173
+ )
174
+ },
175
+ replyWithVoice(this: Context, voice, extra) {
176
+ this.assert(this.chat, 'replyWithVoice')
177
+ return this.telegram.sendVoice(this.chat.id, voice, makeReply(this, extra))
178
+ },
179
+ replyWithRichMessage(this: Context, options) {
180
+ this.assert(this.chat, 'replyWithRichMessage')
181
+ const { text, parseMode = 'HTML', buttons, disableLinkPreview, extra } = options
182
+ return this.telegram.sendMessage(this.chat.id, text, makeReply(this, {
183
+ parse_mode: parseMode,
184
+ link_preview_options: disableLinkPreview ? { is_disabled: true } : undefined,
185
+ reply_markup: buttons?.length ? { inline_keyboard: buttons } : undefined,
186
+ ...extra,
187
+ }))
188
+ },
189
+ replyWithRichMessageContent(this: Context, richMessage: InputRichMessage, extra?: ExtraSendRichMessage) {
190
+ this.assert(this.chat, 'replyWithRichMessageContent')
191
+ return this.telegram.sendRichMessage(this.chat.id, richMessage, makeReply(this, extra))
192
+ },
193
+ }
194
+
195
+ /**
196
+ * Sets up Context to use the new reply methods.
197
+ * This middleware makes `ctx.reply()` and `ctx.replyWith*()` methods will actually reply to the message they are replying to.
198
+ * Use `ctx.sendMessage()` to send a message in chat without replying to it.
199
+ *
200
+ * If the message to reply is deleted, `reply()` will send a normal message.
201
+ * If the update is not a message and we are unable to reply, `reply()` will send a normal message.
202
+ */
203
+ export function useNewReplies<C extends Context>(): Middleware<C> {
204
+ return (ctx, next) => {
205
+ ctx.reply = replyContext.reply
206
+ ctx.replyWithPhoto = replyContext.replyWithPhoto
207
+ ctx.replyWithMediaGroup = replyContext.replyWithMediaGroup
208
+ ctx.replyWithAudio = replyContext.replyWithAudio
209
+ ctx.replyWithDice = replyContext.replyWithDice
210
+ ctx.replyWithDocument = replyContext.replyWithDocument
211
+ ctx.replyWithSticker = replyContext.replyWithSticker
212
+ ctx.replyWithVideo = replyContext.replyWithVideo
213
+ ctx.replyWithAnimation = replyContext.replyWithAnimation
214
+ ctx.replyWithVideoNote = replyContext.replyWithVideoNote
215
+ ctx.replyWithInvoice = replyContext.replyWithInvoice
216
+ ctx.replyWithGame = replyContext.replyWithGame
217
+ ctx.replyWithVoice = replyContext.replyWithVoice
218
+ ctx.replyWithPoll = replyContext.replyWithPoll
219
+ ctx.replyWithQuiz = replyContext.replyWithQuiz
220
+ ctx.replyWithChatAction = replyContext.replyWithChatAction
221
+ ctx.replyWithLocation = replyContext.replyWithLocation
222
+ ctx.replyWithVenue = replyContext.replyWithVenue
223
+ ctx.replyWithContact = replyContext.replyWithContact
224
+ ctx.replyWithMarkdown = replyContext.replyWithMarkdown
225
+ ctx.replyWithMarkdownV2 = replyContext.replyWithMarkdownV2
226
+ ctx.replyWithHTML = replyContext.replyWithHTML
227
+ ctx.replyWithRichMessage = replyContext.replyWithRichMessage
228
+ ctx.replyWithRichMessageContent = replyContext.replyWithRichMessageContent
229
+ return next()
230
+ }
231
+ }
package/src/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ export { Telegraf } from './telegraf'
2
+ export { Context, NarrowedContext } from './context'
3
+ export { Composer } from './composer'
4
+ export { Middleware, MiddlewareFn, MiddlewareObj } from './middleware'
5
+ export { Router } from './router'
6
+ export { TelegramError } from './core/network/error'
7
+ export { Telegram } from './telegram'
8
+
9
+ export * as Types from './telegram-types'
10
+ export * as Markup from './markup'
11
+ export * as Input from './input'
12
+ export * as Format from './format'
13
+
14
+ export { deunionize } from './core/helpers/deunionize'
15
+ export { session, MemorySessionStore, SessionStore } from './session'
16
+
17
+ export * as Scenes from './scenes'
18
+ export * as RichMessage from './core/types/rich-message'
19
+
20
+ export { SmartQueue } from './core/helpers/smart-queue'
21
+ export { AIStreamAdapter } from './core/helpers/ai-stream'
22
+ export { sanitizeRichHtml } from './core/helpers/rich-sanitizer'
23
+ export { PaginatedBuilder } from './paginated'
24
+ export { FormScene } from './scenes/form-scene'
25
+ export { InputBox } from './core/helpers/input-box'
26
+
27
+
package/src/input.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { InputFile } from './core/types/typegram'
2
+
3
+ /**
4
+ * The local file specified by path will be uploaded to Telegram using multipart/form-data.
5
+ *
6
+ * 10 MB max size for photos, 50 MB for other files.
7
+ */
8
+ // prettier-ignore
9
+ export const fromLocalFile = (path: string, filename?: string): InputFile => ({ source: path, filename })
10
+
11
+ /**
12
+ * The buffer will be uploaded as file to Telegram using multipart/form-data.
13
+ *
14
+ * 10 MB max size for photos, 50 MB for other files.
15
+ */
16
+ // prettier-ignore
17
+ export const fromBuffer = (buffer: Buffer, filename?: string): InputFile => ({ source: buffer, filename })
18
+
19
+ /**
20
+ * Contents of the stream will be uploaded as file to Telegram using multipart/form-data.
21
+ *
22
+ * 10 MB max size for photos, 50 MB for other files.
23
+ */
24
+ // prettier-ignore
25
+ export const fromReadableStream = (stream: NodeJS.ReadableStream, filename?: string): InputFile => ({ source: stream, filename })
26
+
27
+ /**
28
+ * Contents of the URL will be streamed to Telegram.
29
+ *
30
+ * 10 MB max size for photos, 50 MB for other files.
31
+ */
32
+ // prettier-ignore
33
+ export const fromURLStream = (url: string | URL, filename?: string): InputFile => ({ url: url.toString(), filename })
34
+
35
+ /**
36
+ * Provide Telegram with an HTTP URL for the file to be sent.
37
+ * Telegram will download and send the file.
38
+ *
39
+ * * The target file must have the correct MIME type (e.g., audio/mpeg for `sendAudio`, etc.).
40
+ * * `sendDocument` with URL will currently only work for GIF, PDF and ZIP files.
41
+ * * To use `sendVoice`, the file must have the type audio/ogg and be no more than 1MB in size.
42
+ * 1-20MB voice notes will be sent as files.
43
+ *
44
+ * 5 MB max size for photos and 20 MB max for other types of content.
45
+ */
46
+ export const fromURL = (url: string | URL): string => url.toString()
47
+
48
+ /**
49
+ * If the file is already stored somewhere on the Telegram servers, you don't need to reupload it:
50
+ * each file object has a file_id field, simply pass this file_id as a parameter instead of uploading.
51
+ *
52
+ * It is not possible to change the file type when resending by file_id.
53
+ *
54
+ * It is not possible to resend thumbnails using file_id.
55
+ * They have to be uploaded using one of the other Input methods.
56
+ *
57
+ * There are no limits for files sent this way.
58
+ */
59
+ export const fromFileId = (fileId: string): string => fileId
package/src/markup.js ADDED
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.inlineKeyboard = exports.keyboard = exports.forceReply = exports.removeKeyboard = exports.button = exports.Markup = void 0;
27
+ const check_1 = require("./core/helpers/check");
28
+ class Markup {
29
+ constructor(reply_markup) {
30
+ this.reply_markup = reply_markup;
31
+ }
32
+ selective(value = true) {
33
+ return new Markup(Object.assign(Object.assign({}, this.reply_markup), { selective: value }));
34
+ }
35
+ placeholder(placeholder) {
36
+ return new Markup(Object.assign(Object.assign({}, this.reply_markup), { input_field_placeholder: placeholder }));
37
+ }
38
+ resize(value = true) {
39
+ return new Markup(Object.assign(Object.assign({}, this.reply_markup), { resize_keyboard: value }));
40
+ }
41
+ oneTime(value = true) {
42
+ return new Markup(Object.assign(Object.assign({}, this.reply_markup), { one_time_keyboard: value }));
43
+ }
44
+ persistent(value = true) {
45
+ return new Markup(Object.assign(Object.assign({}, this.reply_markup), { is_persistent: value }));
46
+ }
47
+ }
48
+ exports.Markup = Markup;
49
+ exports.button = __importStar(require("./button"));
50
+ function removeKeyboard() {
51
+ return new Markup({ remove_keyboard: true });
52
+ }
53
+ exports.removeKeyboard = removeKeyboard;
54
+ function forceReply() {
55
+ return new Markup({ force_reply: true });
56
+ }
57
+ exports.forceReply = forceReply;
58
+ function keyboard(buttons, options) {
59
+ const keyboard = buildKeyboard(buttons, Object.assign({ columns: 1 }, options));
60
+ return new Markup({ keyboard });
61
+ }
62
+ exports.keyboard = keyboard;
63
+ function inlineKeyboard(buttons, options) {
64
+ const inlineKeyboard = buildKeyboard(buttons, Object.assign({ columns: buttons.length }, options));
65
+ return new Markup({ inline_keyboard: inlineKeyboard });
66
+ }
67
+ exports.inlineKeyboard = inlineKeyboard;
68
+ function buildKeyboard(buttons, options) {
69
+ const result = [];
70
+ if (!Array.isArray(buttons)) {
71
+ return result;
72
+ }
73
+ if ((0, check_1.is2D)(buttons)) {
74
+ return buttons.map((row) => row.filter((button) => !button.hide));
75
+ }
76
+ const wrapFn = options.wrap !== undefined
77
+ ? options.wrap
78
+ : (_btn, _index, currentRow) => currentRow.length >= options.columns;
79
+ let currentRow = [];
80
+ let index = 0;
81
+ for (const btn of buttons.filter((button) => !button.hide)) {
82
+ if (wrapFn(btn, index, currentRow) && currentRow.length > 0) {
83
+ result.push(currentRow);
84
+ currentRow = [];
85
+ }
86
+ currentRow.push(btn);
87
+ index++;
88
+ }
89
+ if (currentRow.length > 0) {
90
+ result.push(currentRow);
91
+ }
92
+ return result;
93
+ }