@effect-ak/tg-bot-client 0.3.2 → 0.3.3
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 +29 -52
- package/dist/index.js +52 -61
- package/dist/index.mjs +52 -61
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2725,20 +2725,6 @@ interface UploadStickerFileInput {
|
|
|
2725
2725
|
sticker_format: "static" | "animated" | "video";
|
|
2726
2726
|
}
|
|
2727
2727
|
|
|
2728
|
-
declare const TgBotClientConfig_base: Context.TagClass<TgBotClientConfig, "TgBotClientConfig", Required<TgBotClientSettingsInput>>;
|
|
2729
|
-
declare class TgBotClientConfig extends TgBotClientConfig_base {
|
|
2730
|
-
}
|
|
2731
|
-
|
|
2732
|
-
type PollAndHandleInput = {
|
|
2733
|
-
settings: BotMessageHandlerSettings;
|
|
2734
|
-
};
|
|
2735
|
-
type PollAndHandleResult = Micro.Micro.Success<ReturnType<typeof pollAndHandle>>;
|
|
2736
|
-
declare const pollAndHandle: (input: PollAndHandleInput) => Micro.Micro<{
|
|
2737
|
-
updates: Update[];
|
|
2738
|
-
lastSuccessId: number | undefined;
|
|
2739
|
-
hasError: boolean;
|
|
2740
|
-
}, TgBotClientError, TgBotClientConfig>;
|
|
2741
|
-
|
|
2742
2728
|
type AvailableUpdateTypes = Exclude<keyof Update, 'update_id'>;
|
|
2743
2729
|
type LogLevel = "info" | "debug";
|
|
2744
2730
|
type BotResponse = {
|
|
@@ -2749,38 +2735,23 @@ type BotResponse = {
|
|
|
2749
2735
|
type BotMessageHandlers = {
|
|
2750
2736
|
[K in AvailableUpdateTypes as `on_${K}`]?: (update: NonNullable<Update[K]>) => BotResponse | undefined;
|
|
2751
2737
|
};
|
|
2752
|
-
|
|
2738
|
+
|
|
2739
|
+
type BotMessageHandlerShape = Context.Tag.Service<BotMessageHandler>;
|
|
2740
|
+
declare const BotMessageHandler_base: Context.TagClass<BotMessageHandler, "BotMessageHandler", {
|
|
2753
2741
|
readonly log_level?: LogLevel;
|
|
2754
2742
|
readonly update_types?: AvailableUpdateTypes[];
|
|
2755
2743
|
readonly batch_size?: number;
|
|
2756
2744
|
readonly timeout?: number;
|
|
2757
2745
|
readonly max_empty_responses?: number;
|
|
2758
|
-
} & BotMessageHandlers
|
|
2759
|
-
|
|
2760
|
-
};
|
|
2761
|
-
|
|
2762
|
-
type BotUpdatePollerServiceInterface = Micro.Micro.Success<typeof BotUpdatesPollerServiceDefault>;
|
|
2763
|
-
declare const BotUpdatePollerService_base: Context.TagClass<BotUpdatePollerService, "BotUpdatePollerService", {
|
|
2764
|
-
readonly runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
|
|
2765
|
-
}>;
|
|
2766
|
-
declare class BotUpdatePollerService extends BotUpdatePollerService_base {
|
|
2746
|
+
} & BotMessageHandlers>;
|
|
2747
|
+
declare class BotMessageHandler extends BotMessageHandler_base {
|
|
2767
2748
|
}
|
|
2768
|
-
declare const BotUpdatesPollerServiceDefault: Micro.Micro<{
|
|
2769
|
-
readonly runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
|
|
2770
|
-
}, never, never>;
|
|
2771
2749
|
|
|
2772
2750
|
type BotInstance = Micro.Micro.Success<ReturnType<typeof BotFactoryServiceDefault["runBot"]>>;
|
|
2773
2751
|
declare const BotFactoryService_base: Context.TagClass<BotFactoryService, "BotFactoryService", {
|
|
2774
|
-
makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<{
|
|
2775
|
-
runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
|
|
2776
|
-
interrupt: Micro.Micro<void, never, never>;
|
|
2777
|
-
}, never, TgBotClientConfig | BotUpdatePollerService>;
|
|
2778
2752
|
runBot: (input: RunBotInput) => Micro.Micro<{
|
|
2779
|
-
readonly reload: (input: Partial<RunBotInput>) =>
|
|
2780
|
-
readonly
|
|
2781
|
-
runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
|
|
2782
|
-
interrupt: Micro.Micro<void, never, never>;
|
|
2783
|
-
};
|
|
2753
|
+
readonly reload: (input: Partial<RunBotInput>) => Promise<void>;
|
|
2754
|
+
readonly fiber: () => Micro.MicroFiber<unknown, TgBotClientError> | undefined;
|
|
2784
2755
|
}, string, never>;
|
|
2785
2756
|
}>;
|
|
2786
2757
|
declare class BotFactoryService extends BotFactoryService_base {
|
|
@@ -2789,27 +2760,33 @@ type RunBotInput = ({
|
|
|
2789
2760
|
type: "fromJsonFile";
|
|
2790
2761
|
} | {
|
|
2791
2762
|
type: "config";
|
|
2792
|
-
} & TgBotClientSettingsInput) &
|
|
2763
|
+
} & TgBotClientSettingsInput) & BotMessageHandlerShape;
|
|
2793
2764
|
declare const BotFactoryServiceDefault: {
|
|
2794
|
-
makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<{
|
|
2795
|
-
runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
|
|
2796
|
-
interrupt: Micro.Micro<void, never, never>;
|
|
2797
|
-
}, never, TgBotClientConfig | BotUpdatePollerService>;
|
|
2798
2765
|
runBot: (input: RunBotInput) => Micro.Micro<{
|
|
2799
|
-
readonly reload: (input: Partial<RunBotInput>) =>
|
|
2800
|
-
readonly
|
|
2801
|
-
runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
|
|
2802
|
-
interrupt: Micro.Micro<void, never, never>;
|
|
2803
|
-
};
|
|
2766
|
+
readonly reload: (input: Partial<RunBotInput>) => Promise<void>;
|
|
2767
|
+
readonly fiber: () => Micro.MicroFiber<unknown, TgBotClientError> | undefined;
|
|
2804
2768
|
}, string, never>;
|
|
2805
2769
|
};
|
|
2806
2770
|
|
|
2771
|
+
declare const TgBotClientConfig_base: Context.TagClass<TgBotClientConfig, "TgBotClientConfig", Required<TgBotClientSettingsInput>>;
|
|
2772
|
+
declare class TgBotClientConfig extends TgBotClientConfig_base {
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
type BotUpdatePollerServiceInterface = Micro.Micro.Success<typeof BotUpdatesPollerServiceDefault>;
|
|
2776
|
+
declare const BotUpdatePollerService_base: Context.TagClass<BotUpdatePollerService, "BotUpdatePollerService", {
|
|
2777
|
+
readonly runBot: Micro.Micro<void, never, BotMessageHandler | TgBotClientConfig>;
|
|
2778
|
+
readonly getFiber: () => Micro.MicroFiber<unknown, TgBotClientError> | undefined;
|
|
2779
|
+
}>;
|
|
2780
|
+
declare class BotUpdatePollerService extends BotUpdatePollerService_base {
|
|
2781
|
+
}
|
|
2782
|
+
declare const BotUpdatesPollerServiceDefault: Micro.Micro<{
|
|
2783
|
+
readonly runBot: Micro.Micro<void, never, BotMessageHandler | TgBotClientConfig>;
|
|
2784
|
+
readonly getFiber: () => Micro.MicroFiber<unknown, TgBotClientError> | undefined;
|
|
2785
|
+
}, never, never>;
|
|
2786
|
+
|
|
2807
2787
|
declare const runTgChatBot: (input: RunBotInput) => Promise<{
|
|
2808
|
-
readonly reload: (input: Partial<RunBotInput>) =>
|
|
2809
|
-
readonly
|
|
2810
|
-
runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, TgBotClientConfig>;
|
|
2811
|
-
interrupt: Micro.Micro<void, never, never>;
|
|
2812
|
-
};
|
|
2788
|
+
readonly reload: (input: Partial<RunBotInput>) => Promise<void>;
|
|
2789
|
+
readonly fiber: () => Micro.MicroFiber<unknown, TgBotClientError> | undefined;
|
|
2813
2790
|
}>;
|
|
2814
2791
|
|
|
2815
2792
|
declare const getFile: (fileId: string) => Micro.Micro<File, TgBotClientError, TgBotClientConfig>;
|
|
@@ -2842,4 +2819,4 @@ type MessageEffect = keyof typeof MESSAGE_EFFECTS;
|
|
|
2842
2819
|
declare const messageEffectIdCodes: MessageEffect[];
|
|
2843
2820
|
declare const isMessageEffect: (input: unknown) => input is MessageEffect;
|
|
2844
2821
|
|
|
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
|
|
2822
|
+
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 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
|
@@ -44,12 +44,17 @@ __export(src_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(src_exports);
|
|
45
45
|
|
|
46
46
|
// src/bot/factory/_service.ts
|
|
47
|
-
var
|
|
48
|
-
var
|
|
47
|
+
var Micro6 = __toESM(require("effect/Micro"));
|
|
48
|
+
var Context4 = __toESM(require("effect/Context"));
|
|
49
|
+
|
|
50
|
+
// src/bot/message-handler/_service.ts
|
|
51
|
+
var Context = __toESM(require("effect/Context"));
|
|
52
|
+
var BotMessageHandler = class extends Context.Tag("BotMessageHandler")() {
|
|
53
|
+
};
|
|
49
54
|
|
|
50
55
|
// src/bot/update-poller/_service.ts
|
|
51
56
|
var Micro4 = __toESM(require("effect/Micro"));
|
|
52
|
-
var
|
|
57
|
+
var Context3 = __toESM(require("effect/Context"));
|
|
53
58
|
|
|
54
59
|
// src/bot/update-poller/poll-and-handle.ts
|
|
55
60
|
var Micro3 = __toESM(require("effect/Micro"));
|
|
@@ -126,7 +131,7 @@ var TgBotClientError = class _TgBotClientError extends Data.TaggedError("TgBotCl
|
|
|
126
131
|
};
|
|
127
132
|
|
|
128
133
|
// src/client/config.ts
|
|
129
|
-
var
|
|
134
|
+
var Context2 = __toESM(require("effect/Context"));
|
|
130
135
|
|
|
131
136
|
// src/const.ts
|
|
132
137
|
var defaultBaseUrl = "https://api.telegram.org";
|
|
@@ -148,7 +153,7 @@ var makeTgBotClientConfig = (input) => TgBotClientConfig.of({
|
|
|
148
153
|
...input,
|
|
149
154
|
base_url: input.base_url ?? defaultBaseUrl
|
|
150
155
|
});
|
|
151
|
-
var TgBotClientConfig = class extends
|
|
156
|
+
var TgBotClientConfig = class extends Context2.Tag("TgBotClientConfig")() {
|
|
152
157
|
};
|
|
153
158
|
|
|
154
159
|
// src/client/guards.ts
|
|
@@ -322,14 +327,16 @@ var pollAndHandle = (input) => {
|
|
|
322
327
|
};
|
|
323
328
|
|
|
324
329
|
// src/bot/update-poller/_service.ts
|
|
325
|
-
var BotUpdatePollerService = class extends
|
|
330
|
+
var BotUpdatePollerService = class extends Context3.Tag("BotUpdatePollerService")() {
|
|
326
331
|
};
|
|
327
332
|
var BotUpdatesPollerServiceDefault = Micro4.gen(function* () {
|
|
328
333
|
console.log("Initiating BotUpdatesPollerServiceDefault");
|
|
329
334
|
const state = {
|
|
330
335
|
fiber: void 0
|
|
331
336
|
};
|
|
332
|
-
const runBot =
|
|
337
|
+
const runBot = Micro4.gen(function* () {
|
|
338
|
+
console.log("run bot");
|
|
339
|
+
const messageHandler = yield* Micro4.service(BotMessageHandler);
|
|
333
340
|
const startFiber = pollAndHandle({
|
|
334
341
|
settings: messageHandler
|
|
335
342
|
}).pipe(
|
|
@@ -337,9 +344,6 @@ var BotUpdatesPollerServiceDefault = Micro4.gen(function* () {
|
|
|
337
344
|
Micro4.tap(
|
|
338
345
|
(fiber) => fiber.addObserver((exit) => {
|
|
339
346
|
console.log("bot's fiber has been closed", exit);
|
|
340
|
-
if (messageHandler.onExit) {
|
|
341
|
-
messageHandler.onExit(exit);
|
|
342
|
-
}
|
|
343
347
|
})
|
|
344
348
|
)
|
|
345
349
|
);
|
|
@@ -349,10 +353,10 @@ var BotUpdatesPollerServiceDefault = Micro4.gen(function* () {
|
|
|
349
353
|
}
|
|
350
354
|
state.fiber = yield* startFiber;
|
|
351
355
|
console.log("Fetching bot updates via long polling...");
|
|
352
|
-
return state.fiber;
|
|
353
356
|
});
|
|
354
357
|
return {
|
|
355
|
-
runBot
|
|
358
|
+
runBot,
|
|
359
|
+
getFiber: () => state.fiber
|
|
356
360
|
};
|
|
357
361
|
});
|
|
358
362
|
|
|
@@ -378,66 +382,53 @@ var makeClientConfigFrom = (input) => Micro5.gen(function* () {
|
|
|
378
382
|
return makeTgBotClientConfig(config);
|
|
379
383
|
});
|
|
380
384
|
|
|
381
|
-
// src/bot/factory/make-bot.ts
|
|
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);
|
|
387
|
-
return {
|
|
388
|
-
runBot,
|
|
389
|
-
interrupt
|
|
390
|
-
};
|
|
391
|
-
}).pipe(
|
|
392
|
-
Micro6.tapError((error) => {
|
|
393
|
-
console.error(error);
|
|
394
|
-
return Micro6.void;
|
|
395
|
-
})
|
|
396
|
-
);
|
|
397
|
-
|
|
398
385
|
// src/bot/factory/_service.ts
|
|
399
|
-
var BotFactoryService = class extends
|
|
386
|
+
var BotFactoryService = class extends Context4.Tag("BotFactoryService")() {
|
|
400
387
|
};
|
|
401
388
|
var BotFactoryServiceDefault = {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const client = Context3.make(TgBotClientConfig, yield* makeClientConfigFrom(input));
|
|
389
|
+
runBot: (input) => Micro6.gen(function* () {
|
|
390
|
+
const client = Context4.make(TgBotClientConfig, yield* makeClientConfigFrom(input));
|
|
405
391
|
const poller = yield* BotUpdatesPollerServiceDefault.pipe(
|
|
406
|
-
|
|
392
|
+
Micro6.provideContext(client)
|
|
407
393
|
);
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
394
|
+
yield* poller.runBot.pipe(
|
|
395
|
+
Micro6.provideService(BotMessageHandler, input),
|
|
396
|
+
Micro6.provideContext(client)
|
|
411
397
|
);
|
|
412
|
-
const reload = (input2) =>
|
|
413
|
-
|
|
398
|
+
const reload = (input2) => poller.runBot.pipe(
|
|
399
|
+
Micro6.provideService(BotMessageHandler, input2),
|
|
400
|
+
Micro6.provideContext(client),
|
|
401
|
+
Micro6.runPromise
|
|
414
402
|
);
|
|
415
403
|
return {
|
|
416
404
|
reload,
|
|
417
|
-
|
|
405
|
+
fiber: poller.getFiber
|
|
418
406
|
};
|
|
419
407
|
})
|
|
420
408
|
};
|
|
421
409
|
|
|
422
410
|
// src/bot/run.ts
|
|
423
|
-
var
|
|
424
|
-
var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(
|
|
411
|
+
var Micro7 = __toESM(require("effect/Micro"));
|
|
412
|
+
var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(
|
|
413
|
+
Micro7.provideService(BotMessageHandler, input),
|
|
414
|
+
Micro7.runPromise
|
|
415
|
+
);
|
|
425
416
|
|
|
426
417
|
// src/client/_client.ts
|
|
427
|
-
var
|
|
418
|
+
var Micro10 = __toESM(require("effect/Micro"));
|
|
428
419
|
|
|
429
420
|
// src/client/file/_service.ts
|
|
430
|
-
var
|
|
431
|
-
var
|
|
421
|
+
var Micro9 = __toESM(require("effect/Micro"));
|
|
422
|
+
var Context5 = __toESM(require("effect/Context"));
|
|
432
423
|
|
|
433
424
|
// src/client/file/get-file.ts
|
|
434
|
-
var
|
|
435
|
-
var getFile = (fileId) =>
|
|
425
|
+
var Micro8 = __toESM(require("effect/Micro"));
|
|
426
|
+
var getFile = (fileId) => Micro8.gen(function* () {
|
|
436
427
|
const response = yield* execute("get_file", { file_id: fileId });
|
|
437
|
-
const config = yield*
|
|
428
|
+
const config = yield* Micro8.service(TgBotClientConfig);
|
|
438
429
|
const file_path = response.file_path;
|
|
439
430
|
if (!file_path || file_path.length == 0) {
|
|
440
|
-
return yield*
|
|
431
|
+
return yield* Micro8.fail(
|
|
441
432
|
new TgBotClientError({
|
|
442
433
|
reason: {
|
|
443
434
|
type: "UnableToGetFile",
|
|
@@ -448,7 +439,7 @@ var getFile = (fileId) => Micro9.gen(function* () {
|
|
|
448
439
|
}
|
|
449
440
|
const file_name = file_path.replaceAll("/", "-");
|
|
450
441
|
const url = `${config.base_url}/file/bot${config.bot_token}/${file_path}`;
|
|
451
|
-
const fileContent = yield*
|
|
442
|
+
const fileContent = yield* Micro8.tryPromise({
|
|
452
443
|
try: () => fetch(url).then((_) => _.arrayBuffer()),
|
|
453
444
|
catch: (cause) => new TgBotClientError({
|
|
454
445
|
reason: { type: "UnableToGetFile", cause }
|
|
@@ -459,9 +450,9 @@ var getFile = (fileId) => Micro9.gen(function* () {
|
|
|
459
450
|
});
|
|
460
451
|
|
|
461
452
|
// src/client/file/_service.ts
|
|
462
|
-
var ClientFileService = class extends
|
|
453
|
+
var ClientFileService = class extends Context5.Tag("ClientFileService")() {
|
|
463
454
|
};
|
|
464
|
-
var ClientFileServiceDefault =
|
|
455
|
+
var ClientFileServiceDefault = Micro9.gen(function* () {
|
|
465
456
|
return {
|
|
466
457
|
getFile: (input) => getFile(input.file_id)
|
|
467
458
|
};
|
|
@@ -470,22 +461,22 @@ var ClientFileServiceDefault = Micro10.gen(function* () {
|
|
|
470
461
|
// src/client/_client.ts
|
|
471
462
|
var makeTgBotClient = (input) => {
|
|
472
463
|
const config = makeTgBotClientConfig(input);
|
|
473
|
-
const client =
|
|
474
|
-
const file = yield*
|
|
464
|
+
const client = Micro10.gen(function* () {
|
|
465
|
+
const file = yield* Micro10.service(ClientFileService);
|
|
475
466
|
return {
|
|
476
467
|
execute: (method, input2) => execute(method, input2).pipe(
|
|
477
|
-
|
|
478
|
-
|
|
468
|
+
Micro10.provideService(TgBotClientConfig, config),
|
|
469
|
+
Micro10.runPromise
|
|
479
470
|
),
|
|
480
471
|
getFile: (input2) => file.getFile(input2).pipe(
|
|
481
|
-
|
|
482
|
-
|
|
472
|
+
Micro10.provideService(TgBotClientConfig, config),
|
|
473
|
+
Micro10.runPromise
|
|
483
474
|
)
|
|
484
475
|
};
|
|
485
476
|
}).pipe(
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
477
|
+
Micro10.provideServiceEffect(ClientFileService, ClientFileServiceDefault),
|
|
478
|
+
Micro10.provideService(TgBotClientConfig, config),
|
|
479
|
+
Micro10.runSync
|
|
489
480
|
);
|
|
490
481
|
return client;
|
|
491
482
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
// src/bot/factory/_service.ts
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as Micro6 from "effect/Micro";
|
|
3
|
+
import * as Context4 from "effect/Context";
|
|
4
|
+
|
|
5
|
+
// src/bot/message-handler/_service.ts
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
var BotMessageHandler = class extends Context.Tag("BotMessageHandler")() {
|
|
8
|
+
};
|
|
4
9
|
|
|
5
10
|
// src/bot/update-poller/_service.ts
|
|
6
11
|
import * as Micro4 from "effect/Micro";
|
|
7
|
-
import * as
|
|
12
|
+
import * as Context3 from "effect/Context";
|
|
8
13
|
|
|
9
14
|
// src/bot/update-poller/poll-and-handle.ts
|
|
10
15
|
import * as Micro3 from "effect/Micro";
|
|
@@ -81,7 +86,7 @@ var TgBotClientError = class _TgBotClientError extends Data.TaggedError("TgBotCl
|
|
|
81
86
|
};
|
|
82
87
|
|
|
83
88
|
// src/client/config.ts
|
|
84
|
-
import * as
|
|
89
|
+
import * as Context2 from "effect/Context";
|
|
85
90
|
|
|
86
91
|
// src/const.ts
|
|
87
92
|
var defaultBaseUrl = "https://api.telegram.org";
|
|
@@ -103,7 +108,7 @@ var makeTgBotClientConfig = (input) => TgBotClientConfig.of({
|
|
|
103
108
|
...input,
|
|
104
109
|
base_url: input.base_url ?? defaultBaseUrl
|
|
105
110
|
});
|
|
106
|
-
var TgBotClientConfig = class extends
|
|
111
|
+
var TgBotClientConfig = class extends Context2.Tag("TgBotClientConfig")() {
|
|
107
112
|
};
|
|
108
113
|
|
|
109
114
|
// src/client/guards.ts
|
|
@@ -277,14 +282,16 @@ var pollAndHandle = (input) => {
|
|
|
277
282
|
};
|
|
278
283
|
|
|
279
284
|
// src/bot/update-poller/_service.ts
|
|
280
|
-
var BotUpdatePollerService = class extends
|
|
285
|
+
var BotUpdatePollerService = class extends Context3.Tag("BotUpdatePollerService")() {
|
|
281
286
|
};
|
|
282
287
|
var BotUpdatesPollerServiceDefault = Micro4.gen(function* () {
|
|
283
288
|
console.log("Initiating BotUpdatesPollerServiceDefault");
|
|
284
289
|
const state = {
|
|
285
290
|
fiber: void 0
|
|
286
291
|
};
|
|
287
|
-
const runBot =
|
|
292
|
+
const runBot = Micro4.gen(function* () {
|
|
293
|
+
console.log("run bot");
|
|
294
|
+
const messageHandler = yield* Micro4.service(BotMessageHandler);
|
|
288
295
|
const startFiber = pollAndHandle({
|
|
289
296
|
settings: messageHandler
|
|
290
297
|
}).pipe(
|
|
@@ -292,9 +299,6 @@ var BotUpdatesPollerServiceDefault = Micro4.gen(function* () {
|
|
|
292
299
|
Micro4.tap(
|
|
293
300
|
(fiber) => fiber.addObserver((exit) => {
|
|
294
301
|
console.log("bot's fiber has been closed", exit);
|
|
295
|
-
if (messageHandler.onExit) {
|
|
296
|
-
messageHandler.onExit(exit);
|
|
297
|
-
}
|
|
298
302
|
})
|
|
299
303
|
)
|
|
300
304
|
);
|
|
@@ -304,10 +308,10 @@ var BotUpdatesPollerServiceDefault = Micro4.gen(function* () {
|
|
|
304
308
|
}
|
|
305
309
|
state.fiber = yield* startFiber;
|
|
306
310
|
console.log("Fetching bot updates via long polling...");
|
|
307
|
-
return state.fiber;
|
|
308
311
|
});
|
|
309
312
|
return {
|
|
310
|
-
runBot
|
|
313
|
+
runBot,
|
|
314
|
+
getFiber: () => state.fiber
|
|
311
315
|
};
|
|
312
316
|
});
|
|
313
317
|
|
|
@@ -333,66 +337,53 @@ var makeClientConfigFrom = (input) => Micro5.gen(function* () {
|
|
|
333
337
|
return makeTgBotClientConfig(config);
|
|
334
338
|
});
|
|
335
339
|
|
|
336
|
-
// src/bot/factory/make-bot.ts
|
|
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);
|
|
342
|
-
return {
|
|
343
|
-
runBot,
|
|
344
|
-
interrupt
|
|
345
|
-
};
|
|
346
|
-
}).pipe(
|
|
347
|
-
Micro6.tapError((error) => {
|
|
348
|
-
console.error(error);
|
|
349
|
-
return Micro6.void;
|
|
350
|
-
})
|
|
351
|
-
);
|
|
352
|
-
|
|
353
340
|
// src/bot/factory/_service.ts
|
|
354
|
-
var BotFactoryService = class extends
|
|
341
|
+
var BotFactoryService = class extends Context4.Tag("BotFactoryService")() {
|
|
355
342
|
};
|
|
356
343
|
var BotFactoryServiceDefault = {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const client = Context3.make(TgBotClientConfig, yield* makeClientConfigFrom(input));
|
|
344
|
+
runBot: (input) => Micro6.gen(function* () {
|
|
345
|
+
const client = Context4.make(TgBotClientConfig, yield* makeClientConfigFrom(input));
|
|
360
346
|
const poller = yield* BotUpdatesPollerServiceDefault.pipe(
|
|
361
|
-
|
|
347
|
+
Micro6.provideContext(client)
|
|
362
348
|
);
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
349
|
+
yield* poller.runBot.pipe(
|
|
350
|
+
Micro6.provideService(BotMessageHandler, input),
|
|
351
|
+
Micro6.provideContext(client)
|
|
366
352
|
);
|
|
367
|
-
const reload = (input2) =>
|
|
368
|
-
|
|
353
|
+
const reload = (input2) => poller.runBot.pipe(
|
|
354
|
+
Micro6.provideService(BotMessageHandler, input2),
|
|
355
|
+
Micro6.provideContext(client),
|
|
356
|
+
Micro6.runPromise
|
|
369
357
|
);
|
|
370
358
|
return {
|
|
371
359
|
reload,
|
|
372
|
-
|
|
360
|
+
fiber: poller.getFiber
|
|
373
361
|
};
|
|
374
362
|
})
|
|
375
363
|
};
|
|
376
364
|
|
|
377
365
|
// src/bot/run.ts
|
|
378
|
-
import * as
|
|
379
|
-
var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(
|
|
366
|
+
import * as Micro7 from "effect/Micro";
|
|
367
|
+
var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(
|
|
368
|
+
Micro7.provideService(BotMessageHandler, input),
|
|
369
|
+
Micro7.runPromise
|
|
370
|
+
);
|
|
380
371
|
|
|
381
372
|
// src/client/_client.ts
|
|
382
|
-
import * as
|
|
373
|
+
import * as Micro10 from "effect/Micro";
|
|
383
374
|
|
|
384
375
|
// src/client/file/_service.ts
|
|
385
|
-
import * as
|
|
386
|
-
import * as
|
|
376
|
+
import * as Micro9 from "effect/Micro";
|
|
377
|
+
import * as Context5 from "effect/Context";
|
|
387
378
|
|
|
388
379
|
// src/client/file/get-file.ts
|
|
389
|
-
import * as
|
|
390
|
-
var getFile = (fileId) =>
|
|
380
|
+
import * as Micro8 from "effect/Micro";
|
|
381
|
+
var getFile = (fileId) => Micro8.gen(function* () {
|
|
391
382
|
const response = yield* execute("get_file", { file_id: fileId });
|
|
392
|
-
const config = yield*
|
|
383
|
+
const config = yield* Micro8.service(TgBotClientConfig);
|
|
393
384
|
const file_path = response.file_path;
|
|
394
385
|
if (!file_path || file_path.length == 0) {
|
|
395
|
-
return yield*
|
|
386
|
+
return yield* Micro8.fail(
|
|
396
387
|
new TgBotClientError({
|
|
397
388
|
reason: {
|
|
398
389
|
type: "UnableToGetFile",
|
|
@@ -403,7 +394,7 @@ var getFile = (fileId) => Micro9.gen(function* () {
|
|
|
403
394
|
}
|
|
404
395
|
const file_name = file_path.replaceAll("/", "-");
|
|
405
396
|
const url = `${config.base_url}/file/bot${config.bot_token}/${file_path}`;
|
|
406
|
-
const fileContent = yield*
|
|
397
|
+
const fileContent = yield* Micro8.tryPromise({
|
|
407
398
|
try: () => fetch(url).then((_) => _.arrayBuffer()),
|
|
408
399
|
catch: (cause) => new TgBotClientError({
|
|
409
400
|
reason: { type: "UnableToGetFile", cause }
|
|
@@ -414,9 +405,9 @@ var getFile = (fileId) => Micro9.gen(function* () {
|
|
|
414
405
|
});
|
|
415
406
|
|
|
416
407
|
// src/client/file/_service.ts
|
|
417
|
-
var ClientFileService = class extends
|
|
408
|
+
var ClientFileService = class extends Context5.Tag("ClientFileService")() {
|
|
418
409
|
};
|
|
419
|
-
var ClientFileServiceDefault =
|
|
410
|
+
var ClientFileServiceDefault = Micro9.gen(function* () {
|
|
420
411
|
return {
|
|
421
412
|
getFile: (input) => getFile(input.file_id)
|
|
422
413
|
};
|
|
@@ -425,22 +416,22 @@ var ClientFileServiceDefault = Micro10.gen(function* () {
|
|
|
425
416
|
// src/client/_client.ts
|
|
426
417
|
var makeTgBotClient = (input) => {
|
|
427
418
|
const config = makeTgBotClientConfig(input);
|
|
428
|
-
const client =
|
|
429
|
-
const file = yield*
|
|
419
|
+
const client = Micro10.gen(function* () {
|
|
420
|
+
const file = yield* Micro10.service(ClientFileService);
|
|
430
421
|
return {
|
|
431
422
|
execute: (method, input2) => execute(method, input2).pipe(
|
|
432
|
-
|
|
433
|
-
|
|
423
|
+
Micro10.provideService(TgBotClientConfig, config),
|
|
424
|
+
Micro10.runPromise
|
|
434
425
|
),
|
|
435
426
|
getFile: (input2) => file.getFile(input2).pipe(
|
|
436
|
-
|
|
437
|
-
|
|
427
|
+
Micro10.provideService(TgBotClientConfig, config),
|
|
428
|
+
Micro10.runPromise
|
|
438
429
|
)
|
|
439
430
|
};
|
|
440
431
|
}).pipe(
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
432
|
+
Micro10.provideServiceEffect(ClientFileService, ClientFileServiceDefault),
|
|
433
|
+
Micro10.provideService(TgBotClientConfig, config),
|
|
434
|
+
Micro10.runSync
|
|
444
435
|
);
|
|
445
436
|
return client;
|
|
446
437
|
};
|