@grom.js/effect-tg 0.7.0 → 0.9.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 (99) hide show
  1. package/README.md +162 -5
  2. package/dist/BotApi.d.ts +10 -12
  3. package/dist/BotApi.d.ts.map +1 -1
  4. package/dist/BotApi.js +2 -2
  5. package/dist/BotApi.js.map +1 -1
  6. package/dist/BotApiError.d.ts +46 -71
  7. package/dist/BotApiError.d.ts.map +1 -1
  8. package/dist/BotApiError.js +59 -41
  9. package/dist/BotApiError.js.map +1 -1
  10. package/dist/BotApiTransport.d.ts +10 -17
  11. package/dist/BotApiTransport.d.ts.map +1 -1
  12. package/dist/BotApiTransport.js +2 -7
  13. package/dist/BotApiTransport.js.map +1 -1
  14. package/dist/BotApiUrl.d.ts +6 -8
  15. package/dist/BotApiUrl.d.ts.map +1 -1
  16. package/dist/BotApiUrl.js.map +1 -1
  17. package/dist/Content.d.ts.map +1 -1
  18. package/dist/Dialog.d.ts +96 -41
  19. package/dist/Dialog.d.ts.map +1 -1
  20. package/dist/Dialog.js +60 -25
  21. package/dist/Dialog.js.map +1 -1
  22. package/dist/File.d.ts +1 -2
  23. package/dist/File.d.ts.map +1 -1
  24. package/dist/File.js +1 -1
  25. package/dist/File.js.map +1 -1
  26. package/dist/Markup.d.ts.map +1 -1
  27. package/dist/Runner.d.ts +1 -1
  28. package/dist/Runner.d.ts.map +1 -1
  29. package/dist/Send.d.ts +57 -130
  30. package/dist/Send.d.ts.map +1 -1
  31. package/dist/Send.js +65 -128
  32. package/dist/Send.js.map +1 -1
  33. package/dist/Text.d.ts.map +1 -1
  34. package/dist/internal/botApi.d.ts +3 -1
  35. package/dist/internal/botApi.d.ts.map +1 -1
  36. package/dist/internal/botApi.gen.d.ts +6501 -0
  37. package/dist/internal/botApi.gen.d.ts.map +1 -0
  38. package/dist/internal/botApi.gen.js +2 -0
  39. package/dist/internal/botApi.gen.js.map +1 -0
  40. package/dist/internal/botApi.js +2 -6
  41. package/dist/internal/botApi.js.map +1 -1
  42. package/dist/internal/botApiError.d.ts +5 -2
  43. package/dist/internal/botApiError.d.ts.map +1 -1
  44. package/dist/internal/botApiError.js +8 -18
  45. package/dist/internal/botApiError.js.map +1 -1
  46. package/dist/internal/botApiTransport.d.ts +5 -2
  47. package/dist/internal/botApiTransport.d.ts.map +1 -1
  48. package/dist/internal/botApiTransport.js +14 -10
  49. package/dist/internal/botApiTransport.js.map +1 -1
  50. package/dist/internal/dialog.d.ts +27 -10
  51. package/dist/internal/dialog.d.ts.map +1 -1
  52. package/dist/internal/dialog.js +88 -14
  53. package/dist/internal/dialog.js.map +1 -1
  54. package/dist/internal/file.d.ts +1 -1
  55. package/dist/internal/file.d.ts.map +1 -1
  56. package/dist/internal/file.js +1 -1
  57. package/dist/internal/file.js.map +1 -1
  58. package/dist/internal/runner.d.ts +4 -5
  59. package/dist/internal/runner.d.ts.map +1 -1
  60. package/dist/internal/runner.js +14 -19
  61. package/dist/internal/runner.js.map +1 -1
  62. package/dist/internal/send.d.ts +4 -4
  63. package/dist/internal/send.d.ts.map +1 -1
  64. package/dist/internal/send.js +62 -51
  65. package/dist/internal/send.js.map +1 -1
  66. package/package.json +12 -10
  67. package/src/BotApi.ts +38 -31
  68. package/src/BotApiError.ts +109 -63
  69. package/src/BotApiTransport.ts +18 -20
  70. package/src/BotApiUrl.ts +6 -8
  71. package/src/Content.ts +14 -14
  72. package/src/Dialog.ts +164 -42
  73. package/src/File.ts +3 -4
  74. package/src/Markup.ts +5 -5
  75. package/src/Send.ts +114 -202
  76. package/src/Text.ts +5 -5
  77. package/src/internal/botApi.gen.ts +6783 -0
  78. package/src/internal/botApi.ts +7 -11
  79. package/src/internal/botApiError.ts +15 -20
  80. package/src/internal/botApiTransport.ts +25 -17
  81. package/src/internal/dialog.ts +109 -26
  82. package/src/internal/file.ts +1 -1
  83. package/src/internal/runner.ts +34 -38
  84. package/src/internal/send.ts +161 -132
  85. package/dist/internal/botApiMethods.gen.d.ts +0 -2026
  86. package/dist/internal/botApiMethods.gen.d.ts.map +0 -1
  87. package/dist/internal/botApiMethods.gen.js +0 -2
  88. package/dist/internal/botApiMethods.gen.js.map +0 -1
  89. package/dist/internal/botApiShape.gen.d.ts +0 -398
  90. package/dist/internal/botApiShape.gen.d.ts.map +0 -1
  91. package/dist/internal/botApiShape.gen.js +0 -2
  92. package/dist/internal/botApiShape.gen.js.map +0 -1
  93. package/dist/internal/botApiTypes.gen.d.ts +0 -3903
  94. package/dist/internal/botApiTypes.gen.d.ts.map +0 -1
  95. package/dist/internal/botApiTypes.gen.js +0 -2
  96. package/dist/internal/botApiTypes.gen.js.map +0 -1
  97. package/src/internal/botApiMethods.gen.ts +0 -2027
  98. package/src/internal/botApiShape.gen.ts +0 -398
  99. package/src/internal/botApiTypes.gen.ts +0 -4178
package/src/Send.ts CHANGED
@@ -4,9 +4,8 @@
4
4
 
5
5
  import type * as BotApi from './BotApi.ts'
6
6
  import type * as BotApiError from './BotApiError.ts'
7
- import type * as BotApiTransport from './BotApiTransport.ts'
8
7
  import type * as Content from './Content.ts'
9
- import type * as Dialog_ from './Dialog.ts'
8
+ import type * as Dialog from './Dialog.ts'
10
9
  import type * as Markup from './Markup.ts'
11
10
  import * as Context from 'effect/Context'
12
11
  import * as Data from 'effect/Data'
@@ -14,104 +13,66 @@ import * as Effect from 'effect/Effect'
14
13
  import * as Effectable from 'effect/Effectable'
15
14
  import * as Function from 'effect/Function'
16
15
  import * as Inspectable from 'effect/Inspectable'
17
- import * as Pipeable from 'effect/Pipeable'
18
16
  import * as internal from './internal/send.ts'
19
17
 
20
- // ─── Type ID ──────────────────────────────────────────────────────
21
-
22
- const MessageToSendTypeId: unique symbol = Symbol.for('@grom.js/effect-tg/Send/MessageToSend')
23
-
24
- // ─── Services ─────────────────────────────────────────────────────
25
-
26
- /**
27
- * Service providing the target dialog for sending messages.
28
- */
29
- export class Dialog extends Context.Tag('@grom.js/effect-tg/Send/Dialog')<
30
- Dialog,
31
- Dialog_.Dialog
32
- >() {}
33
-
34
- // ─── Options ──────────────────────────────────────────────────────
35
-
36
- /**
37
- * Options for sending a message.
38
- *
39
- * @see {@link https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1message_send_options.html td.td_api.messageSendOptions}
40
- */
41
- export class Options extends Data.Class<{
42
- disableNotification?: boolean
43
- protectContent?: boolean
44
- allowPaidBroadcast?: boolean
45
- }> {}
46
-
47
- // ─── Direct Send ──────────────────────────────────────────────────
18
+ // =============================================================================
19
+ // Send Methods
20
+ // =============================================================================
48
21
 
49
22
  /**
50
- * Sends a message directly with explicit parameters.
51
- *
52
- * Prefer {@linkcode message} for more composability.
53
- *
54
- * Example:
55
- * ```ts
56
- * yield* Send.sendMessage({
57
- * content: new Content.Text({
58
- * text,
59
- * linkPreview: Option.none(),
60
- * }),
61
- * dialog: new Dialog.UserId(userId),
62
- * options: new Send.Options({
63
- * protectContent: true,
64
- * }),
65
- * })
66
- * ```
67
- *
68
- * @see {@link https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1send_message.html td.td_api.sendMessage}
23
+ * Sends a message by calling the appropriate `send*` Bot API method
24
+ * and passing the required parameters.
69
25
  */
70
26
  export const sendMessage: (params: {
71
27
  content: Content.Content
72
- dialog: Dialog_.Dialog
28
+ dialog: Dialog.Dialog | Dialog.DialogId
73
29
  options?: Options
74
30
  markup?: Markup.Markup
75
31
  }) => Effect.Effect<
76
32
  BotApi.Types.Message,
77
- BotApiError.BotApiError | BotApiTransport.BotApiTransportError,
33
+ BotApiError.BotApiError,
78
34
  BotApi.BotApi
79
35
  > = internal.sendMessage
80
36
 
81
- // ─── MessageToSend ────────────────────────────────────────────────
37
+ // =============================================================================
38
+ // MessageToSend
39
+ // =============================================================================
82
40
 
83
- type MessageToSendEffect = Effect.Effect<
84
- BotApi.Types.Message,
85
- BotApiError.BotApiError | BotApiTransport.BotApiTransportError,
86
- BotApi.BotApi | Dialog
87
- >
41
+ export const MessageToSendTypeId: unique symbol = Symbol.for('@grom.js/effect-tg/Send/MessageToSend')
42
+
43
+ export type MessageToSendTypeId = typeof MessageToSendTypeId
88
44
 
89
45
  /**
90
- * A message prepared to be sent.
46
+ * Message prepared to be sent.
91
47
  */
92
48
  export interface MessageToSend extends
93
49
  Inspectable.Inspectable,
94
- MessageToSendEffect
50
+ Effect.Effect<
51
+ BotApi.Types.Message,
52
+ BotApiError.BotApiError,
53
+ BotApi.BotApi | TargetDialog
54
+ >
95
55
  {
96
56
  readonly [MessageToSendTypeId]: typeof MessageToSendTypeId
97
57
  readonly content: Content.Content
98
- readonly options: Options
99
- readonly markup: Markup.Markup | undefined
58
+ readonly markup?: Markup.Markup
59
+ readonly options?: Options
100
60
  }
101
61
 
102
- const Proto = {
103
- [MessageToSendTypeId]: MessageToSendTypeId,
104
- ...Effectable.CommitPrototype,
62
+ const MessageToSendProto = {
105
63
  ...Inspectable.BaseProto,
64
+ ...Effectable.CommitPrototype,
106
65
 
107
- commit(this: MessageToSend): MessageToSendEffect {
66
+ [MessageToSendTypeId]: MessageToSendTypeId,
67
+
68
+ commit(this: MessageToSend) {
108
69
  return Effect.flatMap(
109
- Dialog,
70
+ TargetDialog,
110
71
  dialog => sendMessage({
111
72
  dialog,
112
73
  content: this.content,
113
- options: this.options,
114
74
  markup: this.markup,
75
+ options: this.options,
115
76
  }),
116
77
  )
117
78
  },
@@ -120,99 +81,108 @@ const Proto = {
120
81
  return {
121
82
  _id: this[MessageToSendTypeId].description,
122
83
  content: this.content,
123
- options: this.options,
124
84
  markup: this.markup,
85
+ options: this.options,
125
86
  }
126
87
  },
127
-
128
- pipe() {
129
- // eslint-disable-next-line prefer-rest-params
130
- return Pipeable.pipeArguments(this, arguments)
131
- },
132
88
  }
133
89
 
134
- const make = (args: {
135
- content: Content.Content
136
- options?: Options
90
+ /**
91
+ * Creates a message prepared to be sent with the specified content
92
+ * and optional parameters.
93
+ */
94
+ export const message = (content: Content.Content, params?: {
137
95
  markup?: Markup.Markup
96
+ options?: Options
138
97
  }): MessageToSend => {
139
- const self = Object.create(Proto)
140
- self.content = args.content
141
- self.options = args.options
142
- self.markup = args.markup
98
+ const self = Object.create(MessageToSendProto)
99
+ self.content = content
100
+ self.markup = params?.markup
101
+ self.options = params?.options
143
102
  return self
144
103
  }
145
104
 
146
- // ─── Constructors ─────────────────────────────────────────────────
105
+ // =============================================================================
106
+ // TargetDialog
107
+ // =============================================================================
147
108
 
148
109
  /**
149
- * Creates a message to send with the given content.
150
- *
151
- * Example:
152
- * ```ts
153
- * yield* Send.message(content).pipe(
154
- * Send.withProtection,
155
- * Send.to(dialog),
156
- * )
157
- * ```
110
+ * Target dialog for sending messages.
158
111
  */
159
- export const message = (
160
- content: Content.Content,
161
- ): MessageToSend => make({ content })
162
-
163
- // ─── Dialog Provider ──────────────────────────────────────────────
112
+ export class TargetDialog extends Context.Tag('@grom.js/effect-tg/Send/TargetDialog')<
113
+ TargetDialog,
114
+ Dialog.Dialog | Dialog.DialogId
115
+ >() {}
164
116
 
117
+ /**
118
+ * Provides the target dialog for sending messages.
119
+ */
165
120
  export const to: {
166
- /**
167
- * Provides the target dialog for sending messages.
168
- *
169
- * Example:
170
- * ```ts
171
- * // Per-message
172
- * yield* Send.message(content).pipe(
173
- * Send.withProtection,
174
- * Send.to(dialog),
175
- * )
176
- *
177
- * // For entire handler (multiple sends)
178
- * const handler = Effect.gen(function* () {
179
- * yield* Send.message(content1)
180
- * yield* Send.message(content2)
181
- * }).pipe(Send.to(dialog))
182
- * ```
183
- */
184
- (dialog: Dialog_.Dialog): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Dialog>>
185
- <A, E, R>(effect: Effect.Effect<A, E, R>, dialog: Dialog_.Dialog): Effect.Effect<A, E, Exclude<R, Dialog>>
121
+ (dialog: Dialog.Dialog): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, TargetDialog>>
122
+ <A, E, R>(effect: Effect.Effect<A, E, R>, dialog: Dialog.Dialog): Effect.Effect<A, E, Exclude<R, TargetDialog>>
186
123
  } = Function.dual(2, <A, E, R>(
187
124
  effect: Effect.Effect<A, E, R>,
188
- dialog: Dialog_.Dialog,
189
- ): Effect.Effect<A, E, Exclude<R, Dialog>> => (
190
- Effect.provideService(effect, Dialog, dialog)
125
+ dialog: Dialog.Dialog,
126
+ ): Effect.Effect<A, E, Exclude<R, TargetDialog>> => (
127
+ Effect.provideService(effect, TargetDialog, dialog)
191
128
  ))
192
129
 
193
- // ─── Options Combinators ──────────────────────────────────────────
130
+ // =============================================================================
131
+ // Reply Markup
132
+ // =============================================================================
133
+
134
+ /**
135
+ * Sets the reply markup for the message.
136
+ */
137
+ export const withMarkup: {
138
+ (markup: Markup.Markup): (self: MessageToSend) => MessageToSend
139
+ (self: MessageToSend, markup: Markup.Markup): MessageToSend
140
+ } = Function.dual(2, (
141
+ self: MessageToSend,
142
+ markup: Markup.Markup,
143
+ ): MessageToSend => (
144
+ message(self.content, {
145
+ markup,
146
+ options: self.options,
147
+ })
148
+ ))
149
+
150
+ /**
151
+ * Removes the reply markup from the message.
152
+ */
153
+ export const withoutMarkup: (
154
+ self: MessageToSend,
155
+ ) => MessageToSend = self => message(self.content, {
156
+ markup: undefined,
157
+ options: self.options,
158
+ })
159
+
160
+ // =============================================================================
161
+ // Send Options
162
+ // =============================================================================
163
+
164
+ /**
165
+ * Options for sending a message.
166
+ */
167
+ export class Options extends Data.Class<{
168
+ disableNotification?: boolean
169
+ protectContent?: boolean
170
+ allowPaidBroadcast?: boolean
171
+ }> {}
172
+
173
+ export const options = (args: {
174
+ disableNotification?: boolean
175
+ protectContent?: boolean
176
+ allowPaidBroadcast?: boolean
177
+ }): Options => new Options(args)
194
178
 
195
179
  /**
196
180
  * Modifies the options for sending a message by merging with existing options.
197
181
  *
198
- * Example:
199
- * ```ts
200
- * yield* Send.message(content).pipe(
201
- * Send.withOptions({
202
- * disableNotification: true,
203
- * protectContent: true,
204
- * }),
205
- * Send.to(dialog),
206
- * )
207
- * ```
208
- *
209
182
  * Available shortcuts:
210
- * - {@linkcode withoutNotification}
211
- * - {@linkcode withNotification}
212
- * - {@linkcode withoutContentProtection}
213
- * - {@linkcode withContentProtection}
214
- * - {@linkcode withoutPaidBroadcast}
215
- * - {@linkcode withPaidBroadcast}
183
+ * - {@linkcode withNotification} / {@linkcode withoutNotification}
184
+ * - {@linkcode withContentProtection} / {@linkcode withoutContentProtection}
185
+ * - {@linkcode withPaidBroadcast} / {@linkcode withoutPaidBroadcast}
216
186
  */
217
187
  export const withOptions: {
218
188
  (options: Options): (self: MessageToSend) => MessageToSend
@@ -221,22 +191,17 @@ export const withOptions: {
221
191
  self: MessageToSend,
222
192
  options: Options,
223
193
  ): MessageToSend => (
224
- make(
225
- {
226
- content: self.content,
227
- options: new Options({
228
- ...self.options,
229
- ...options,
230
- }),
231
- markup: self.markup,
232
- },
233
- )
194
+ message(self.content, {
195
+ markup: self.markup,
196
+ options: new Options({
197
+ ...self.options,
198
+ ...options,
199
+ }),
200
+ })
234
201
  ))
235
202
 
236
203
  /**
237
204
  * Disables notification for the message.
238
- *
239
- * Shortcut for `withOptions({ disableNotification: true })`.
240
205
  */
241
206
  export const withoutNotification: (
242
207
  self: MessageToSend,
@@ -244,8 +209,6 @@ export const withoutNotification: (
244
209
 
245
210
  /**
246
211
  * Enables notification for the message.
247
- *
248
- * Shortcut for `withOptions({ disableNotification: false })`.
249
212
  */
250
213
  export const withNotification: (
251
214
  self: MessageToSend,
@@ -253,8 +216,6 @@ export const withNotification: (
253
216
 
254
217
  /**
255
218
  * Allows message content to be saved and forwarded.
256
- *
257
- * Shortcut for `withOptions({ protectContent: false })`.
258
219
  */
259
220
  export const withoutContentProtection: (
260
221
  self: MessageToSend,
@@ -262,8 +223,6 @@ export const withoutContentProtection: (
262
223
 
263
224
  /**
264
225
  * Protects message content from saving and forwarding.
265
- *
266
- * Shortcut for `withOptions({ protectContent: true })`.
267
226
  */
268
227
  export const withContentProtection: (
269
228
  self: MessageToSend,
@@ -271,8 +230,6 @@ export const withContentProtection: (
271
230
 
272
231
  /**
273
232
  * Disallows paid broadcast for the message.
274
- *
275
- * Shortcut for `withOptions({ allowPaidBroadcast: false })`.
276
233
  */
277
234
  export const withoutPaidBroadcast: (
278
235
  self: MessageToSend,
@@ -280,52 +237,7 @@ export const withoutPaidBroadcast: (
280
237
 
281
238
  /**
282
239
  * Allows paid broadcast for the message.
283
- *
284
- * Shortcut for `withOptions({ allowPaidBroadcast: true })`.
285
240
  */
286
241
  export const withPaidBroadcast: (
287
242
  self: MessageToSend,
288
243
  ) => MessageToSend = withOptions({ allowPaidBroadcast: true })
289
-
290
- // ─── Markup Combinators ──────────────────────────────────────────
291
-
292
- /**
293
- * Sets the reply markup for the message.
294
- *
295
- * Example:
296
- * ```ts
297
- * yield* Send.message(content).pipe(
298
- * Send.withMarkup(
299
- * new Markup.ForceReply({
300
- * selective: false,
301
- * inputPlaceholder: Option.some("effect-tg or grammY?"),
302
- * }),
303
- * ),
304
- * Send.to(dialog),
305
- * )
306
- * ```
307
- */
308
- export const withMarkup: {
309
- (markup: Markup.Markup): (self: MessageToSend) => MessageToSend
310
- (self: MessageToSend, markup: Markup.Markup): MessageToSend
311
- } = Function.dual(2, (
312
- self: MessageToSend,
313
- markup: Markup.Markup,
314
- ): MessageToSend => (
315
- make({
316
- content: self.content,
317
- options: self.options,
318
- markup,
319
- })
320
- ))
321
-
322
- /**
323
- * Removes the reply markup from the message.
324
- */
325
- export const withoutMarkup: (
326
- self: MessageToSend,
327
- ) => MessageToSend = self => make({
328
- content: self.content,
329
- options: self.options,
330
- markup: undefined,
331
- })
package/src/Text.ts CHANGED
@@ -5,11 +5,11 @@ import * as Data from 'effect/Data'
5
5
  /**
6
6
  * Formatted text.
7
7
  */
8
- export type Text
9
- = | Plain
10
- | Html
11
- | Markdown
12
- | Tgx
8
+ export type Text =
9
+ | Plain
10
+ | Html
11
+ | Markdown
12
+ | Tgx
13
13
 
14
14
  export class Plain extends Data.TaggedClass('Plain')<{
15
15
  text: string