@grom.js/effect-tg 0.6.0 → 0.8.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 (58) hide show
  1. package/dist/BotApi.d.ts +3 -15
  2. package/dist/BotApi.d.ts.map +1 -1
  3. package/dist/BotApi.js +0 -9
  4. package/dist/BotApi.js.map +1 -1
  5. package/dist/BotApiError.d.ts +91 -0
  6. package/dist/BotApiError.d.ts.map +1 -0
  7. package/dist/BotApiError.js +53 -0
  8. package/dist/BotApiError.js.map +1 -0
  9. package/dist/File.d.ts +14 -6
  10. package/dist/File.d.ts.map +1 -1
  11. package/dist/File.js +5 -15
  12. package/dist/File.js.map +1 -1
  13. package/dist/Runner.d.ts +1 -1
  14. package/dist/Runner.d.ts.map +1 -1
  15. package/dist/Send.d.ts +3 -2
  16. package/dist/Send.d.ts.map +1 -1
  17. package/dist/Send.js.map +1 -1
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/internal/botApi.d.ts +1 -1
  23. package/dist/internal/botApi.d.ts.map +1 -1
  24. package/dist/internal/botApi.js +2 -2
  25. package/dist/internal/botApi.js.map +1 -1
  26. package/dist/internal/botApiError.d.ts +3 -0
  27. package/dist/internal/botApiError.d.ts.map +1 -0
  28. package/dist/internal/botApiError.js +34 -0
  29. package/dist/internal/botApiError.js.map +1 -0
  30. package/dist/internal/botApiMethods.gen.d.ts +112 -28
  31. package/dist/internal/botApiMethods.gen.d.ts.map +1 -1
  32. package/dist/internal/botApiShape.gen.d.ts +11 -3
  33. package/dist/internal/botApiShape.gen.d.ts.map +1 -1
  34. package/dist/internal/botApiTypes.gen.d.ts +94 -11
  35. package/dist/internal/botApiTypes.gen.d.ts.map +1 -1
  36. package/dist/internal/file.d.ts +7 -0
  37. package/dist/internal/file.d.ts.map +1 -0
  38. package/dist/internal/file.js +13 -0
  39. package/dist/internal/file.js.map +1 -0
  40. package/dist/internal/runner.d.ts +1 -1
  41. package/dist/internal/runner.d.ts.map +1 -1
  42. package/dist/internal/runner.js +1 -1
  43. package/dist/internal/runner.js.map +1 -1
  44. package/dist/internal/send.d.ts +1 -1
  45. package/dist/internal/send.d.ts.map +1 -1
  46. package/package.json +5 -5
  47. package/src/BotApi.ts +3 -16
  48. package/src/BotApiError.ts +81 -0
  49. package/src/File.ts +17 -27
  50. package/src/Send.ts +3 -2
  51. package/src/index.ts +1 -0
  52. package/src/internal/botApi.ts +3 -2
  53. package/src/internal/botApiError.ts +36 -0
  54. package/src/internal/botApiMethods.gen.ts +112 -28
  55. package/src/internal/botApiShape.gen.ts +11 -3
  56. package/src/internal/botApiTypes.gen.ts +97 -11
  57. package/src/internal/file.ts +16 -0
  58. package/src/internal/runner.ts +2 -2
@@ -104,6 +104,8 @@ export interface User {
104
104
  can_connect_to_business?: boolean
105
105
  /** _True_, if the bot has a main Web App. Returned only in [getMe](https://core.telegram.org/bots/api#getme). */
106
106
  has_main_web_app?: boolean
107
+ /** _True_, if the bot has forum topic mode enabled in private chats. Returned only in [getMe](https://core.telegram.org/bots/api#getme). */
108
+ has_topics_enabled?: boolean
107
109
  }
108
110
 
109
111
  /** This object represents a chat. */
@@ -222,13 +224,19 @@ export interface ChatFullInfo {
222
224
  linked_chat_id?: number
223
225
  /** For supergroups, the location to which the supergroup is connected */
224
226
  location?: ChatLocation
227
+ /** For private chats, the rating of the user if any */
228
+ rating?: UserRating
229
+ /** The color scheme based on a unique gift that must be used for the chat's name, message replies and link previews */
230
+ unique_gift_colors?: UniqueGiftColors
231
+ /** The number of Telegram Stars a general user have to pay to send a message to the chat */
232
+ paid_message_star_count?: number
225
233
  }
226
234
 
227
235
  /** This object represents a message. */
228
236
  export interface Message {
229
237
  /** Unique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent */
230
238
  message_id: number
231
- /** Unique identifier of a message thread to which the message belongs; for supergroups only */
239
+ /** Unique identifier of a message thread or forum topic to which the message belongs; for supergroups and private chats only */
232
240
  message_thread_id?: number
233
241
  /** Information about the direct messages chat topic that contains the message */
234
242
  direct_messages_topic?: DirectMessagesTopic
@@ -248,7 +256,7 @@ export interface Message {
248
256
  chat: Chat
249
257
  /** Information about the original message for forwarded messages */
250
258
  forward_origin?: MessageOrigin
251
- /** _True_, if the message is sent to a forum topic */
259
+ /** _True_, if the message is sent to a topic in a forum supergroup or a private chat with the bot */
252
260
  is_topic_message?: true
253
261
  /** _True_, if the message is a channel post that was automatically forwarded to the connected discussion group */
254
262
  is_automatic_forward?: true
@@ -368,6 +376,8 @@ export interface Message {
368
376
  gift?: GiftInfo
369
377
  /** Service message: a unique gift was sent or received */
370
378
  unique_gift?: UniqueGiftInfo
379
+ /** Service message: upgrade of a gift was purchased after the gift was sent */
380
+ gift_upgrade_sent?: GiftInfo
371
381
  /** The domain name of the website on which the user has logged in. [More about Telegram Login »](https://core.telegram.org/widgets/login) */
372
382
  connected_website?: string
373
383
  /** Service message: the user allowed the bot to write messages after adding it to the attachment or side menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method [requestWriteAccess](https://core.telegram.org/bots/webapps#initializing-mini-apps) */
@@ -893,8 +903,10 @@ export interface ChecklistTask {
893
903
  text: string
894
904
  /** Special entities that appear in the task text */
895
905
  text_entities?: Array<MessageEntity>
896
- /** User that completed the task; omitted if the task wasn't completed */
906
+ /** User that completed the task; omitted if the task wasn't completed by a user */
897
907
  completed_by_user?: User
908
+ /** Chat that completed the task; omitted if the task wasn't completed by a chat */
909
+ completed_by_chat?: Chat
898
910
  /** Point in time (Unix timestamp) when the task was completed; 0 if the task wasn't completed */
899
911
  completion_date?: number
900
912
  }
@@ -1132,6 +1144,8 @@ export interface ForumTopicCreated {
1132
1144
  icon_color: number
1133
1145
  /** Unique identifier of the custom emoji shown as the topic icon */
1134
1146
  icon_custom_emoji_id?: string
1147
+ /** _True_, if the name of the topic wasn't specified explicitly by its creator and likely needs to be changed by the bot */
1148
+ is_name_implicit?: true
1135
1149
  }
1136
1150
 
1137
1151
  /** This object represents a service message about a forum topic closed in the chat. Currently holds no information. */
@@ -1987,6 +2001,18 @@ export interface BusinessOpeningHours {
1987
2001
  opening_hours: Array<BusinessOpeningHoursInterval>
1988
2002
  }
1989
2003
 
2004
+ /** This object describes the rating of a user based on their Telegram Star spendings. */
2005
+ export interface UserRating {
2006
+ /** Current level of the user, indicating their reliability when purchasing digital goods and services. A higher level suggests a more trustworthy customer; a negative level is likely reason for concern. */
2007
+ level: number
2008
+ /** Numerical value of the user's rating; the higher the rating, the better */
2009
+ rating: number
2010
+ /** The rating value required to get the current level */
2011
+ current_level_rating: number
2012
+ /** The rating value required to get to the next level; omitted if the maximum level was reached */
2013
+ next_level_rating?: number
2014
+ }
2015
+
1990
2016
  /** Describes the position of a clickable area within a story. */
1991
2017
  export interface StoryAreaPosition {
1992
2018
  /** The abscissa of the area's center, as a percentage of the media width */
@@ -2173,6 +2199,18 @@ export interface ForumTopic {
2173
2199
  icon_color: number
2174
2200
  /** Unique identifier of the custom emoji shown as the topic icon */
2175
2201
  icon_custom_emoji_id?: string
2202
+ /** _True_, if the name of the topic wasn't specified explicitly by its creator and likely needs to be changed by the bot */
2203
+ is_name_implicit?: true
2204
+ }
2205
+
2206
+ /** This object describes the background of a gift. */
2207
+ export interface GiftBackground {
2208
+ /** Center color of the background in RGB format */
2209
+ center_color: number
2210
+ /** Edge color of the background in RGB format */
2211
+ edge_color: number
2212
+ /** Text color of the background in RGB format */
2213
+ text_color: number
2176
2214
  }
2177
2215
 
2178
2216
  /** This object represents a gift that can be sent by the bot. */
@@ -2185,10 +2223,22 @@ export interface Gift {
2185
2223
  star_count: number
2186
2224
  /** The number of Telegram Stars that must be paid to upgrade the gift to a unique one */
2187
2225
  upgrade_star_count?: number
2188
- /** The total number of the gifts of this type that can be sent; for limited gifts only */
2226
+ /** _True_, if the gift can only be purchased by Telegram Premium subscribers */
2227
+ is_premium?: true
2228
+ /** _True_, if the gift can be used (after being upgraded) to customize a user's appearance */
2229
+ has_colors?: true
2230
+ /** The total number of gifts of this type that can be sent by all users; for limited gifts only */
2189
2231
  total_count?: number
2190
- /** The number of remaining gifts of this type that can be sent; for limited gifts only */
2232
+ /** The number of remaining gifts of this type that can be sent by all users; for limited gifts only */
2191
2233
  remaining_count?: number
2234
+ /** The total number of gifts of this type that can be sent by the bot; for limited gifts only */
2235
+ personal_total_count?: number
2236
+ /** The number of remaining gifts of this type that can be sent by the bot; for limited gifts only */
2237
+ personal_remaining_count?: number
2238
+ /** Background of the gift */
2239
+ background?: GiftBackground
2240
+ /** The total number of different unique gifts that can be obtained by upgrading the gift */
2241
+ unique_gift_variant_count?: number
2192
2242
  /** Information about the chat that published the gift */
2193
2243
  publisher_chat?: Chat
2194
2244
  }
@@ -2241,8 +2291,26 @@ export interface UniqueGiftBackdrop {
2241
2291
  rarity_per_mille: number
2242
2292
  }
2243
2293
 
2294
+ /** This object contains information about the color scheme for a user's name, message replies and link previews based on a unique gift. */
2295
+ export interface UniqueGiftColors {
2296
+ /** Custom emoji identifier of the unique gift's model */
2297
+ model_custom_emoji_id: string
2298
+ /** Custom emoji identifier of the unique gift's symbol */
2299
+ symbol_custom_emoji_id: string
2300
+ /** Main color used in light themes; RGB format */
2301
+ light_theme_main_color: number
2302
+ /** List of 1-3 additional colors used in light themes; RGB format */
2303
+ light_theme_other_colors: Array<number>
2304
+ /** Main color used in dark themes; RGB format */
2305
+ dark_theme_main_color: number
2306
+ /** List of 1-3 additional colors used in dark themes; RGB format */
2307
+ dark_theme_other_colors: Array<number>
2308
+ }
2309
+
2244
2310
  /** This object describes a unique gift that was upgraded from a regular gift. */
2245
2311
  export interface UniqueGift {
2312
+ /** Identifier of the regular gift from which the gift was upgraded */
2313
+ gift_id: string
2246
2314
  /** Human-readable name of the regular gift from which this unique gift was upgraded */
2247
2315
  base_name: string
2248
2316
  /** Unique name of the gift. This name can be used in `https://t.me/nft/...` links and story areas */
@@ -2255,6 +2323,12 @@ export interface UniqueGift {
2255
2323
  symbol: UniqueGiftSymbol
2256
2324
  /** Backdrop of the gift */
2257
2325
  backdrop: UniqueGiftBackdrop
2326
+ /** _True_, if the original regular gift was exclusively purchaseable by Telegram Premium subscribers */
2327
+ is_premium?: true
2328
+ /** _True_, if the gift is assigned from the TON blockchain and can't be resold or transferred in Telegram */
2329
+ is_from_blockchain?: true
2330
+ /** The color scheme that can be used by the gift's owner for the chat's name, replies to messages and link previews; for business account gifts and gifts that are currently on sale only */
2331
+ colors?: UniqueGiftColors
2258
2332
  /** Information about the chat that published the gift */
2259
2333
  publisher_chat?: Chat
2260
2334
  }
@@ -2267,8 +2341,10 @@ export interface GiftInfo {
2267
2341
  owned_gift_id?: string
2268
2342
  /** Number of Telegram Stars that can be claimed by the receiver by converting the gift; omitted if conversion to Telegram Stars is impossible */
2269
2343
  convert_star_count?: number
2270
- /** Number of Telegram Stars that were prepaid by the sender for the ability to upgrade the gift */
2344
+ /** Number of Telegram Stars that were prepaid for the ability to upgrade the gift */
2271
2345
  prepaid_upgrade_star_count?: number
2346
+ /** _True_, if the gift's upgrade was purchased after the gift was sent */
2347
+ is_upgrade_separate?: true
2272
2348
  /** _True_, if the gift can be upgraded to a unique gift */
2273
2349
  can_be_upgraded?: true
2274
2350
  /** Text of the message that was added to the gift */
@@ -2277,16 +2353,20 @@ export interface GiftInfo {
2277
2353
  entities?: Array<MessageEntity>
2278
2354
  /** _True_, if the sender and gift text are shown only to the gift receiver; otherwise, everyone will be able to see them */
2279
2355
  is_private?: true
2356
+ /** Unique number reserved for this gift when upgraded. See the _number_ field in [UniqueGift](https://core.telegram.org/bots/api#uniquegift) */
2357
+ unique_gift_number?: number
2280
2358
  }
2281
2359
 
2282
2360
  /** Describes a service message about a unique gift that was sent or received. */
2283
2361
  export interface UniqueGiftInfo {
2284
2362
  /** Information about the gift */
2285
2363
  gift: UniqueGift
2286
- /** Origin of the gift. Currently, either “upgrade” for gifts upgraded from regular gifts, “transfer” for gifts transferred from other users or channels, or “resale” for gifts bought from other users */
2364
+ /** Origin of the gift. Currently, either “upgrade” for gifts upgraded from regular gifts, “transfer” for gifts transferred from other users or channels, “resale” for gifts bought from other users, “gifted\_upgrade” for upgrades purchased after the gift was sent, or “offer” for gifts bought or sold through gift purchase offers */
2287
2365
  origin: string
2288
- /** For gifts bought from other users, the price paid for the gift */
2289
- last_resale_star_count?: number
2366
+ /** For gifts bought from other users, the currency in which the payment for the gift was done. Currently, one of “XTR” for Telegram Stars or “TON” for toncoins. */
2367
+ last_resale_currency?: string
2368
+ /** For gifts bought from other users, the price paid for the gift in either Telegram Stars or nanotoncoins */
2369
+ last_resale_amount?: number
2290
2370
  /** Unique identifier of the received gift for the bot; only present for gifts received on behalf of business accounts */
2291
2371
  owned_gift_id?: string
2292
2372
  /** Number of Telegram Stars that must be paid to transfer the gift; omitted if the bot cannot transfer the gift */
@@ -2327,10 +2407,14 @@ export interface OwnedGiftRegular {
2327
2407
  can_be_upgraded?: true
2328
2408
  /** _True_, if the gift was refunded and isn't available anymore */
2329
2409
  was_refunded?: true
2330
- /** Number of Telegram Stars that can be claimed by the receiver instead of the gift; omitted if the gift cannot be converted to Telegram Stars */
2410
+ /** Number of Telegram Stars that can be claimed by the receiver instead of the gift; omitted if the gift cannot be converted to Telegram Stars; for gifts received on behalf of business accounts only */
2331
2411
  convert_star_count?: number
2332
- /** Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift */
2412
+ /** Number of Telegram Stars that were paid for the ability to upgrade the gift */
2333
2413
  prepaid_upgrade_star_count?: number
2414
+ /** _True_, if the gift's upgrade was purchased after the gift was sent; for gifts received on behalf of business accounts only */
2415
+ is_upgrade_separate?: true
2416
+ /** Unique number reserved for this gift when upgraded. See the _number_ field in [UniqueGift](https://core.telegram.org/bots/api#uniquegift) */
2417
+ unique_gift_number?: number
2334
2418
  }
2335
2419
 
2336
2420
  /** Describes a unique gift received and owned by a user or a chat. */
@@ -2375,6 +2459,8 @@ export interface AcceptedGiftTypes {
2375
2459
  unique_gifts: boolean
2376
2460
  /** _True_, if a Telegram Premium subscription is accepted */
2377
2461
  premium_subscription: boolean
2462
+ /** _True_, if transfers of unique gifts from channels are accepted */
2463
+ gifts_from_channels: boolean
2378
2464
  }
2379
2465
 
2380
2466
  /** Describes an amount of Telegram Stars. */
@@ -0,0 +1,16 @@
1
+ import type { FileId } from '../File.ts'
2
+ import * as HttpClient from '@effect/platform/HttpClient'
3
+ import * as Effect from 'effect/Effect'
4
+ import * as BotApi from '../BotApi.ts'
5
+ import * as BotApiUrl from '../BotApiUrl.ts'
6
+
7
+ export const get = Effect.fnUntraced(
8
+ function* (fileId: FileId) {
9
+ const file = yield* BotApi.callMethod('getFile', { file_id: fileId })
10
+ if (file.file_path == null) {
11
+ return yield* Effect.die(new Error(`Bot API returned no file path for file "${fileId}".`))
12
+ }
13
+ const url = yield* BotApiUrl.BotApiUrl
14
+ return yield* HttpClient.get(url.toFile(file.file_path))
15
+ },
16
+ )
@@ -1,4 +1,4 @@
1
- import type { BotApiError } from '../BotApi.ts'
1
+ import type { BotApiError } from '../BotApiError.ts'
2
2
  import type { BotApiTransportError } from '../BotApiTransport.ts'
3
3
  import type { Runner } from '../Runner.ts'
4
4
  import * as Duration from 'effect/Duration'
@@ -29,7 +29,7 @@ export const makeSimple = (options?: {
29
29
  schedule: Schedule.spaced(Duration.seconds(3)),
30
30
  while: error => Match.value(error).pipe(
31
31
  Match.tagsExhaustive({
32
- '@grom.js/effect-tg/BotApi/BotApiError': error => Effect.succeed(
32
+ '@grom.js/effect-tg/BotApiError': error => Effect.succeed(
33
33
  error.code >= 500 || (
34
34
  error.code !== 401
35
35
  && error.code !== 403