@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.
- package/README.md +162 -5
- package/dist/BotApi.d.ts +10 -12
- package/dist/BotApi.d.ts.map +1 -1
- package/dist/BotApi.js +2 -2
- package/dist/BotApi.js.map +1 -1
- package/dist/BotApiError.d.ts +46 -71
- package/dist/BotApiError.d.ts.map +1 -1
- package/dist/BotApiError.js +59 -41
- package/dist/BotApiError.js.map +1 -1
- package/dist/BotApiTransport.d.ts +10 -17
- package/dist/BotApiTransport.d.ts.map +1 -1
- package/dist/BotApiTransport.js +2 -7
- package/dist/BotApiTransport.js.map +1 -1
- package/dist/BotApiUrl.d.ts +6 -8
- package/dist/BotApiUrl.d.ts.map +1 -1
- package/dist/BotApiUrl.js.map +1 -1
- package/dist/Content.d.ts.map +1 -1
- package/dist/Dialog.d.ts +96 -41
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Dialog.js +60 -25
- package/dist/Dialog.js.map +1 -1
- package/dist/File.d.ts +1 -2
- package/dist/File.d.ts.map +1 -1
- package/dist/File.js +1 -1
- package/dist/File.js.map +1 -1
- package/dist/Markup.d.ts.map +1 -1
- package/dist/Runner.d.ts +1 -1
- package/dist/Runner.d.ts.map +1 -1
- package/dist/Send.d.ts +57 -130
- package/dist/Send.d.ts.map +1 -1
- package/dist/Send.js +65 -128
- package/dist/Send.js.map +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/internal/botApi.d.ts +3 -1
- package/dist/internal/botApi.d.ts.map +1 -1
- package/dist/internal/botApi.gen.d.ts +6501 -0
- package/dist/internal/botApi.gen.d.ts.map +1 -0
- package/dist/internal/botApi.gen.js +2 -0
- package/dist/internal/botApi.gen.js.map +1 -0
- package/dist/internal/botApi.js +2 -6
- package/dist/internal/botApi.js.map +1 -1
- package/dist/internal/botApiError.d.ts +5 -2
- package/dist/internal/botApiError.d.ts.map +1 -1
- package/dist/internal/botApiError.js +8 -18
- package/dist/internal/botApiError.js.map +1 -1
- package/dist/internal/botApiTransport.d.ts +5 -2
- package/dist/internal/botApiTransport.d.ts.map +1 -1
- package/dist/internal/botApiTransport.js +14 -10
- package/dist/internal/botApiTransport.js.map +1 -1
- package/dist/internal/dialog.d.ts +27 -10
- package/dist/internal/dialog.d.ts.map +1 -1
- package/dist/internal/dialog.js +88 -14
- package/dist/internal/dialog.js.map +1 -1
- package/dist/internal/file.d.ts +1 -1
- package/dist/internal/file.d.ts.map +1 -1
- package/dist/internal/file.js +1 -1
- package/dist/internal/file.js.map +1 -1
- package/dist/internal/runner.d.ts +4 -5
- package/dist/internal/runner.d.ts.map +1 -1
- package/dist/internal/runner.js +14 -19
- package/dist/internal/runner.js.map +1 -1
- package/dist/internal/send.d.ts +4 -4
- package/dist/internal/send.d.ts.map +1 -1
- package/dist/internal/send.js +62 -51
- package/dist/internal/send.js.map +1 -1
- package/package.json +12 -10
- package/src/BotApi.ts +38 -31
- package/src/BotApiError.ts +109 -63
- package/src/BotApiTransport.ts +18 -20
- package/src/BotApiUrl.ts +6 -8
- package/src/Content.ts +14 -14
- package/src/Dialog.ts +164 -42
- package/src/File.ts +3 -4
- package/src/Markup.ts +5 -5
- package/src/Send.ts +114 -202
- package/src/Text.ts +5 -5
- package/src/internal/botApi.gen.ts +6783 -0
- package/src/internal/botApi.ts +7 -11
- package/src/internal/botApiError.ts +15 -20
- package/src/internal/botApiTransport.ts +25 -17
- package/src/internal/dialog.ts +109 -26
- package/src/internal/file.ts +1 -1
- package/src/internal/runner.ts +34 -38
- package/src/internal/send.ts +161 -132
- package/dist/internal/botApiMethods.gen.d.ts +0 -2026
- package/dist/internal/botApiMethods.gen.d.ts.map +0 -1
- package/dist/internal/botApiMethods.gen.js +0 -2
- package/dist/internal/botApiMethods.gen.js.map +0 -1
- package/dist/internal/botApiShape.gen.d.ts +0 -398
- package/dist/internal/botApiShape.gen.d.ts.map +0 -1
- package/dist/internal/botApiShape.gen.js +0 -2
- package/dist/internal/botApiShape.gen.js.map +0 -1
- package/dist/internal/botApiTypes.gen.d.ts +0 -3903
- package/dist/internal/botApiTypes.gen.d.ts.map +0 -1
- package/dist/internal/botApiTypes.gen.js +0 -2
- package/dist/internal/botApiTypes.gen.js.map +0 -1
- package/src/internal/botApiMethods.gen.ts +0 -2027
- package/src/internal/botApiShape.gen.ts +0 -398
- package/src/internal/botApiTypes.gen.ts +0 -4178
package/src/internal/send.ts
CHANGED
|
@@ -1,33 +1,83 @@
|
|
|
1
1
|
import type * as Content from '../Content.ts'
|
|
2
2
|
import type * as Dialog from '../Dialog.ts'
|
|
3
|
-
import type * as Dialog_ from '../Dialog.ts'
|
|
4
3
|
import type * as Markup from '../Markup.ts'
|
|
5
4
|
import type * as Send from '../Send.ts'
|
|
6
5
|
import type * as Text from '../Text.ts'
|
|
7
6
|
import * as Tgx from '@grom.js/tgx'
|
|
8
7
|
import * as Duration from 'effect/Duration'
|
|
9
8
|
import * as Effect from 'effect/Effect'
|
|
10
|
-
import * as Function from 'effect/Function'
|
|
11
9
|
import * as Match from 'effect/Match'
|
|
12
10
|
import * as Option from 'effect/Option'
|
|
13
11
|
import * as BotApi from '../BotApi.ts'
|
|
14
12
|
import * as LinkPreview from '../LinkPreview.ts'
|
|
15
13
|
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Helpers
|
|
16
|
+
// =============================================================================
|
|
17
|
+
|
|
18
|
+
const methodByContent: Record<Content.Content['_tag'], SendMethod> = {
|
|
19
|
+
Text: 'sendMessage',
|
|
20
|
+
Photo: 'sendPhoto',
|
|
21
|
+
Audio: 'sendAudio',
|
|
22
|
+
Document: 'sendDocument',
|
|
23
|
+
Video: 'sendVideo',
|
|
24
|
+
Animation: 'sendAnimation',
|
|
25
|
+
Voice: 'sendVoice',
|
|
26
|
+
VideoNote: 'sendVideoNote',
|
|
27
|
+
Location: 'sendLocation',
|
|
28
|
+
Venue: 'sendVenue',
|
|
29
|
+
Contact: 'sendContact',
|
|
30
|
+
Dice: 'sendDice',
|
|
31
|
+
Sticker: 'sendSticker',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type SendMethod = Extract<
|
|
35
|
+
keyof BotApi.MethodParams,
|
|
36
|
+
| 'sendMessage'
|
|
37
|
+
| 'sendPhoto'
|
|
38
|
+
| 'sendAudio'
|
|
39
|
+
| 'sendDocument'
|
|
40
|
+
| 'sendVideo'
|
|
41
|
+
| 'sendAnimation'
|
|
42
|
+
| 'sendVoice'
|
|
43
|
+
| 'sendVideoNote'
|
|
44
|
+
| 'sendPaidMedia'
|
|
45
|
+
| 'sendLocation'
|
|
46
|
+
| 'sendVenue'
|
|
47
|
+
| 'sendContact'
|
|
48
|
+
| 'sendDice'
|
|
49
|
+
| 'sendSticker'
|
|
50
|
+
| 'sendInvoice'
|
|
51
|
+
>
|
|
52
|
+
|
|
53
|
+
type PickMethodParams<
|
|
54
|
+
TMethod extends keyof BotApi.MethodParams,
|
|
55
|
+
TPick extends keyof BotApi.MethodParams[TMethod],
|
|
56
|
+
> = Pick<BotApi.MethodParams[TMethod], TPick>
|
|
57
|
+
|
|
58
|
+
// =============================================================================
|
|
59
|
+
// Parameters (Text)
|
|
60
|
+
// =============================================================================
|
|
61
|
+
|
|
16
62
|
type ParamsText = PickMethodParams<'sendMessage', 'text' | 'entities' | 'parse_mode'>
|
|
17
|
-
|
|
18
|
-
|
|
63
|
+
|
|
64
|
+
const paramsText: (
|
|
65
|
+
text: Text.Text,
|
|
66
|
+
) => ParamsText = Match.type<Text.Text>().pipe(
|
|
19
67
|
Match.withReturnType<ParamsText>(),
|
|
20
|
-
Match.
|
|
68
|
+
Match.tagsExhaustive({
|
|
21
69
|
Plain: ({ text, entities }) => ({ text, entities }),
|
|
22
70
|
Html: ({ html }) => ({ text: html, parse_mode: 'HTML' }),
|
|
23
71
|
Markdown: ({ markdown }) => ({ text: markdown, parse_mode: 'MarkdownV2' }),
|
|
24
72
|
Tgx: ({ tgx }) => ({ text: Tgx.html(tgx), parse_mode: 'HTML' }),
|
|
25
73
|
}),
|
|
26
|
-
Match.exhaustive,
|
|
27
74
|
)
|
|
28
75
|
|
|
29
76
|
type ParamsCaption = PickMethodParams<'sendPhoto', 'caption' | 'caption_entities' | 'parse_mode'>
|
|
30
|
-
|
|
77
|
+
|
|
78
|
+
const paramsCaption = (
|
|
79
|
+
caption: Option.Option<Text.Text>,
|
|
80
|
+
): ParamsCaption => (
|
|
31
81
|
Option.match(caption, {
|
|
32
82
|
onNone: () => ({}),
|
|
33
83
|
onSome: (caption) => {
|
|
@@ -37,50 +87,44 @@ const paramsCaption = (caption: Option.Option<Text.Text>): ParamsCaption => (
|
|
|
37
87
|
})
|
|
38
88
|
)
|
|
39
89
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
(
|
|
63
|
-
(
|
|
64
|
-
|
|
65
|
-
(content: Content.Dice): ParamsContentDice
|
|
66
|
-
(content: Content.Sticker): ParamsContentSticker
|
|
67
|
-
} = Function.pipe(
|
|
68
|
-
Match.type<Content.Content>(),
|
|
69
|
-
Match.tags({
|
|
70
|
-
Text: ({ text, linkPreview }): ParamsContentText => ({
|
|
90
|
+
// =============================================================================
|
|
91
|
+
// Parameters (Content)
|
|
92
|
+
// =============================================================================
|
|
93
|
+
|
|
94
|
+
type ParamsContent =
|
|
95
|
+
| PickMethodParams<'sendMessage', 'text' | 'entities' | 'parse_mode' | 'link_preview_options'>
|
|
96
|
+
| PickMethodParams<'sendPhoto', 'photo' | 'caption' | 'caption_entities' | 'parse_mode' | 'show_caption_above_media' | 'has_spoiler'>
|
|
97
|
+
| PickMethodParams<'sendAudio', 'audio' | 'caption' | 'caption_entities' | 'parse_mode' | 'duration' | 'performer' | 'title' | 'thumbnail'>
|
|
98
|
+
| PickMethodParams<'sendDocument', 'document' | 'thumbnail' | 'caption' | 'parse_mode' | 'caption_entities' | 'disable_content_type_detection'>
|
|
99
|
+
| PickMethodParams<'sendVideo', 'video' | 'duration' | 'width' | 'height' | 'thumbnail' | 'cover' | 'start_timestamp' | 'show_caption_above_media' | 'has_spoiler' | 'supports_streaming'>
|
|
100
|
+
| PickMethodParams<'sendAnimation', 'animation' | 'duration' | 'width' | 'height' | 'thumbnail' | 'has_spoiler'>
|
|
101
|
+
| PickMethodParams<'sendVoice', 'voice' | 'duration'>
|
|
102
|
+
| PickMethodParams<'sendVideoNote', 'video_note' | 'duration' | 'length' | 'thumbnail'>
|
|
103
|
+
| PickMethodParams<'sendLocation', 'latitude' | 'longitude' | 'horizontal_accuracy' | 'live_period' | 'heading' | 'proximity_alert_radius'>
|
|
104
|
+
| PickMethodParams<'sendVenue', 'latitude' | 'longitude' | 'title' | 'address' | 'foursquare_id' | 'foursquare_type' | 'google_place_id' | 'google_place_type'>
|
|
105
|
+
| PickMethodParams<'sendContact', 'phone_number' | 'first_name' | 'last_name' | 'vcard'>
|
|
106
|
+
| PickMethodParams<'sendDice', 'emoji'>
|
|
107
|
+
| PickMethodParams<'sendSticker', 'sticker' | 'emoji'>
|
|
108
|
+
|
|
109
|
+
const paramsContent: (
|
|
110
|
+
content: Content.Content,
|
|
111
|
+
) => ParamsContent = Match.type<Content.Content>().pipe(
|
|
112
|
+
Match.withReturnType<ParamsContent>(),
|
|
113
|
+
Match.tagsExhaustive({
|
|
114
|
+
Text: ({ text, linkPreview }) => ({
|
|
71
115
|
...paramsText(text),
|
|
72
116
|
link_preview_options: Option.match(linkPreview, {
|
|
73
117
|
onNone: () => ({ is_disabled: true }),
|
|
74
118
|
onSome: linkPreview => LinkPreview.options(linkPreview),
|
|
75
119
|
}),
|
|
76
120
|
}),
|
|
77
|
-
Photo: ({ file, caption, layout, spoiler })
|
|
121
|
+
Photo: ({ file, caption, layout, spoiler }) => ({
|
|
78
122
|
...paramsCaption(caption),
|
|
79
123
|
photo: file instanceof URL ? file.toString() : file,
|
|
80
124
|
show_caption_above_media: layout === 'caption-above',
|
|
81
125
|
has_spoiler: spoiler,
|
|
82
126
|
}),
|
|
83
|
-
Audio: ({ file, caption, duration, performer, title, thumbnail })
|
|
127
|
+
Audio: ({ file, caption, duration, performer, title, thumbnail }) => ({
|
|
84
128
|
...paramsCaption(caption),
|
|
85
129
|
audio: file instanceof URL ? file.toString() : file,
|
|
86
130
|
duration: Option.match(duration, {
|
|
@@ -91,13 +135,13 @@ const paramsContent: {
|
|
|
91
135
|
title: Option.getOrUndefined(title),
|
|
92
136
|
thumbnail: Option.getOrUndefined(thumbnail),
|
|
93
137
|
}),
|
|
94
|
-
Document: ({ file, caption, thumbnail, contentTypeDetection })
|
|
138
|
+
Document: ({ file, caption, thumbnail, contentTypeDetection }) => ({
|
|
95
139
|
...paramsCaption(caption),
|
|
96
140
|
document: file instanceof URL ? file.toString() : file,
|
|
97
141
|
thumbnail: Option.getOrUndefined(thumbnail),
|
|
98
142
|
disable_content_type_detection: !contentTypeDetection,
|
|
99
143
|
}),
|
|
100
|
-
Video: ({ file, caption, layout, spoiler, duration, width, height, thumbnail, cover, startAt, supportsStreaming })
|
|
144
|
+
Video: ({ file, caption, layout, spoiler, duration, width, height, thumbnail, cover, startAt, supportsStreaming }) => ({
|
|
101
145
|
...paramsCaption(caption),
|
|
102
146
|
video: file instanceof URL ? file.toString() : file,
|
|
103
147
|
duration: Option.match(duration, {
|
|
@@ -116,7 +160,7 @@ const paramsContent: {
|
|
|
116
160
|
has_spoiler: spoiler,
|
|
117
161
|
supports_streaming: supportsStreaming,
|
|
118
162
|
}),
|
|
119
|
-
Animation: ({ file, caption, spoiler, duration, width, height, thumbnail })
|
|
163
|
+
Animation: ({ file, caption, spoiler, duration, width, height, thumbnail }) => ({
|
|
120
164
|
...paramsCaption(caption),
|
|
121
165
|
animation: file instanceof URL ? file.toString() : file,
|
|
122
166
|
duration: Option.match(duration, {
|
|
@@ -128,7 +172,7 @@ const paramsContent: {
|
|
|
128
172
|
thumbnail: Option.getOrUndefined(thumbnail),
|
|
129
173
|
has_spoiler: spoiler,
|
|
130
174
|
}),
|
|
131
|
-
Voice: ({ file, caption, duration })
|
|
175
|
+
Voice: ({ file, caption, duration }) => ({
|
|
132
176
|
...paramsCaption(caption),
|
|
133
177
|
voice: file instanceof URL ? file.toString() : file,
|
|
134
178
|
duration: Option.match(duration, {
|
|
@@ -136,7 +180,7 @@ const paramsContent: {
|
|
|
136
180
|
onSome: duration => Math.round(Duration.toSeconds(duration)),
|
|
137
181
|
}),
|
|
138
182
|
}),
|
|
139
|
-
VideoNote: ({ file, duration, diameter, thumbnail })
|
|
183
|
+
VideoNote: ({ file, duration, diameter, thumbnail }) => ({
|
|
140
184
|
video_note: file,
|
|
141
185
|
duration: Option.match(duration, {
|
|
142
186
|
onNone: () => undefined,
|
|
@@ -145,7 +189,7 @@ const paramsContent: {
|
|
|
145
189
|
length: Option.getOrUndefined(diameter),
|
|
146
190
|
thumbnail: Option.getOrUndefined(thumbnail),
|
|
147
191
|
}),
|
|
148
|
-
Location: ({ latitude, longitude, uncertaintyRadius, livePeriod, heading, proximityAlertRadius })
|
|
192
|
+
Location: ({ latitude, longitude, uncertaintyRadius, livePeriod, heading, proximityAlertRadius }) => ({
|
|
149
193
|
latitude,
|
|
150
194
|
longitude,
|
|
151
195
|
horizontal_accuracy: Option.getOrUndefined(uncertaintyRadius),
|
|
@@ -158,7 +202,7 @@ const paramsContent: {
|
|
|
158
202
|
heading: Option.getOrUndefined(heading),
|
|
159
203
|
proximity_alert_radius: Option.getOrUndefined(proximityAlertRadius),
|
|
160
204
|
}),
|
|
161
|
-
Venue: ({ latitude, longitude, title, address, foursquareId, foursquareType, googlePlaceId, googlePlaceType })
|
|
205
|
+
Venue: ({ latitude, longitude, title, address, foursquareId, foursquareType, googlePlaceId, googlePlaceType }) => ({
|
|
162
206
|
latitude,
|
|
163
207
|
longitude,
|
|
164
208
|
title,
|
|
@@ -168,67 +212,72 @@ const paramsContent: {
|
|
|
168
212
|
google_place_id: Option.getOrUndefined(googlePlaceId),
|
|
169
213
|
google_place_type: Option.getOrUndefined(googlePlaceType),
|
|
170
214
|
}),
|
|
171
|
-
Contact: ({ phoneNumber, firstName, lastName, vcard })
|
|
215
|
+
Contact: ({ phoneNumber, firstName, lastName, vcard }) => ({
|
|
172
216
|
phone_number: phoneNumber,
|
|
173
217
|
first_name: firstName,
|
|
174
218
|
last_name: Option.getOrUndefined(lastName),
|
|
175
219
|
vcard: Option.getOrUndefined(vcard),
|
|
176
220
|
}),
|
|
177
|
-
Dice: ({ emoji })
|
|
221
|
+
Dice: ({ emoji }) => ({
|
|
178
222
|
emoji,
|
|
179
223
|
}),
|
|
180
|
-
Sticker: ({ file, emoji })
|
|
224
|
+
Sticker: ({ file, emoji }) => ({
|
|
181
225
|
sticker: file instanceof URL ? file.toString() : file,
|
|
182
226
|
emoji: Option.getOrUndefined(emoji),
|
|
183
227
|
}),
|
|
184
228
|
}),
|
|
185
|
-
|
|
186
|
-
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
// =============================================================================
|
|
232
|
+
// Parameters (Dialog)
|
|
233
|
+
// =============================================================================
|
|
187
234
|
|
|
188
235
|
type ParamsDialog = PickMethodParams<SendMethod, 'chat_id' | 'message_thread_id' | 'direct_messages_topic_id'>
|
|
189
|
-
|
|
190
|
-
|
|
236
|
+
|
|
237
|
+
const paramsDialog: (
|
|
238
|
+
dialog: Dialog.Dialog | Dialog.DialogId,
|
|
239
|
+
) => ParamsDialog = Match.type<Dialog.Dialog | Dialog.DialogId>().pipe(
|
|
191
240
|
Match.withReturnType<ParamsDialog>(),
|
|
241
|
+
Match.when(Match.number, dialogId => ({
|
|
242
|
+
chat_id: dialogId,
|
|
243
|
+
})),
|
|
192
244
|
Match.tagsExhaustive({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
chat_id:
|
|
201
|
-
Match.tagsExhaustive({
|
|
202
|
-
SupergroupId: ({ dialogId }) => dialogId,
|
|
203
|
-
PublicSupergroup: ({ username }) => username,
|
|
204
|
-
}),
|
|
205
|
-
),
|
|
206
|
-
message_thread_id: topicId,
|
|
245
|
+
User: user => ({
|
|
246
|
+
chat_id: user.dialogId(),
|
|
247
|
+
}),
|
|
248
|
+
Group: group => ({
|
|
249
|
+
chat_id: group.dialogId(),
|
|
250
|
+
}),
|
|
251
|
+
Supergroup: supergroup => ({
|
|
252
|
+
chat_id: supergroup.dialogId(),
|
|
207
253
|
}),
|
|
208
|
-
|
|
209
|
-
chat_id:
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
254
|
+
Channel: channel => ({
|
|
255
|
+
chat_id: channel.dialogId(),
|
|
256
|
+
}),
|
|
257
|
+
PrivateTopic: topic => ({
|
|
258
|
+
chat_id: topic.user.dialogId(),
|
|
259
|
+
message_thread_id: topic.topicId,
|
|
260
|
+
}),
|
|
261
|
+
ForumTopic: topic => ({
|
|
262
|
+
chat_id: topic.supergroup.dialogId(),
|
|
263
|
+
message_thread_id: topic.topicId,
|
|
264
|
+
}),
|
|
265
|
+
ChannelDm: dm => ({
|
|
266
|
+
chat_id: dm.channel.dialogId(),
|
|
267
|
+
direct_messages_topic_id: dm.topicId,
|
|
216
268
|
}),
|
|
217
269
|
}),
|
|
218
270
|
)
|
|
219
271
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
disable_notification: options.disableNotification || undefined,
|
|
224
|
-
protect_content: options.protectContent || undefined,
|
|
225
|
-
allow_paid_broadcast: options.allowPaidBroadcast || undefined,
|
|
226
|
-
}
|
|
227
|
-
}
|
|
272
|
+
// =============================================================================
|
|
273
|
+
// Parameters (Reply Markup)
|
|
274
|
+
// =============================================================================
|
|
228
275
|
|
|
229
276
|
type ParamsMarkup = PickMethodParams<SendMethod, 'reply_markup'>
|
|
230
|
-
|
|
231
|
-
|
|
277
|
+
|
|
278
|
+
const paramsMarkup: (
|
|
279
|
+
markup: Markup.Markup,
|
|
280
|
+
) => ParamsMarkup = Match.type<Markup.Markup>().pipe(
|
|
232
281
|
Match.withReturnType<ParamsMarkup>(),
|
|
233
282
|
Match.tagsExhaustive({
|
|
234
283
|
InlineKeyboard: markup => ({
|
|
@@ -262,57 +311,37 @@ const paramsMarkup: (markup: Markup.Markup) => ParamsMarkup = Function.pipe(
|
|
|
262
311
|
}),
|
|
263
312
|
)
|
|
264
313
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
> = Pick<BotApi.MethodParams[TMethod], TPick>
|
|
314
|
+
// =============================================================================
|
|
315
|
+
// Parameters (Send Options)
|
|
316
|
+
// =============================================================================
|
|
269
317
|
|
|
270
|
-
type
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
| 'sendContact'
|
|
284
|
-
| 'sendDice'
|
|
285
|
-
| 'sendSticker'
|
|
286
|
-
| 'sendInvoice'
|
|
287
|
-
>
|
|
318
|
+
type ParamsOptions = PickMethodParams<SendMethod, 'disable_notification' | 'protect_content' | 'allow_paid_broadcast'>
|
|
319
|
+
|
|
320
|
+
const paramsOptions = (options: Send.Options): ParamsOptions => {
|
|
321
|
+
return {
|
|
322
|
+
disable_notification: options.disableNotification || undefined,
|
|
323
|
+
protect_content: options.protectContent || undefined,
|
|
324
|
+
allow_paid_broadcast: options.allowPaidBroadcast || undefined,
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// =============================================================================
|
|
329
|
+
// Send Methods
|
|
330
|
+
// =============================================================================
|
|
288
331
|
|
|
289
332
|
export const sendMessage = Effect.fnUntraced(function* (params: {
|
|
290
333
|
content: Content.Content
|
|
291
|
-
dialog:
|
|
292
|
-
options?: Send.Options
|
|
334
|
+
dialog: Dialog.Dialog | Dialog.DialogId
|
|
293
335
|
markup?: Markup.Markup
|
|
336
|
+
options?: Send.Options
|
|
294
337
|
}) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
Text: content => api.sendMessage({ ...common, ...paramsContent(content) }),
|
|
304
|
-
Photo: content => api.sendPhoto({ ...common, ...paramsContent(content) }),
|
|
305
|
-
Audio: content => api.sendAudio({ ...common, ...paramsContent(content) }),
|
|
306
|
-
Document: content => api.sendDocument({ ...common, ...paramsContent(content) }),
|
|
307
|
-
Video: content => api.sendVideo({ ...common, ...paramsContent(content) }),
|
|
308
|
-
Animation: content => api.sendAnimation({ ...common, ...paramsContent(content) }),
|
|
309
|
-
Voice: content => api.sendVoice({ ...common, ...paramsContent(content) }),
|
|
310
|
-
VideoNote: content => api.sendVideoNote({ ...common, ...paramsContent(content) }),
|
|
311
|
-
Location: content => api.sendLocation({ ...common, ...paramsContent(content) }),
|
|
312
|
-
Venue: content => api.sendVenue({ ...common, ...paramsContent(content) }),
|
|
313
|
-
Contact: content => api.sendContact({ ...common, ...paramsContent(content) }),
|
|
314
|
-
Dice: content => api.sendDice({ ...common, ...paramsContent(content) }),
|
|
315
|
-
Sticker: content => api.sendSticker({ ...common, ...paramsContent(content) }),
|
|
316
|
-
}),
|
|
338
|
+
return yield* BotApi.callMethod(
|
|
339
|
+
methodByContent[params.content._tag],
|
|
340
|
+
{
|
|
341
|
+
...paramsContent(params.content),
|
|
342
|
+
...paramsDialog(params.dialog),
|
|
343
|
+
...(params.options ? paramsOptions(params.options) : {}),
|
|
344
|
+
...(params.markup ? paramsMarkup(params.markup) : {}),
|
|
345
|
+
},
|
|
317
346
|
)
|
|
318
347
|
})
|