@effect-ak/tg-bot-client 0.3.1 → 0.3.2

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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as Context from 'effect/Context';
2
- import * as Micro from 'effect/Micro';
3
1
  import * as effect_Cause from 'effect/Cause';
4
2
  import * as effect_Types from 'effect/Types';
3
+ import * as Micro from 'effect/Micro';
4
+ import * as Context from 'effect/Context';
5
5
 
6
6
  type ErrorReason = {
7
7
  readonly type: "NotOkResponse";
@@ -31,11 +31,6 @@ type TgBotClientSettingsInput = {
31
31
  base_url?: string;
32
32
  };
33
33
 
34
- type TgBotClientConfigObject = Required<TgBotClientSettingsInput>;
35
- declare const TgBotClientConfig_base: Context.TagClass<TgBotClientConfig, "TgBotClientConfig", Required<TgBotClientSettingsInput>>;
36
- declare class TgBotClientConfig extends TgBotClientConfig_base {
37
- }
38
-
39
34
  interface AffiliateInfo {
40
35
  commission_per_mille: number;
41
36
  amount: number;
@@ -2730,38 +2725,19 @@ interface UploadStickerFileInput {
2730
2725
  sticker_format: "static" | "animated" | "video";
2731
2726
  }
2732
2727
 
2733
- type ClientExecuteRequestServiceInterface = Micro.Micro.Success<typeof ClientExecuteRequestServiceDefault>;
2734
- declare const ClientExecuteRequestServiceDefault: Micro.Micro<{
2735
- readonly execute: <M extends keyof Api>(method: M, input: Parameters<Api[M]>[0]) => Micro.Micro<ReturnType<Api[M]>, TgBotClientError, never>;
2736
- }, never, TgBotClientConfig>;
2737
-
2738
- declare const getFile: (fileId: string, config: TgBotClientConfigObject, execute: ClientExecuteRequestServiceInterface) => Micro.Micro<File, TgBotClientError>;
2739
-
2740
- type ClientFileServiceInterface = Context.Tag.Service<typeof ClientFileService>;
2741
- declare const ClientFileService_base: Context.TagClass<ClientFileService, "ClientFileService", {
2742
- getFile: (input: {
2743
- file_id: string;
2744
- }) => ReturnType<typeof getFile>;
2745
- }>;
2746
- declare class ClientFileService extends ClientFileService_base {
2728
+ declare const TgBotClientConfig_base: Context.TagClass<TgBotClientConfig, "TgBotClientConfig", Required<TgBotClientSettingsInput>>;
2729
+ declare class TgBotClientConfig extends TgBotClientConfig_base {
2747
2730
  }
2748
2731
 
2749
- type TgBotClient = ReturnType<typeof makeTgBotClient>;
2750
- declare const makeTgBotClient: (input: TgBotClientSettingsInput) => {
2751
- execute: <M extends keyof Api>(method: M, input: Parameters<Api[M]>[0]) => Promise<ReturnType<Api[M]>>;
2752
- getFile: (input: Parameters<ClientFileServiceInterface["getFile"]>[0]) => Promise<File>;
2753
- };
2754
-
2755
2732
  type PollAndHandleInput = {
2756
2733
  settings: BotMessageHandlerSettings;
2757
- execute: ClientExecuteRequestServiceInterface["execute"];
2758
2734
  };
2759
2735
  type PollAndHandleResult = Micro.Micro.Success<ReturnType<typeof pollAndHandle>>;
2760
2736
  declare const pollAndHandle: (input: PollAndHandleInput) => Micro.Micro<{
2761
2737
  updates: Update[];
2762
2738
  lastSuccessId: number | undefined;
2763
2739
  hasError: boolean;
2764
- }, TgBotClientError, never>;
2740
+ }, TgBotClientError, TgBotClientConfig>;
2765
2741
 
2766
2742
  type AvailableUpdateTypes = Exclude<keyof Update, 'update_id'>;
2767
2743
  type LogLevel = "info" | "debug";
@@ -2783,20 +2759,28 @@ type BotMessageHandlerSettings = {
2783
2759
  onExit?: (_: Micro.MicroExit<PollAndHandleResult, TgBotClientError>) => void;
2784
2760
  };
2785
2761
 
2762
+ type BotUpdatePollerServiceInterface = Micro.Micro.Success<typeof BotUpdatesPollerServiceDefault>;
2786
2763
  declare const BotUpdatePollerService_base: Context.TagClass<BotUpdatePollerService, "BotUpdatePollerService", {
2787
- readonly runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
2764
+ readonly runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
2788
2765
  }>;
2789
2766
  declare class BotUpdatePollerService extends BotUpdatePollerService_base {
2790
2767
  }
2768
+ declare const BotUpdatesPollerServiceDefault: Micro.Micro<{
2769
+ readonly runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
2770
+ }, never, never>;
2791
2771
 
2792
2772
  type BotInstance = Micro.Micro.Success<ReturnType<typeof BotFactoryServiceDefault["runBot"]>>;
2793
2773
  declare const BotFactoryService_base: Context.TagClass<BotFactoryService, "BotFactoryService", {
2794
2774
  makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<{
2795
- fiber: Micro.MicroFiber<unknown, TgBotClientError>;
2796
- runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
2797
- }, never, BotUpdatePollerService>;
2775
+ runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
2776
+ interrupt: Micro.Micro<void, never, never>;
2777
+ }, never, TgBotClientConfig | BotUpdatePollerService>;
2798
2778
  runBot: (input: RunBotInput) => Micro.Micro<{
2799
- readonly reload: (input: Partial<RunBotInput>) => Promise<Micro.MicroFiber<unknown, TgBotClientError>>;
2779
+ readonly reload: (input: Partial<RunBotInput>) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
2780
+ readonly bot: {
2781
+ runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
2782
+ interrupt: Micro.Micro<void, never, never>;
2783
+ };
2800
2784
  }, string, never>;
2801
2785
  }>;
2802
2786
  declare class BotFactoryService extends BotFactoryService_base {
@@ -2808,17 +2792,42 @@ type RunBotInput = ({
2808
2792
  } & TgBotClientSettingsInput) & BotMessageHandlerSettings;
2809
2793
  declare const BotFactoryServiceDefault: {
2810
2794
  makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<{
2811
- fiber: Micro.MicroFiber<unknown, TgBotClientError>;
2812
- runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
2813
- }, never, BotUpdatePollerService>;
2795
+ runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
2796
+ interrupt: Micro.Micro<void, never, never>;
2797
+ }, never, TgBotClientConfig | BotUpdatePollerService>;
2814
2798
  runBot: (input: RunBotInput) => Micro.Micro<{
2815
- readonly reload: (input: Partial<RunBotInput>) => Promise<Micro.MicroFiber<unknown, TgBotClientError>>;
2799
+ readonly reload: (input: Partial<RunBotInput>) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
2800
+ readonly bot: {
2801
+ runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
2802
+ interrupt: Micro.Micro<void, never, never>;
2803
+ };
2816
2804
  }, string, never>;
2817
2805
  };
2818
2806
 
2819
- declare const runTgChatBot: (input: Parameters<typeof BotFactoryServiceDefault.runBot>[0]) => Promise<{
2820
- readonly reload: (input: Partial<RunBotInput>) => Promise<Micro.MicroFiber<unknown, TgBotClientError>>;
2807
+ declare const runTgChatBot: (input: RunBotInput) => Promise<{
2808
+ readonly reload: (input: Partial<RunBotInput>) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
2809
+ readonly bot: {
2810
+ runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
2811
+ interrupt: Micro.Micro<void, never, never>;
2812
+ };
2813
+ }>;
2814
+
2815
+ declare const getFile: (fileId: string) => Micro.Micro<File, TgBotClientError, TgBotClientConfig>;
2816
+
2817
+ type ClientFileServiceInterface = Context.Tag.Service<typeof ClientFileService>;
2818
+ declare const ClientFileService_base: Context.TagClass<ClientFileService, "ClientFileService", {
2819
+ getFile: (input: {
2820
+ file_id: string;
2821
+ }) => ReturnType<typeof getFile>;
2821
2822
  }>;
2823
+ declare class ClientFileService extends ClientFileService_base {
2824
+ }
2825
+
2826
+ type TgBotClient = ReturnType<typeof makeTgBotClient>;
2827
+ declare const makeTgBotClient: (input: TgBotClientSettingsInput) => {
2828
+ execute: <M extends keyof Api>(method: M, input: Parameters<Api[M]>[0]) => Promise<ReturnType<Api[M]>>;
2829
+ getFile: (input: Parameters<ClientFileServiceInterface["getFile"]>[0]) => Promise<File>;
2830
+ };
2822
2831
 
2823
2832
  declare const defaultBaseUrl = "https://api.telegram.org";
2824
2833
  declare const MESSAGE_EFFECTS: {
@@ -2833,4 +2842,4 @@ type MessageEffect = keyof typeof MESSAGE_EFFECTS;
2833
2842
  declare const messageEffectIdCodes: MessageEffect[];
2834
2843
  declare const isMessageEffect: (input: unknown) => input is MessageEffect;
2835
2844
 
2836
- export { type AddStickerToSetInput, type AffiliateInfo, type Animation, type AnswerCallbackQueryInput, type AnswerInlineQueryInput, type AnswerPreCheckoutQueryInput, type AnswerShippingQueryInput, type AnswerWebAppQueryInput, type Api, type ApproveChatJoinRequestInput, type Audio, type AvailableUpdateTypes, type BackgroundFill, type BackgroundFillFreeformGradient, type BackgroundFillGradient, type BackgroundFillSolid, type BackgroundType, type BackgroundTypeChatTheme, type BackgroundTypeFill, type BackgroundTypePattern, type BackgroundTypeWallpaper, type BanChatMemberInput, type BanChatSenderChatInput, type Birthdate, type BotCommand, type BotCommandScope, type BotCommandScopeAllChatAdministrators, type BotCommandScopeAllGroupChats, type BotCommandScopeAllPrivateChats, type BotCommandScopeChat, type BotCommandScopeChatAdministrators, type BotCommandScopeChatMember, type BotCommandScopeDefault, type BotDescription, BotFactoryService, BotFactoryServiceDefault, type BotInstance, type BotMessageHandlerSettings, type BotMessageHandlers, type BotName, type BotResponse, type BotShortDescription, type BusinessConnection, type BusinessIntro, type BusinessLocation, type BusinessMessagesDeleted, type BusinessOpeningHours, type BusinessOpeningHoursInterval, type CallbackGame, type CallbackQuery, type Chat, type ChatAdministratorRights, type ChatBackground, type ChatBoost, type ChatBoostAdded, type ChatBoostRemoved, type ChatBoostSource, type ChatBoostSourceGiftCode, type ChatBoostSourceGiveaway, type ChatBoostSourcePremium, type ChatBoostUpdated, type ChatFullInfo, type ChatInviteLink, type ChatJoinRequest, type ChatLocation, type ChatMember, type ChatMemberAdministrator, type ChatMemberBanned, type ChatMemberLeft, type ChatMemberMember, type ChatMemberOwner, type ChatMemberRestricted, type ChatMemberUpdated, type ChatPermissions, type ChatPhoto, type ChatShared, type ChosenInlineResult, type CloseForumTopicInput, type CloseGeneralForumTopicInput, type CloseInput, type Contact, type CopyMessageInput, type CopyMessagesInput, type CopyTextButton, type CreateChatInviteLinkInput, type CreateChatSubscriptionInviteLinkInput, type CreateForumTopicInput, type CreateInvoiceLinkInput, type CreateNewStickerSetInput, type DeclineChatJoinRequestInput, type DeleteChatPhotoInput, type DeleteChatStickerSetInput, type DeleteForumTopicInput, type DeleteMessageInput, type DeleteMessagesInput, type DeleteMyCommandsInput, type DeleteStickerFromSetInput, type DeleteStickerSetInput, type DeleteWebhookInput, type Dice, type Document, type EditChatInviteLinkInput, type EditChatSubscriptionInviteLinkInput, type EditForumTopicInput, type EditGeneralForumTopicInput, type EditMessageCaptionInput, type EditMessageLiveLocationInput, type EditMessageMediaInput, type EditMessageReplyMarkupInput, type EditMessageTextInput, type EditUserStarSubscriptionInput, type EncryptedCredentials, type EncryptedPassportElement, type ExportChatInviteLinkInput, type ExternalReplyInfo, type File$1 as File, type ForceReply, type ForumTopic, type ForumTopicClosed, type ForumTopicCreated, type ForumTopicEdited, type ForumTopicReopened, type ForwardMessageInput, type ForwardMessagesInput, type Game, type GameHighScore, type GeneralForumTopicHidden, type GeneralForumTopicUnhidden, type GetAvailableGiftsInput, type GetBusinessConnectionInput, type GetChatAdministratorsInput, type GetChatInput, type GetChatMemberCountInput, type GetChatMemberInput, type GetChatMenuButtonInput, type GetCustomEmojiStickersInput, type GetFileInput, type GetForumTopicIconStickersInput, type GetGameHighScoresInput, type GetMeInput, type GetMyCommandsInput, type GetMyDefaultAdministratorRightsInput, type GetMyDescriptionInput, type GetMyNameInput, type GetMyShortDescriptionInput, type GetStarTransactionsInput, type GetStickerSetInput, type GetUpdatesInput, type GetUserChatBoostsInput, type GetUserProfilePhotosInput, type GetWebhookInfoInput, type Gift, type Gifts, type Giveaway, type GiveawayCompleted, type GiveawayCreated, type GiveawayWinners, type HideGeneralForumTopicInput, type InaccessibleMessage, type InlineKeyboardButton, type InlineKeyboardMarkup, type InlineQuery, type InlineQueryResult, type InlineQueryResultArticle, type InlineQueryResultAudio, type InlineQueryResultCachedAudio, type InlineQueryResultCachedDocument, type InlineQueryResultCachedGif, type InlineQueryResultCachedMpeg4Gif, type InlineQueryResultCachedPhoto, type InlineQueryResultCachedSticker, type InlineQueryResultCachedVideo, type InlineQueryResultCachedVoice, type InlineQueryResultContact, type InlineQueryResultDocument, type InlineQueryResultGame, type InlineQueryResultGif, type InlineQueryResultLocation, type InlineQueryResultMpeg4Gif, type InlineQueryResultPhoto, type InlineQueryResultVenue, type InlineQueryResultVideo, type InlineQueryResultVoice, type InlineQueryResultsButton, type InputContactMessageContent, type InputFile, type InputInvoiceMessageContent, type InputLocationMessageContent, type InputMedia, type InputMediaAnimation, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type InputMessageContent, type InputPaidMedia, type InputPaidMediaPhoto, type InputPaidMediaVideo, type InputPollOption, type InputSticker, type InputTextMessageContent, type InputVenueMessageContent, type Invoice, type KeyboardButton, type KeyboardButtonPollType, type KeyboardButtonRequestChat, type KeyboardButtonRequestUsers, type LabeledPrice, type LeaveChatInput, type LinkPreviewOptions, type Location, type LogLevel, type LogOutInput, type LoginUrl, MESSAGE_EFFECTS, type MaskPosition, type MaybeInaccessibleMessage, type MenuButton, type MenuButtonCommands, type MenuButtonDefault, type MenuButtonWebApp, type Message, type MessageAutoDeleteTimerChanged, type MessageEffect, type MessageEntity, type MessageId, type MessageOrigin, type MessageOriginChannel, type MessageOriginChat, type MessageOriginHiddenUser, type MessageOriginUser, type MessageReactionCountUpdated, type MessageReactionUpdated, type OrderInfo, type PaidMedia, type PaidMediaInfo, type PaidMediaPhoto, type PaidMediaPreview, type PaidMediaPurchased, type PaidMediaVideo, type PassportData, type PassportElementError, type PassportElementErrorDataField, type PassportElementErrorFile, type PassportElementErrorFiles, type PassportElementErrorFrontSide, type PassportElementErrorReverseSide, type PassportElementErrorSelfie, type PassportElementErrorTranslationFile, type PassportElementErrorTranslationFiles, type PassportElementErrorUnspecified, type PassportFile, type PhotoSize, type PinChatMessageInput, type Poll, type PollAnswer, type PollOption, type PreCheckoutQuery, type PreparedInlineMessage, type PromoteChatMemberInput, type ProximityAlertTriggered, type ReactionCount, type ReactionType, type ReactionTypeCustomEmoji, type ReactionTypeEmoji, type ReactionTypePaid, type RefundStarPaymentInput, type RefundedPayment, type ReopenForumTopicInput, type ReopenGeneralForumTopicInput, type ReplaceStickerInSetInput, type ReplyKeyboardMarkup, type ReplyKeyboardRemove, type ReplyParameters, type ResponseParameters, type RestrictChatMemberInput, type RevenueWithdrawalState, type RevenueWithdrawalStateFailed, type RevenueWithdrawalStatePending, type RevenueWithdrawalStateSucceeded, type RevokeChatInviteLinkInput, type RunBotInput, type SavePreparedInlineMessageInput, type SendAnimationInput, type SendAudioInput, type SendChatActionInput, type SendContactInput, type SendDiceInput, type SendDocumentInput, type SendGameInput, type SendGiftInput, type SendInvoiceInput, type SendLocationInput, type SendMediaGroupInput, type SendMessageInput, type SendPaidMediaInput, type SendPhotoInput, type SendPollInput, type SendStickerInput, type SendVenueInput, type SendVideoInput, type SendVideoNoteInput, type SendVoiceInput, type SentWebAppMessage, type SetChatAdministratorCustomTitleInput, type SetChatDescriptionInput, type SetChatMenuButtonInput, type SetChatPermissionsInput, type SetChatPhotoInput, type SetChatStickerSetInput, type SetChatTitleInput, type SetCustomEmojiStickerSetThumbnailInput, type SetGameScoreInput, type SetMessageReactionInput, type SetMyCommandsInput, type SetMyDefaultAdministratorRightsInput, type SetMyDescriptionInput, type SetMyNameInput, type SetMyShortDescriptionInput, type SetPassportDataErrorsInput, type SetStickerEmojiListInput, type SetStickerKeywordsInput, type SetStickerMaskPositionInput, type SetStickerPositionInSetInput, type SetStickerSetThumbnailInput, type SetStickerSetTitleInput, type SetUserEmojiStatusInput, type SetWebhookInput, type SharedUser, type ShippingAddress, type ShippingOption, type ShippingQuery, type StarTransaction, type StarTransactions, type Sticker, type StickerSet, type StopMessageLiveLocationInput, type StopPollInput, type Story, type SuccessfulPayment, type SwitchInlineQueryChosenChat, type TextQuote, type TgBotClient, type TransactionPartner, type TransactionPartnerAffiliateProgram, type TransactionPartnerFragment, type TransactionPartnerOther, type TransactionPartnerTelegramAds, type TransactionPartnerTelegramApi, type TransactionPartnerUser, type UnbanChatMemberInput, type UnbanChatSenderChatInput, type UnhideGeneralForumTopicInput, type UnpinAllChatMessagesInput, type UnpinAllForumTopicMessagesInput, type UnpinAllGeneralForumTopicMessagesInput, type UnpinChatMessageInput, type Update, type UploadStickerFileInput, type User, type UserChatBoosts, type UserProfilePhotos, type UsersShared, type Venue, type Video, type VideoChatEnded, type VideoChatParticipantsInvited, type VideoChatScheduled, type VideoChatStarted, type VideoNote, type Voice, type WebAppData, type WebAppInfo, type WebhookInfo, type WriteAccessAllowed, defaultBaseUrl, isMessageEffect, makeTgBotClient, messageEffectIdCodes, runTgChatBot };
2845
+ export { type AddStickerToSetInput, type AffiliateInfo, type Animation, type AnswerCallbackQueryInput, type AnswerInlineQueryInput, type AnswerPreCheckoutQueryInput, type AnswerShippingQueryInput, type AnswerWebAppQueryInput, type Api, type ApproveChatJoinRequestInput, type Audio, type AvailableUpdateTypes, type BackgroundFill, type BackgroundFillFreeformGradient, type BackgroundFillGradient, type BackgroundFillSolid, type BackgroundType, type BackgroundTypeChatTheme, type BackgroundTypeFill, type BackgroundTypePattern, type BackgroundTypeWallpaper, type BanChatMemberInput, type BanChatSenderChatInput, type Birthdate, type BotCommand, type BotCommandScope, type BotCommandScopeAllChatAdministrators, type BotCommandScopeAllGroupChats, type BotCommandScopeAllPrivateChats, type BotCommandScopeChat, type BotCommandScopeChatAdministrators, type BotCommandScopeChatMember, type BotCommandScopeDefault, type BotDescription, BotFactoryService, BotFactoryServiceDefault, type BotInstance, type BotMessageHandlerSettings, type BotMessageHandlers, type BotName, type BotResponse, type BotShortDescription, BotUpdatePollerService, type BotUpdatePollerServiceInterface, BotUpdatesPollerServiceDefault, type BusinessConnection, type BusinessIntro, type BusinessLocation, type BusinessMessagesDeleted, type BusinessOpeningHours, type BusinessOpeningHoursInterval, type CallbackGame, type CallbackQuery, type Chat, type ChatAdministratorRights, type ChatBackground, type ChatBoost, type ChatBoostAdded, type ChatBoostRemoved, type ChatBoostSource, type ChatBoostSourceGiftCode, type ChatBoostSourceGiveaway, type ChatBoostSourcePremium, type ChatBoostUpdated, type ChatFullInfo, type ChatInviteLink, type ChatJoinRequest, type ChatLocation, type ChatMember, type ChatMemberAdministrator, type ChatMemberBanned, type ChatMemberLeft, type ChatMemberMember, type ChatMemberOwner, type ChatMemberRestricted, type ChatMemberUpdated, type ChatPermissions, type ChatPhoto, type ChatShared, type ChosenInlineResult, type CloseForumTopicInput, type CloseGeneralForumTopicInput, type CloseInput, type Contact, type CopyMessageInput, type CopyMessagesInput, type CopyTextButton, type CreateChatInviteLinkInput, type CreateChatSubscriptionInviteLinkInput, type CreateForumTopicInput, type CreateInvoiceLinkInput, type CreateNewStickerSetInput, type DeclineChatJoinRequestInput, type DeleteChatPhotoInput, type DeleteChatStickerSetInput, type DeleteForumTopicInput, type DeleteMessageInput, type DeleteMessagesInput, type DeleteMyCommandsInput, type DeleteStickerFromSetInput, type DeleteStickerSetInput, type DeleteWebhookInput, type Dice, type Document, type EditChatInviteLinkInput, type EditChatSubscriptionInviteLinkInput, type EditForumTopicInput, type EditGeneralForumTopicInput, type EditMessageCaptionInput, type EditMessageLiveLocationInput, type EditMessageMediaInput, type EditMessageReplyMarkupInput, type EditMessageTextInput, type EditUserStarSubscriptionInput, type EncryptedCredentials, type EncryptedPassportElement, type ExportChatInviteLinkInput, type ExternalReplyInfo, type File$1 as File, type ForceReply, type ForumTopic, type ForumTopicClosed, type ForumTopicCreated, type ForumTopicEdited, type ForumTopicReopened, type ForwardMessageInput, type ForwardMessagesInput, type Game, type GameHighScore, type GeneralForumTopicHidden, type GeneralForumTopicUnhidden, type GetAvailableGiftsInput, type GetBusinessConnectionInput, type GetChatAdministratorsInput, type GetChatInput, type GetChatMemberCountInput, type GetChatMemberInput, type GetChatMenuButtonInput, type GetCustomEmojiStickersInput, type GetFileInput, type GetForumTopicIconStickersInput, type GetGameHighScoresInput, type GetMeInput, type GetMyCommandsInput, type GetMyDefaultAdministratorRightsInput, type GetMyDescriptionInput, type GetMyNameInput, type GetMyShortDescriptionInput, type GetStarTransactionsInput, type GetStickerSetInput, type GetUpdatesInput, type GetUserChatBoostsInput, type GetUserProfilePhotosInput, type GetWebhookInfoInput, type Gift, type Gifts, type Giveaway, type GiveawayCompleted, type GiveawayCreated, type GiveawayWinners, type HideGeneralForumTopicInput, type InaccessibleMessage, type InlineKeyboardButton, type InlineKeyboardMarkup, type InlineQuery, type InlineQueryResult, type InlineQueryResultArticle, type InlineQueryResultAudio, type InlineQueryResultCachedAudio, type InlineQueryResultCachedDocument, type InlineQueryResultCachedGif, type InlineQueryResultCachedMpeg4Gif, type InlineQueryResultCachedPhoto, type InlineQueryResultCachedSticker, type InlineQueryResultCachedVideo, type InlineQueryResultCachedVoice, type InlineQueryResultContact, type InlineQueryResultDocument, type InlineQueryResultGame, type InlineQueryResultGif, type InlineQueryResultLocation, type InlineQueryResultMpeg4Gif, type InlineQueryResultPhoto, type InlineQueryResultVenue, type InlineQueryResultVideo, type InlineQueryResultVoice, type InlineQueryResultsButton, type InputContactMessageContent, type InputFile, type InputInvoiceMessageContent, type InputLocationMessageContent, type InputMedia, type InputMediaAnimation, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type InputMessageContent, type InputPaidMedia, type InputPaidMediaPhoto, type InputPaidMediaVideo, type InputPollOption, type InputSticker, type InputTextMessageContent, type InputVenueMessageContent, type Invoice, type KeyboardButton, type KeyboardButtonPollType, type KeyboardButtonRequestChat, type KeyboardButtonRequestUsers, type LabeledPrice, type LeaveChatInput, type LinkPreviewOptions, type Location, type LogLevel, type LogOutInput, type LoginUrl, MESSAGE_EFFECTS, type MaskPosition, type MaybeInaccessibleMessage, type MenuButton, type MenuButtonCommands, type MenuButtonDefault, type MenuButtonWebApp, type Message, type MessageAutoDeleteTimerChanged, type MessageEffect, type MessageEntity, type MessageId, type MessageOrigin, type MessageOriginChannel, type MessageOriginChat, type MessageOriginHiddenUser, type MessageOriginUser, type MessageReactionCountUpdated, type MessageReactionUpdated, type OrderInfo, type PaidMedia, type PaidMediaInfo, type PaidMediaPhoto, type PaidMediaPreview, type PaidMediaPurchased, type PaidMediaVideo, type PassportData, type PassportElementError, type PassportElementErrorDataField, type PassportElementErrorFile, type PassportElementErrorFiles, type PassportElementErrorFrontSide, type PassportElementErrorReverseSide, type PassportElementErrorSelfie, type PassportElementErrorTranslationFile, type PassportElementErrorTranslationFiles, type PassportElementErrorUnspecified, type PassportFile, type PhotoSize, type PinChatMessageInput, type Poll, type PollAnswer, type PollOption, type PreCheckoutQuery, type PreparedInlineMessage, type PromoteChatMemberInput, type ProximityAlertTriggered, type ReactionCount, type ReactionType, type ReactionTypeCustomEmoji, type ReactionTypeEmoji, type ReactionTypePaid, type RefundStarPaymentInput, type RefundedPayment, type ReopenForumTopicInput, type ReopenGeneralForumTopicInput, type ReplaceStickerInSetInput, type ReplyKeyboardMarkup, type ReplyKeyboardRemove, type ReplyParameters, type ResponseParameters, type RestrictChatMemberInput, type RevenueWithdrawalState, type RevenueWithdrawalStateFailed, type RevenueWithdrawalStatePending, type RevenueWithdrawalStateSucceeded, type RevokeChatInviteLinkInput, type RunBotInput, type SavePreparedInlineMessageInput, type SendAnimationInput, type SendAudioInput, type SendChatActionInput, type SendContactInput, type SendDiceInput, type SendDocumentInput, type SendGameInput, type SendGiftInput, type SendInvoiceInput, type SendLocationInput, type SendMediaGroupInput, type SendMessageInput, type SendPaidMediaInput, type SendPhotoInput, type SendPollInput, type SendStickerInput, type SendVenueInput, type SendVideoInput, type SendVideoNoteInput, type SendVoiceInput, type SentWebAppMessage, type SetChatAdministratorCustomTitleInput, type SetChatDescriptionInput, type SetChatMenuButtonInput, type SetChatPermissionsInput, type SetChatPhotoInput, type SetChatStickerSetInput, type SetChatTitleInput, type SetCustomEmojiStickerSetThumbnailInput, type SetGameScoreInput, type SetMessageReactionInput, type SetMyCommandsInput, type SetMyDefaultAdministratorRightsInput, type SetMyDescriptionInput, type SetMyNameInput, type SetMyShortDescriptionInput, type SetPassportDataErrorsInput, type SetStickerEmojiListInput, type SetStickerKeywordsInput, type SetStickerMaskPositionInput, type SetStickerPositionInSetInput, type SetStickerSetThumbnailInput, type SetStickerSetTitleInput, type SetUserEmojiStatusInput, type SetWebhookInput, type SharedUser, type ShippingAddress, type ShippingOption, type ShippingQuery, type StarTransaction, type StarTransactions, type Sticker, type StickerSet, type StopMessageLiveLocationInput, type StopPollInput, type Story, type SuccessfulPayment, type SwitchInlineQueryChosenChat, type TextQuote, type TgBotClient, type TransactionPartner, type TransactionPartnerAffiliateProgram, type TransactionPartnerFragment, type TransactionPartnerOther, type TransactionPartnerTelegramAds, type TransactionPartnerTelegramApi, type TransactionPartnerUser, type UnbanChatMemberInput, type UnbanChatSenderChatInput, type UnhideGeneralForumTopicInput, type UnpinAllChatMessagesInput, type UnpinAllForumTopicMessagesInput, type UnpinAllGeneralForumTopicMessagesInput, type UnpinChatMessageInput, type Update, type UploadStickerFileInput, type User, type UserChatBoosts, type UserProfilePhotos, type UsersShared, type Venue, type Video, type VideoChatEnded, type VideoChatParticipantsInvited, type VideoChatScheduled, type VideoChatStarted, type VideoNote, type Voice, type WebAppData, type WebAppInfo, type WebhookInfo, type WriteAccessAllowed, defaultBaseUrl, isMessageEffect, makeTgBotClient, messageEffectIdCodes, runTgChatBot };
package/dist/index.js CHANGED
@@ -32,6 +32,8 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  BotFactoryService: () => BotFactoryService,
34
34
  BotFactoryServiceDefault: () => BotFactoryServiceDefault,
35
+ BotUpdatePollerService: () => BotUpdatePollerService,
36
+ BotUpdatesPollerServiceDefault: () => BotUpdatesPollerServiceDefault,
35
37
  MESSAGE_EFFECTS: () => MESSAGE_EFFECTS,
36
38
  defaultBaseUrl: () => defaultBaseUrl,
37
39
  isMessageEffect: () => isMessageEffect,
@@ -41,8 +43,87 @@ __export(src_exports, {
41
43
  });
42
44
  module.exports = __toCommonJS(src_exports);
43
45
 
44
- // src/client/_client.ts
45
- var Micro5 = __toESM(require("effect/Micro"));
46
+ // src/bot/factory/_service.ts
47
+ var Micro7 = __toESM(require("effect/Micro"));
48
+ var Context3 = __toESM(require("effect/Context"));
49
+
50
+ // src/bot/update-poller/_service.ts
51
+ var Micro4 = __toESM(require("effect/Micro"));
52
+ var Context2 = __toESM(require("effect/Context"));
53
+
54
+ // src/bot/update-poller/poll-and-handle.ts
55
+ var Micro3 = __toESM(require("effect/Micro"));
56
+
57
+ // src/bot/update-poller/settings.ts
58
+ var makeSettingsFrom = (input) => {
59
+ let limit = input.batch_size ?? 10;
60
+ let timeout = input.timeout ?? 10;
61
+ let max_empty_responses = input.max_empty_responses;
62
+ let update_types = input.update_types;
63
+ let log_level = input.log_level;
64
+ if (limit < 10 || limit > 100) {
65
+ console.warn("Wrong limit, must be in [10..100], using 10 instead");
66
+ limit = 10;
67
+ }
68
+ if (timeout < 2 || timeout > 10) {
69
+ console.warn("Wrong timeout, must be in [2..10], using 2 instead");
70
+ limit = 10;
71
+ }
72
+ if (max_empty_responses && max_empty_responses < 2) {
73
+ console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
74
+ max_empty_responses = void 0;
75
+ }
76
+ if (max_empty_responses && max_empty_responses < 2) {
77
+ console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
78
+ max_empty_responses = void 0;
79
+ }
80
+ if (!update_types) {
81
+ console.info("Handling only messages, ignoring others");
82
+ update_types = ["message"];
83
+ }
84
+ if (!log_level) {
85
+ log_level = "info";
86
+ }
87
+ return {
88
+ limit,
89
+ timeout,
90
+ max_empty_responses,
91
+ update_types,
92
+ log_level
93
+ };
94
+ };
95
+
96
+ // src/bot/update-poller/fetch-updates.ts
97
+ var Micro2 = __toESM(require("effect/Micro"));
98
+
99
+ // src/bot/message-handler/utils.ts
100
+ var extractUpdate = (input) => {
101
+ for (const [field, value] of Object.entries(input)) {
102
+ if (field == "update_id") {
103
+ continue;
104
+ }
105
+ return {
106
+ type: field,
107
+ ...value
108
+ };
109
+ }
110
+ return;
111
+ };
112
+
113
+ // src/client/execute-request/execute.ts
114
+ var Micro = __toESM(require("effect/Micro"));
115
+ var String = __toESM(require("effect/String"));
116
+
117
+ // src/client/errors.ts
118
+ var Data = __toESM(require("effect/Data"));
119
+ var TgBotClientError = class _TgBotClientError extends Data.TaggedError("TgBotClientError") {
120
+ static missingSuccess = new _TgBotClientError({
121
+ reason: {
122
+ type: "ClientInternalError",
123
+ cause: "Expected 'success' to be defined"
124
+ }
125
+ });
126
+ };
46
127
 
47
128
  // src/client/config.ts
48
129
  var Context = __toESM(require("effect/Context"));
@@ -70,25 +151,6 @@ var makeTgBotClientConfig = (input) => TgBotClientConfig.of({
70
151
  var TgBotClientConfig = class extends Context.Tag("TgBotClientConfig")() {
71
152
  };
72
153
 
73
- // src/client/execute-request/_service.ts
74
- var Micro2 = __toESM(require("effect/Micro"));
75
- var Context2 = __toESM(require("effect/Context"));
76
-
77
- // src/client/execute-request/execute.ts
78
- var Micro = __toESM(require("effect/Micro"));
79
- var String = __toESM(require("effect/String"));
80
-
81
- // src/client/errors.ts
82
- var Data = __toESM(require("effect/Data"));
83
- var TgBotClientError = class _TgBotClientError extends Data.TaggedError("TgBotClientError") {
84
- static missingSuccess = new _TgBotClientError({
85
- reason: {
86
- type: "ClientInternalError",
87
- cause: "Expected 'success' to be defined"
88
- }
89
- });
90
- };
91
-
92
154
  // src/client/guards.ts
93
155
  var isFileContent = (input) => typeof input == "object" && input != null && ("file_content" in input && input.file_content instanceof Uint8Array) && ("file_name" in input && typeof input.file_name == "string");
94
156
  var isTgBotApiResponse = (input) => typeof input == "object" && input != null && ("ok" in input && typeof input.ok == "boolean");
@@ -113,7 +175,8 @@ var makePayload = (body) => {
113
175
  };
114
176
 
115
177
  // src/client/execute-request/execute.ts
116
- var execute = (config, method, input) => Micro.gen(function* () {
178
+ var execute = (method, input) => Micro.gen(function* () {
179
+ const config = yield* Micro.service(TgBotClientConfig);
117
180
  const httpResponse = yield* Micro.tryPromise({
118
181
  try: () => fetch(
119
182
  `${config.base_url}/bot${config.bot_token}/${String.snakeToCamel(method)}`,
@@ -149,160 +212,17 @@ var execute = (config, method, input) => Micro.gen(function* () {
149
212
  return response.result;
150
213
  });
151
214
 
152
- // src/client/execute-request/_service.ts
153
- var ClientExecuteRequestService = class extends Context2.Tag("ClientExecuteRequestService")() {
154
- };
155
- var ClientExecuteRequestServiceDefault = Micro2.gen(function* () {
156
- const config = yield* Micro2.service(TgBotClientConfig);
157
- return {
158
- execute: (method, input) => execute(config, method, input)
159
- };
160
- });
161
-
162
- // src/client/file/_service.ts
163
- var Micro4 = __toESM(require("effect/Micro"));
164
- var Context3 = __toESM(require("effect/Context"));
165
-
166
- // src/client/file/get-file.ts
167
- var Micro3 = __toESM(require("effect/Micro"));
168
- var getFile = (fileId, config, execute2) => Micro3.gen(function* () {
169
- const response = yield* execute2.execute("get_file", { file_id: fileId });
170
- const file_path = response.file_path;
171
- if (!file_path || file_path.length == 0) {
172
- return yield* Micro3.fail(
173
- new TgBotClientError({
174
- reason: {
175
- type: "UnableToGetFile",
176
- cause: "File path not defined"
177
- }
178
- })
179
- );
180
- }
181
- const file_name = file_path.replaceAll("/", "-");
182
- const url = `${config.base_url}/file/bot${config.bot_token}/${file_path}`;
183
- const fileContent = yield* Micro3.tryPromise({
184
- try: () => fetch(url).then((_) => _.arrayBuffer()),
185
- catch: (cause) => new TgBotClientError({
186
- reason: { type: "UnableToGetFile", cause }
187
- })
188
- });
189
- const file = new File([new Uint8Array(fileContent)], file_name);
190
- return file;
191
- });
192
-
193
- // src/client/file/_service.ts
194
- var ClientFileService = class extends Context3.Tag("ClientFileService")() {
195
- };
196
- var ClientFileServiceDefault = Micro4.gen(function* () {
197
- const config = yield* Micro4.service(TgBotClientConfig);
198
- const execute2 = yield* Micro4.service(ClientExecuteRequestService);
199
- return {
200
- getFile: (input) => getFile(input.file_id, config, execute2)
201
- };
202
- }).pipe(
203
- Micro4.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault)
204
- );
205
-
206
- // src/client/_client.ts
207
- var makeTgBotClient = (input) => {
208
- const config = makeTgBotClientConfig(input);
209
- const client = Micro5.gen(function* () {
210
- const execute2 = yield* Micro5.service(ClientExecuteRequestService);
211
- const file = yield* Micro5.service(ClientFileService);
212
- return {
213
- execute: (method, input2) => execute2.execute(method, input2).pipe(Micro5.runPromise),
214
- getFile: (input2) => file.getFile(input2).pipe(Micro5.runPromise)
215
- };
216
- }).pipe(
217
- Micro5.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault),
218
- Micro5.provideServiceEffect(ClientFileService, ClientFileServiceDefault),
219
- Micro5.provideService(TgBotClientConfig, config),
220
- Micro5.runSync
221
- );
222
- return client;
223
- };
224
-
225
- // src/bot/run.ts
226
- var Micro12 = __toESM(require("effect/Micro"));
227
-
228
- // src/bot/factory/_service.ts
229
- var Micro11 = __toESM(require("effect/Micro"));
230
- var Context5 = __toESM(require("effect/Context"));
231
-
232
- // src/bot/update-poller/_service.ts
233
- var Micro8 = __toESM(require("effect/Micro"));
234
- var Context4 = __toESM(require("effect/Context"));
235
-
236
- // src/bot/update-poller/poll-and-handle.ts
237
- var Micro7 = __toESM(require("effect/Micro"));
238
-
239
- // src/bot/update-poller/settings.ts
240
- var makeSettingsFrom = (input) => {
241
- let limit = input.batch_size ?? 10;
242
- let timeout = input.timeout ?? 10;
243
- let max_empty_responses = input.max_empty_responses;
244
- let update_types = input.update_types;
245
- let log_level = input.log_level;
246
- if (limit < 10 || limit > 100) {
247
- console.warn("Wrong limit, must be in [10..100], using 10 instead");
248
- limit = 10;
249
- }
250
- if (timeout < 2 || timeout > 10) {
251
- console.warn("Wrong timeout, must be in [2..10], using 2 instead");
252
- limit = 10;
253
- }
254
- if (max_empty_responses && max_empty_responses < 2) {
255
- console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
256
- max_empty_responses = void 0;
257
- }
258
- if (max_empty_responses && max_empty_responses < 2) {
259
- console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
260
- max_empty_responses = void 0;
261
- }
262
- if (!update_types) {
263
- console.info("Handling only messages, ignoring others");
264
- update_types = ["message"];
265
- }
266
- if (!log_level) {
267
- log_level = "info";
268
- }
269
- return {
270
- limit,
271
- timeout,
272
- max_empty_responses,
273
- update_types,
274
- log_level
275
- };
276
- };
277
-
278
215
  // src/bot/update-poller/fetch-updates.ts
279
- var Micro6 = __toESM(require("effect/Micro"));
280
-
281
- // src/bot/message-handler/utils.ts
282
- var extractUpdate = (input) => {
283
- for (const [field, value] of Object.entries(input)) {
284
- if (field == "update_id") {
285
- continue;
286
- }
287
- return {
288
- type: field,
289
- ...value
290
- };
291
- }
292
- return;
293
- };
294
-
295
- // src/bot/update-poller/fetch-updates.ts
296
- var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.gen(function* () {
216
+ var fetchUpdates = ({ state, settings, handlers }) => Micro2.gen(function* () {
297
217
  const updateId = state.lastUpdateId;
298
218
  if (settings.log_level == "debug") {
299
219
  console.debug("getting updates", state);
300
220
  }
301
- const updates = yield* execute2("get_updates", {
221
+ const updates = yield* execute("get_updates", {
302
222
  ...settings,
303
223
  ...updateId ? { offset: updateId } : void 0
304
224
  }).pipe(
305
- Micro6.andThen((_) => _.sort((_2) => _2.update_id))
225
+ Micro2.andThen((_) => _.sort((_2) => _2.update_id))
306
226
  );
307
227
  let lastSuccessId = void 0;
308
228
  let hasError = false;
@@ -336,7 +256,7 @@ var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.
336
256
  }
337
257
  const handleResult = handler(update);
338
258
  if ("chat" in update && handleResult) {
339
- const response = yield* execute2(`send_${handleResult.type}`, {
259
+ const response = yield* execute(`send_${handleResult.type}`, {
340
260
  ...handleResult,
341
261
  chat_id: update.chat.id
342
262
  });
@@ -351,7 +271,7 @@ var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.
351
271
  lastSuccessId = updateObject.update_id;
352
272
  }
353
273
  if (hasError && lastSuccessId) {
354
- yield* execute2("get_updates", {
274
+ yield* execute("get_updates", {
355
275
  offset: lastSuccessId,
356
276
  limit: 0
357
277
  });
@@ -369,15 +289,14 @@ var pollAndHandle = (input) => {
369
289
  emptyResponses: 0
370
290
  };
371
291
  const settings = makeSettingsFrom(input.settings);
372
- return Micro7.delay(1e3)(
292
+ return Micro3.delay(1e3)(
373
293
  fetchUpdates({
374
294
  state,
375
295
  settings,
376
- execute: input.execute,
377
296
  handlers: input.settings
378
297
  })
379
298
  ).pipe(
380
- Micro7.repeat({
299
+ Micro3.repeat({
381
300
  while: ({ updates, lastSuccessId, hasError }) => {
382
301
  if (hasError) {
383
302
  console.info("error in handler, quitting");
@@ -403,22 +322,19 @@ var pollAndHandle = (input) => {
403
322
  };
404
323
 
405
324
  // src/bot/update-poller/_service.ts
406
- var BotUpdatePollerService = class extends Context4.Tag("BotUpdatePollerService")() {
325
+ var BotUpdatePollerService = class extends Context2.Tag("BotUpdatePollerService")() {
407
326
  };
408
- var BotUpdatesPollerServiceDefault = Micro8.gen(function* () {
327
+ var BotUpdatesPollerServiceDefault = Micro4.gen(function* () {
409
328
  console.log("Initiating BotUpdatesPollerServiceDefault");
410
329
  const state = {
411
330
  fiber: void 0
412
331
  };
413
- const client = yield* Micro8.service(ClientExecuteRequestService);
414
- const runBot = (messageHandler) => Micro8.gen(function* () {
415
- console.log(state);
332
+ const runBot = (messageHandler) => Micro4.gen(function* () {
416
333
  const startFiber = pollAndHandle({
417
- settings: messageHandler,
418
- execute: client.execute
334
+ settings: messageHandler
419
335
  }).pipe(
420
- Micro8.forkDaemon,
421
- Micro8.tap(
336
+ Micro4.forkDaemon,
337
+ Micro4.tap(
422
338
  (fiber) => fiber.addObserver((exit) => {
423
339
  console.log("bot's fiber has been closed", exit);
424
340
  if (messageHandler.onExit) {
@@ -429,83 +345,156 @@ var BotUpdatesPollerServiceDefault = Micro8.gen(function* () {
429
345
  );
430
346
  if (state.fiber) {
431
347
  console.log("killing previous bot's fiber");
432
- yield* Micro8.fiberInterrupt(state.fiber);
348
+ yield* Micro4.fiberInterrupt(state.fiber);
433
349
  }
434
350
  state.fiber = yield* startFiber;
435
- console.log("Reading bot's updates.....", state.fiber == null);
351
+ console.log("Fetching bot updates via long polling...");
436
352
  return state.fiber;
437
353
  });
438
354
  return {
439
355
  runBot
440
356
  };
441
- }).pipe(
442
- Micro8.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault)
443
- );
357
+ });
444
358
 
445
359
  // src/bot/factory/client-config.ts
446
- var Micro9 = __toESM(require("effect/Micro"));
447
- var makeClientConfigFrom = (input) => Micro9.gen(function* () {
360
+ var Micro5 = __toESM(require("effect/Micro"));
361
+ var makeClientConfigFrom = (input) => Micro5.gen(function* () {
448
362
  if (input.type == "config") {
449
363
  return makeTgBotClientConfig(input);
450
364
  }
451
- const config = yield* Micro9.tryPromise({
365
+ const config = yield* Micro5.tryPromise({
452
366
  try: async () => {
453
367
  const { readFileSync } = await import("fs");
454
368
  return JSON.parse(await readFileSync("config.json", "utf-8"));
455
369
  },
456
370
  catch: (error) => {
457
- console.warn(error);
371
+ console.warn("invalid tg bot config", error);
458
372
  return "ReadingConfigError";
459
373
  }
460
374
  });
461
375
  if (!isTgBotClientSettingsInput(config)) {
462
- return yield* Micro9.fail("InvalidConfig");
376
+ return yield* Micro5.fail("InvalidConfig");
463
377
  }
464
378
  return makeTgBotClientConfig(config);
465
379
  });
466
380
 
467
381
  // src/bot/factory/make-bot.ts
468
- var Micro10 = __toESM(require("effect/Micro"));
469
- var makeBot = (messageHandler) => Micro10.gen(function* () {
470
- const { runBot } = yield* Micro10.service(BotUpdatePollerService);
382
+ var Micro6 = __toESM(require("effect/Micro"));
383
+ var makeBot = (messageHandler) => Micro6.gen(function* () {
384
+ const { runBot } = yield* Micro6.service(BotUpdatePollerService);
385
+ const fiber = yield* runBot(messageHandler);
386
+ const interrupt = Micro6.fiberInterrupt(fiber);
471
387
  return {
472
- fiber: yield* runBot(messageHandler),
473
- runBot
388
+ runBot,
389
+ interrupt
474
390
  };
475
391
  }).pipe(
476
- Micro10.tapError((error) => {
392
+ Micro6.tapError((error) => {
477
393
  console.error(error);
478
- return Micro10.void;
394
+ return Micro6.void;
479
395
  })
480
396
  );
481
397
 
482
398
  // src/bot/factory/_service.ts
483
- var BotFactoryService = class extends Context5.Tag("BotFactoryService")() {
399
+ var BotFactoryService = class extends Context3.Tag("BotFactoryService")() {
484
400
  };
485
401
  var BotFactoryServiceDefault = {
486
402
  makeBot,
487
- runBot: (input) => Micro11.gen(function* () {
488
- console.log("client");
489
- const client = yield* makeClientConfigFrom(input);
403
+ runBot: (input) => Micro7.gen(function* () {
404
+ const client = Context3.make(TgBotClientConfig, yield* makeClientConfigFrom(input));
490
405
  const poller = yield* BotUpdatesPollerServiceDefault.pipe(
491
- Micro11.provideService(TgBotClientConfig, client)
406
+ Micro7.provideContext(client)
492
407
  );
493
408
  const bot = yield* makeBot(input).pipe(
494
- Micro11.provideService(BotUpdatePollerService, poller)
409
+ Micro7.provideContext(client),
410
+ Micro7.provideService(BotUpdatePollerService, poller)
411
+ );
412
+ const reload = (input2) => bot.runBot(input2).pipe(
413
+ Micro7.provideContext(client)
495
414
  );
496
- const reload = (input2) => bot.runBot(input2).pipe(Micro11.runPromise);
497
415
  return {
498
- reload
416
+ reload,
417
+ bot
499
418
  };
500
419
  })
501
420
  };
502
421
 
503
422
  // src/bot/run.ts
504
- var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(Micro12.runPromise);
423
+ var Micro8 = __toESM(require("effect/Micro"));
424
+ var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(Micro8.runPromise);
425
+
426
+ // src/client/_client.ts
427
+ var Micro11 = __toESM(require("effect/Micro"));
428
+
429
+ // src/client/file/_service.ts
430
+ var Micro10 = __toESM(require("effect/Micro"));
431
+ var Context4 = __toESM(require("effect/Context"));
432
+
433
+ // src/client/file/get-file.ts
434
+ var Micro9 = __toESM(require("effect/Micro"));
435
+ var getFile = (fileId) => Micro9.gen(function* () {
436
+ const response = yield* execute("get_file", { file_id: fileId });
437
+ const config = yield* Micro9.service(TgBotClientConfig);
438
+ const file_path = response.file_path;
439
+ if (!file_path || file_path.length == 0) {
440
+ return yield* Micro9.fail(
441
+ new TgBotClientError({
442
+ reason: {
443
+ type: "UnableToGetFile",
444
+ cause: "File path not defined"
445
+ }
446
+ })
447
+ );
448
+ }
449
+ const file_name = file_path.replaceAll("/", "-");
450
+ const url = `${config.base_url}/file/bot${config.bot_token}/${file_path}`;
451
+ const fileContent = yield* Micro9.tryPromise({
452
+ try: () => fetch(url).then((_) => _.arrayBuffer()),
453
+ catch: (cause) => new TgBotClientError({
454
+ reason: { type: "UnableToGetFile", cause }
455
+ })
456
+ });
457
+ const file = new File([new Uint8Array(fileContent)], file_name);
458
+ return file;
459
+ });
460
+
461
+ // src/client/file/_service.ts
462
+ var ClientFileService = class extends Context4.Tag("ClientFileService")() {
463
+ };
464
+ var ClientFileServiceDefault = Micro10.gen(function* () {
465
+ return {
466
+ getFile: (input) => getFile(input.file_id)
467
+ };
468
+ });
469
+
470
+ // src/client/_client.ts
471
+ var makeTgBotClient = (input) => {
472
+ const config = makeTgBotClientConfig(input);
473
+ const client = Micro11.gen(function* () {
474
+ const file = yield* Micro11.service(ClientFileService);
475
+ return {
476
+ execute: (method, input2) => execute(method, input2).pipe(
477
+ Micro11.provideService(TgBotClientConfig, config),
478
+ Micro11.runPromise
479
+ ),
480
+ getFile: (input2) => file.getFile(input2).pipe(
481
+ Micro11.provideService(TgBotClientConfig, config),
482
+ Micro11.runPromise
483
+ )
484
+ };
485
+ }).pipe(
486
+ Micro11.provideServiceEffect(ClientFileService, ClientFileServiceDefault),
487
+ Micro11.provideService(TgBotClientConfig, config),
488
+ Micro11.runSync
489
+ );
490
+ return client;
491
+ };
505
492
  // Annotate the CommonJS export names for ESM import in node:
506
493
  0 && (module.exports = {
507
494
  BotFactoryService,
508
495
  BotFactoryServiceDefault,
496
+ BotUpdatePollerService,
497
+ BotUpdatesPollerServiceDefault,
509
498
  MESSAGE_EFFECTS,
510
499
  defaultBaseUrl,
511
500
  isMessageEffect,
package/dist/index.mjs CHANGED
@@ -1,5 +1,84 @@
1
- // src/client/_client.ts
2
- import * as Micro5 from "effect/Micro";
1
+ // src/bot/factory/_service.ts
2
+ import * as Micro7 from "effect/Micro";
3
+ import * as Context3 from "effect/Context";
4
+
5
+ // src/bot/update-poller/_service.ts
6
+ import * as Micro4 from "effect/Micro";
7
+ import * as Context2 from "effect/Context";
8
+
9
+ // src/bot/update-poller/poll-and-handle.ts
10
+ import * as Micro3 from "effect/Micro";
11
+
12
+ // src/bot/update-poller/settings.ts
13
+ var makeSettingsFrom = (input) => {
14
+ let limit = input.batch_size ?? 10;
15
+ let timeout = input.timeout ?? 10;
16
+ let max_empty_responses = input.max_empty_responses;
17
+ let update_types = input.update_types;
18
+ let log_level = input.log_level;
19
+ if (limit < 10 || limit > 100) {
20
+ console.warn("Wrong limit, must be in [10..100], using 10 instead");
21
+ limit = 10;
22
+ }
23
+ if (timeout < 2 || timeout > 10) {
24
+ console.warn("Wrong timeout, must be in [2..10], using 2 instead");
25
+ limit = 10;
26
+ }
27
+ if (max_empty_responses && max_empty_responses < 2) {
28
+ console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
29
+ max_empty_responses = void 0;
30
+ }
31
+ if (max_empty_responses && max_empty_responses < 2) {
32
+ console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
33
+ max_empty_responses = void 0;
34
+ }
35
+ if (!update_types) {
36
+ console.info("Handling only messages, ignoring others");
37
+ update_types = ["message"];
38
+ }
39
+ if (!log_level) {
40
+ log_level = "info";
41
+ }
42
+ return {
43
+ limit,
44
+ timeout,
45
+ max_empty_responses,
46
+ update_types,
47
+ log_level
48
+ };
49
+ };
50
+
51
+ // src/bot/update-poller/fetch-updates.ts
52
+ import * as Micro2 from "effect/Micro";
53
+
54
+ // src/bot/message-handler/utils.ts
55
+ var extractUpdate = (input) => {
56
+ for (const [field, value] of Object.entries(input)) {
57
+ if (field == "update_id") {
58
+ continue;
59
+ }
60
+ return {
61
+ type: field,
62
+ ...value
63
+ };
64
+ }
65
+ return;
66
+ };
67
+
68
+ // src/client/execute-request/execute.ts
69
+ import * as Micro from "effect/Micro";
70
+ import * as String from "effect/String";
71
+
72
+ // src/client/errors.ts
73
+ import * as Data from "effect/Data";
74
+ var TgBotClientError = class _TgBotClientError extends Data.TaggedError("TgBotClientError") {
75
+ static missingSuccess = new _TgBotClientError({
76
+ reason: {
77
+ type: "ClientInternalError",
78
+ cause: "Expected 'success' to be defined"
79
+ }
80
+ });
81
+ };
3
82
 
4
83
  // src/client/config.ts
5
84
  import * as Context from "effect/Context";
@@ -27,25 +106,6 @@ var makeTgBotClientConfig = (input) => TgBotClientConfig.of({
27
106
  var TgBotClientConfig = class extends Context.Tag("TgBotClientConfig")() {
28
107
  };
29
108
 
30
- // src/client/execute-request/_service.ts
31
- import * as Micro2 from "effect/Micro";
32
- import * as Context2 from "effect/Context";
33
-
34
- // src/client/execute-request/execute.ts
35
- import * as Micro from "effect/Micro";
36
- import * as String from "effect/String";
37
-
38
- // src/client/errors.ts
39
- import * as Data from "effect/Data";
40
- var TgBotClientError = class _TgBotClientError extends Data.TaggedError("TgBotClientError") {
41
- static missingSuccess = new _TgBotClientError({
42
- reason: {
43
- type: "ClientInternalError",
44
- cause: "Expected 'success' to be defined"
45
- }
46
- });
47
- };
48
-
49
109
  // src/client/guards.ts
50
110
  var isFileContent = (input) => typeof input == "object" && input != null && ("file_content" in input && input.file_content instanceof Uint8Array) && ("file_name" in input && typeof input.file_name == "string");
51
111
  var isTgBotApiResponse = (input) => typeof input == "object" && input != null && ("ok" in input && typeof input.ok == "boolean");
@@ -70,7 +130,8 @@ var makePayload = (body) => {
70
130
  };
71
131
 
72
132
  // src/client/execute-request/execute.ts
73
- var execute = (config, method, input) => Micro.gen(function* () {
133
+ var execute = (method, input) => Micro.gen(function* () {
134
+ const config = yield* Micro.service(TgBotClientConfig);
74
135
  const httpResponse = yield* Micro.tryPromise({
75
136
  try: () => fetch(
76
137
  `${config.base_url}/bot${config.bot_token}/${String.snakeToCamel(method)}`,
@@ -106,160 +167,17 @@ var execute = (config, method, input) => Micro.gen(function* () {
106
167
  return response.result;
107
168
  });
108
169
 
109
- // src/client/execute-request/_service.ts
110
- var ClientExecuteRequestService = class extends Context2.Tag("ClientExecuteRequestService")() {
111
- };
112
- var ClientExecuteRequestServiceDefault = Micro2.gen(function* () {
113
- const config = yield* Micro2.service(TgBotClientConfig);
114
- return {
115
- execute: (method, input) => execute(config, method, input)
116
- };
117
- });
118
-
119
- // src/client/file/_service.ts
120
- import * as Micro4 from "effect/Micro";
121
- import * as Context3 from "effect/Context";
122
-
123
- // src/client/file/get-file.ts
124
- import * as Micro3 from "effect/Micro";
125
- var getFile = (fileId, config, execute2) => Micro3.gen(function* () {
126
- const response = yield* execute2.execute("get_file", { file_id: fileId });
127
- const file_path = response.file_path;
128
- if (!file_path || file_path.length == 0) {
129
- return yield* Micro3.fail(
130
- new TgBotClientError({
131
- reason: {
132
- type: "UnableToGetFile",
133
- cause: "File path not defined"
134
- }
135
- })
136
- );
137
- }
138
- const file_name = file_path.replaceAll("/", "-");
139
- const url = `${config.base_url}/file/bot${config.bot_token}/${file_path}`;
140
- const fileContent = yield* Micro3.tryPromise({
141
- try: () => fetch(url).then((_) => _.arrayBuffer()),
142
- catch: (cause) => new TgBotClientError({
143
- reason: { type: "UnableToGetFile", cause }
144
- })
145
- });
146
- const file = new File([new Uint8Array(fileContent)], file_name);
147
- return file;
148
- });
149
-
150
- // src/client/file/_service.ts
151
- var ClientFileService = class extends Context3.Tag("ClientFileService")() {
152
- };
153
- var ClientFileServiceDefault = Micro4.gen(function* () {
154
- const config = yield* Micro4.service(TgBotClientConfig);
155
- const execute2 = yield* Micro4.service(ClientExecuteRequestService);
156
- return {
157
- getFile: (input) => getFile(input.file_id, config, execute2)
158
- };
159
- }).pipe(
160
- Micro4.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault)
161
- );
162
-
163
- // src/client/_client.ts
164
- var makeTgBotClient = (input) => {
165
- const config = makeTgBotClientConfig(input);
166
- const client = Micro5.gen(function* () {
167
- const execute2 = yield* Micro5.service(ClientExecuteRequestService);
168
- const file = yield* Micro5.service(ClientFileService);
169
- return {
170
- execute: (method, input2) => execute2.execute(method, input2).pipe(Micro5.runPromise),
171
- getFile: (input2) => file.getFile(input2).pipe(Micro5.runPromise)
172
- };
173
- }).pipe(
174
- Micro5.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault),
175
- Micro5.provideServiceEffect(ClientFileService, ClientFileServiceDefault),
176
- Micro5.provideService(TgBotClientConfig, config),
177
- Micro5.runSync
178
- );
179
- return client;
180
- };
181
-
182
- // src/bot/run.ts
183
- import * as Micro12 from "effect/Micro";
184
-
185
- // src/bot/factory/_service.ts
186
- import * as Micro11 from "effect/Micro";
187
- import * as Context5 from "effect/Context";
188
-
189
- // src/bot/update-poller/_service.ts
190
- import * as Micro8 from "effect/Micro";
191
- import * as Context4 from "effect/Context";
192
-
193
- // src/bot/update-poller/poll-and-handle.ts
194
- import * as Micro7 from "effect/Micro";
195
-
196
- // src/bot/update-poller/settings.ts
197
- var makeSettingsFrom = (input) => {
198
- let limit = input.batch_size ?? 10;
199
- let timeout = input.timeout ?? 10;
200
- let max_empty_responses = input.max_empty_responses;
201
- let update_types = input.update_types;
202
- let log_level = input.log_level;
203
- if (limit < 10 || limit > 100) {
204
- console.warn("Wrong limit, must be in [10..100], using 10 instead");
205
- limit = 10;
206
- }
207
- if (timeout < 2 || timeout > 10) {
208
- console.warn("Wrong timeout, must be in [2..10], using 2 instead");
209
- limit = 10;
210
- }
211
- if (max_empty_responses && max_empty_responses < 2) {
212
- console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
213
- max_empty_responses = void 0;
214
- }
215
- if (max_empty_responses && max_empty_responses < 2) {
216
- console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
217
- max_empty_responses = void 0;
218
- }
219
- if (!update_types) {
220
- console.info("Handling only messages, ignoring others");
221
- update_types = ["message"];
222
- }
223
- if (!log_level) {
224
- log_level = "info";
225
- }
226
- return {
227
- limit,
228
- timeout,
229
- max_empty_responses,
230
- update_types,
231
- log_level
232
- };
233
- };
234
-
235
170
  // src/bot/update-poller/fetch-updates.ts
236
- import * as Micro6 from "effect/Micro";
237
-
238
- // src/bot/message-handler/utils.ts
239
- var extractUpdate = (input) => {
240
- for (const [field, value] of Object.entries(input)) {
241
- if (field == "update_id") {
242
- continue;
243
- }
244
- return {
245
- type: field,
246
- ...value
247
- };
248
- }
249
- return;
250
- };
251
-
252
- // src/bot/update-poller/fetch-updates.ts
253
- var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.gen(function* () {
171
+ var fetchUpdates = ({ state, settings, handlers }) => Micro2.gen(function* () {
254
172
  const updateId = state.lastUpdateId;
255
173
  if (settings.log_level == "debug") {
256
174
  console.debug("getting updates", state);
257
175
  }
258
- const updates = yield* execute2("get_updates", {
176
+ const updates = yield* execute("get_updates", {
259
177
  ...settings,
260
178
  ...updateId ? { offset: updateId } : void 0
261
179
  }).pipe(
262
- Micro6.andThen((_) => _.sort((_2) => _2.update_id))
180
+ Micro2.andThen((_) => _.sort((_2) => _2.update_id))
263
181
  );
264
182
  let lastSuccessId = void 0;
265
183
  let hasError = false;
@@ -293,7 +211,7 @@ var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.
293
211
  }
294
212
  const handleResult = handler(update);
295
213
  if ("chat" in update && handleResult) {
296
- const response = yield* execute2(`send_${handleResult.type}`, {
214
+ const response = yield* execute(`send_${handleResult.type}`, {
297
215
  ...handleResult,
298
216
  chat_id: update.chat.id
299
217
  });
@@ -308,7 +226,7 @@ var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.
308
226
  lastSuccessId = updateObject.update_id;
309
227
  }
310
228
  if (hasError && lastSuccessId) {
311
- yield* execute2("get_updates", {
229
+ yield* execute("get_updates", {
312
230
  offset: lastSuccessId,
313
231
  limit: 0
314
232
  });
@@ -326,15 +244,14 @@ var pollAndHandle = (input) => {
326
244
  emptyResponses: 0
327
245
  };
328
246
  const settings = makeSettingsFrom(input.settings);
329
- return Micro7.delay(1e3)(
247
+ return Micro3.delay(1e3)(
330
248
  fetchUpdates({
331
249
  state,
332
250
  settings,
333
- execute: input.execute,
334
251
  handlers: input.settings
335
252
  })
336
253
  ).pipe(
337
- Micro7.repeat({
254
+ Micro3.repeat({
338
255
  while: ({ updates, lastSuccessId, hasError }) => {
339
256
  if (hasError) {
340
257
  console.info("error in handler, quitting");
@@ -360,22 +277,19 @@ var pollAndHandle = (input) => {
360
277
  };
361
278
 
362
279
  // src/bot/update-poller/_service.ts
363
- var BotUpdatePollerService = class extends Context4.Tag("BotUpdatePollerService")() {
280
+ var BotUpdatePollerService = class extends Context2.Tag("BotUpdatePollerService")() {
364
281
  };
365
- var BotUpdatesPollerServiceDefault = Micro8.gen(function* () {
282
+ var BotUpdatesPollerServiceDefault = Micro4.gen(function* () {
366
283
  console.log("Initiating BotUpdatesPollerServiceDefault");
367
284
  const state = {
368
285
  fiber: void 0
369
286
  };
370
- const client = yield* Micro8.service(ClientExecuteRequestService);
371
- const runBot = (messageHandler) => Micro8.gen(function* () {
372
- console.log(state);
287
+ const runBot = (messageHandler) => Micro4.gen(function* () {
373
288
  const startFiber = pollAndHandle({
374
- settings: messageHandler,
375
- execute: client.execute
289
+ settings: messageHandler
376
290
  }).pipe(
377
- Micro8.forkDaemon,
378
- Micro8.tap(
291
+ Micro4.forkDaemon,
292
+ Micro4.tap(
379
293
  (fiber) => fiber.addObserver((exit) => {
380
294
  console.log("bot's fiber has been closed", exit);
381
295
  if (messageHandler.onExit) {
@@ -386,82 +300,155 @@ var BotUpdatesPollerServiceDefault = Micro8.gen(function* () {
386
300
  );
387
301
  if (state.fiber) {
388
302
  console.log("killing previous bot's fiber");
389
- yield* Micro8.fiberInterrupt(state.fiber);
303
+ yield* Micro4.fiberInterrupt(state.fiber);
390
304
  }
391
305
  state.fiber = yield* startFiber;
392
- console.log("Reading bot's updates.....", state.fiber == null);
306
+ console.log("Fetching bot updates via long polling...");
393
307
  return state.fiber;
394
308
  });
395
309
  return {
396
310
  runBot
397
311
  };
398
- }).pipe(
399
- Micro8.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault)
400
- );
312
+ });
401
313
 
402
314
  // src/bot/factory/client-config.ts
403
- import * as Micro9 from "effect/Micro";
404
- var makeClientConfigFrom = (input) => Micro9.gen(function* () {
315
+ import * as Micro5 from "effect/Micro";
316
+ var makeClientConfigFrom = (input) => Micro5.gen(function* () {
405
317
  if (input.type == "config") {
406
318
  return makeTgBotClientConfig(input);
407
319
  }
408
- const config = yield* Micro9.tryPromise({
320
+ const config = yield* Micro5.tryPromise({
409
321
  try: async () => {
410
322
  const { readFileSync } = await import("fs");
411
323
  return JSON.parse(await readFileSync("config.json", "utf-8"));
412
324
  },
413
325
  catch: (error) => {
414
- console.warn(error);
326
+ console.warn("invalid tg bot config", error);
415
327
  return "ReadingConfigError";
416
328
  }
417
329
  });
418
330
  if (!isTgBotClientSettingsInput(config)) {
419
- return yield* Micro9.fail("InvalidConfig");
331
+ return yield* Micro5.fail("InvalidConfig");
420
332
  }
421
333
  return makeTgBotClientConfig(config);
422
334
  });
423
335
 
424
336
  // src/bot/factory/make-bot.ts
425
- import * as Micro10 from "effect/Micro";
426
- var makeBot = (messageHandler) => Micro10.gen(function* () {
427
- const { runBot } = yield* Micro10.service(BotUpdatePollerService);
337
+ import * as Micro6 from "effect/Micro";
338
+ var makeBot = (messageHandler) => Micro6.gen(function* () {
339
+ const { runBot } = yield* Micro6.service(BotUpdatePollerService);
340
+ const fiber = yield* runBot(messageHandler);
341
+ const interrupt = Micro6.fiberInterrupt(fiber);
428
342
  return {
429
- fiber: yield* runBot(messageHandler),
430
- runBot
343
+ runBot,
344
+ interrupt
431
345
  };
432
346
  }).pipe(
433
- Micro10.tapError((error) => {
347
+ Micro6.tapError((error) => {
434
348
  console.error(error);
435
- return Micro10.void;
349
+ return Micro6.void;
436
350
  })
437
351
  );
438
352
 
439
353
  // src/bot/factory/_service.ts
440
- var BotFactoryService = class extends Context5.Tag("BotFactoryService")() {
354
+ var BotFactoryService = class extends Context3.Tag("BotFactoryService")() {
441
355
  };
442
356
  var BotFactoryServiceDefault = {
443
357
  makeBot,
444
- runBot: (input) => Micro11.gen(function* () {
445
- console.log("client");
446
- const client = yield* makeClientConfigFrom(input);
358
+ runBot: (input) => Micro7.gen(function* () {
359
+ const client = Context3.make(TgBotClientConfig, yield* makeClientConfigFrom(input));
447
360
  const poller = yield* BotUpdatesPollerServiceDefault.pipe(
448
- Micro11.provideService(TgBotClientConfig, client)
361
+ Micro7.provideContext(client)
449
362
  );
450
363
  const bot = yield* makeBot(input).pipe(
451
- Micro11.provideService(BotUpdatePollerService, poller)
364
+ Micro7.provideContext(client),
365
+ Micro7.provideService(BotUpdatePollerService, poller)
366
+ );
367
+ const reload = (input2) => bot.runBot(input2).pipe(
368
+ Micro7.provideContext(client)
452
369
  );
453
- const reload = (input2) => bot.runBot(input2).pipe(Micro11.runPromise);
454
370
  return {
455
- reload
371
+ reload,
372
+ bot
456
373
  };
457
374
  })
458
375
  };
459
376
 
460
377
  // src/bot/run.ts
461
- var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(Micro12.runPromise);
378
+ import * as Micro8 from "effect/Micro";
379
+ var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(Micro8.runPromise);
380
+
381
+ // src/client/_client.ts
382
+ import * as Micro11 from "effect/Micro";
383
+
384
+ // src/client/file/_service.ts
385
+ import * as Micro10 from "effect/Micro";
386
+ import * as Context4 from "effect/Context";
387
+
388
+ // src/client/file/get-file.ts
389
+ import * as Micro9 from "effect/Micro";
390
+ var getFile = (fileId) => Micro9.gen(function* () {
391
+ const response = yield* execute("get_file", { file_id: fileId });
392
+ const config = yield* Micro9.service(TgBotClientConfig);
393
+ const file_path = response.file_path;
394
+ if (!file_path || file_path.length == 0) {
395
+ return yield* Micro9.fail(
396
+ new TgBotClientError({
397
+ reason: {
398
+ type: "UnableToGetFile",
399
+ cause: "File path not defined"
400
+ }
401
+ })
402
+ );
403
+ }
404
+ const file_name = file_path.replaceAll("/", "-");
405
+ const url = `${config.base_url}/file/bot${config.bot_token}/${file_path}`;
406
+ const fileContent = yield* Micro9.tryPromise({
407
+ try: () => fetch(url).then((_) => _.arrayBuffer()),
408
+ catch: (cause) => new TgBotClientError({
409
+ reason: { type: "UnableToGetFile", cause }
410
+ })
411
+ });
412
+ const file = new File([new Uint8Array(fileContent)], file_name);
413
+ return file;
414
+ });
415
+
416
+ // src/client/file/_service.ts
417
+ var ClientFileService = class extends Context4.Tag("ClientFileService")() {
418
+ };
419
+ var ClientFileServiceDefault = Micro10.gen(function* () {
420
+ return {
421
+ getFile: (input) => getFile(input.file_id)
422
+ };
423
+ });
424
+
425
+ // src/client/_client.ts
426
+ var makeTgBotClient = (input) => {
427
+ const config = makeTgBotClientConfig(input);
428
+ const client = Micro11.gen(function* () {
429
+ const file = yield* Micro11.service(ClientFileService);
430
+ return {
431
+ execute: (method, input2) => execute(method, input2).pipe(
432
+ Micro11.provideService(TgBotClientConfig, config),
433
+ Micro11.runPromise
434
+ ),
435
+ getFile: (input2) => file.getFile(input2).pipe(
436
+ Micro11.provideService(TgBotClientConfig, config),
437
+ Micro11.runPromise
438
+ )
439
+ };
440
+ }).pipe(
441
+ Micro11.provideServiceEffect(ClientFileService, ClientFileServiceDefault),
442
+ Micro11.provideService(TgBotClientConfig, config),
443
+ Micro11.runSync
444
+ );
445
+ return client;
446
+ };
462
447
  export {
463
448
  BotFactoryService,
464
449
  BotFactoryServiceDefault,
450
+ BotUpdatePollerService,
451
+ BotUpdatesPollerServiceDefault,
465
452
  MESSAGE_EFFECTS,
466
453
  defaultBaseUrl,
467
454
  isMessageEffect,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-ak/tg-bot-client",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "homepage": "https://effect-ak.github.io/telegram-bot-client",
5
5
  "author": {
6
6
  "name": "Aleksandr Kondaurov",