@effect-ak/tg-bot-client 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +41 -29
- package/dist/index.js +79 -58
- package/dist/index.mjs +79 -58
- package/package.json +2 -2
- package/readme.md +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ declare class TgBotClientError extends TgBotClientError_base<{
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
type TgBotClientSettingsInput = {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
bot_token: string;
|
|
31
|
+
base_url?: string;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
type TgBotClientConfigObject = Required<TgBotClientSettingsInput>;
|
|
@@ -2752,6 +2752,17 @@ declare const makeTgBotClient: (input: TgBotClientSettingsInput) => {
|
|
|
2752
2752
|
getFile: (input: Parameters<ClientFileServiceInterface["getFile"]>[0]) => Promise<File>;
|
|
2753
2753
|
};
|
|
2754
2754
|
|
|
2755
|
+
type PollAndHandleInput = {
|
|
2756
|
+
settings: BotMessageHandlerSettings;
|
|
2757
|
+
execute: ClientExecuteRequestServiceInterface["execute"];
|
|
2758
|
+
};
|
|
2759
|
+
type PollAndHandleResult = Micro.Micro.Success<ReturnType<typeof pollAndHandle>>;
|
|
2760
|
+
declare const pollAndHandle: (input: PollAndHandleInput) => Micro.Micro<{
|
|
2761
|
+
updates: Update[];
|
|
2762
|
+
lastSuccessId: number | undefined;
|
|
2763
|
+
hasError: boolean;
|
|
2764
|
+
}, TgBotClientError, never>;
|
|
2765
|
+
|
|
2755
2766
|
type AvailableUpdateTypes = Exclude<keyof Update, 'update_id'>;
|
|
2756
2767
|
type BotResponse = {
|
|
2757
2768
|
[K in keyof Api]: K extends `send_${infer R}` ? {
|
|
@@ -2765,19 +2776,25 @@ type BotMessageHandlerSettings = {
|
|
|
2765
2776
|
readonly batch_size?: number;
|
|
2766
2777
|
readonly timeout?: number;
|
|
2767
2778
|
readonly max_empty_responses?: number;
|
|
2768
|
-
} & BotMessageHandlers
|
|
2779
|
+
} & BotMessageHandlers & {
|
|
2780
|
+
onExit?: (_: Micro.MicroExit<PollAndHandleResult, TgBotClientError>) => void;
|
|
2781
|
+
};
|
|
2769
2782
|
|
|
2783
|
+
declare const BotUpdatePollerService_base: Context.TagClass<BotUpdatePollerService, "BotUpdatePollerService", {
|
|
2784
|
+
readonly runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
|
|
2785
|
+
}>;
|
|
2786
|
+
declare class BotUpdatePollerService extends BotUpdatePollerService_base {
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
type BotInstance = Micro.Micro.Success<ReturnType<typeof BotFactoryServiceDefault["runBot"]>>;
|
|
2770
2790
|
declare const BotFactoryService_base: Context.TagClass<BotFactoryService, "BotFactoryService", {
|
|
2771
|
-
makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
lastSuccessId: number | undefined;
|
|
2779
|
-
hasError: boolean;
|
|
2780
|
-
}, TgBotClientError>, string, never>;
|
|
2791
|
+
makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<{
|
|
2792
|
+
fiber: Micro.MicroFiber<unknown, TgBotClientError>;
|
|
2793
|
+
runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
|
|
2794
|
+
}, never, BotUpdatePollerService>;
|
|
2795
|
+
runBot: (input: RunBotInput) => Micro.Micro<{
|
|
2796
|
+
readonly reload: (input: Partial<RunBotInput>) => Promise<Micro.MicroFiber<unknown, TgBotClientError>>;
|
|
2797
|
+
}, string, never>;
|
|
2781
2798
|
}>;
|
|
2782
2799
|
declare class BotFactoryService extends BotFactoryService_base {
|
|
2783
2800
|
}
|
|
@@ -2787,23 +2804,18 @@ type RunBotInput = ({
|
|
|
2787
2804
|
type: "config";
|
|
2788
2805
|
} & TgBotClientSettingsInput) & BotMessageHandlerSettings;
|
|
2789
2806
|
declare const BotFactoryServiceDefault: {
|
|
2790
|
-
makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
lastSuccessId: number | undefined;
|
|
2798
|
-
hasError: boolean;
|
|
2799
|
-
}, TgBotClientError>, string, never>;
|
|
2807
|
+
makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<{
|
|
2808
|
+
fiber: Micro.MicroFiber<unknown, TgBotClientError>;
|
|
2809
|
+
runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<unknown, TgBotClientError>, never, never>;
|
|
2810
|
+
}, never, BotUpdatePollerService>;
|
|
2811
|
+
runBot: (input: RunBotInput) => Micro.Micro<{
|
|
2812
|
+
readonly reload: (input: Partial<RunBotInput>) => Promise<Micro.MicroFiber<unknown, TgBotClientError>>;
|
|
2813
|
+
}, string, never>;
|
|
2800
2814
|
};
|
|
2801
2815
|
|
|
2802
|
-
declare const runTgChatBot: (input: Parameters<typeof BotFactoryServiceDefault.runBot>[0]) => Promise<
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
hasError: boolean;
|
|
2806
|
-
}, TgBotClientError>, string>>;
|
|
2816
|
+
declare const runTgChatBot: (input: Parameters<typeof BotFactoryServiceDefault.runBot>[0]) => Promise<{
|
|
2817
|
+
readonly reload: (input: Partial<RunBotInput>) => Promise<Micro.MicroFiber<unknown, TgBotClientError>>;
|
|
2818
|
+
}>;
|
|
2807
2819
|
|
|
2808
2820
|
declare const defaultBaseUrl = "https://api.telegram.org";
|
|
2809
2821
|
declare const MESSAGE_EFFECTS: {
|
|
@@ -2818,4 +2830,4 @@ type MessageEffect = keyof typeof MESSAGE_EFFECTS;
|
|
|
2818
2830
|
declare const messageEffectIdCodes: MessageEffect[];
|
|
2819
2831
|
declare const isMessageEffect: (input: unknown) => input is MessageEffect;
|
|
2820
2832
|
|
|
2821
|
-
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 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 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 };
|
|
2833
|
+
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 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
|
@@ -65,7 +65,7 @@ var isMessageEffect = (input) => {
|
|
|
65
65
|
// src/client/config.ts
|
|
66
66
|
var makeTgBotClientConfig = (input) => TgBotClientConfig.of({
|
|
67
67
|
...input,
|
|
68
|
-
|
|
68
|
+
base_url: input.base_url ?? defaultBaseUrl
|
|
69
69
|
});
|
|
70
70
|
var TgBotClientConfig = class extends Context.Tag("TgBotClientConfig")() {
|
|
71
71
|
};
|
|
@@ -92,7 +92,7 @@ var TgBotClientError = class _TgBotClientError extends Data.TaggedError("TgBotCl
|
|
|
92
92
|
// src/client/guards.ts
|
|
93
93
|
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
94
|
var isTgBotApiResponse = (input) => typeof input == "object" && input != null && ("ok" in input && typeof input.ok == "boolean");
|
|
95
|
-
var isTgBotClientSettingsInput = (input) => typeof input == "object" && input != null && ("
|
|
95
|
+
var isTgBotClientSettingsInput = (input) => typeof input == "object" && input != null && ("bot_token" in input && typeof input.bot_token == "string");
|
|
96
96
|
|
|
97
97
|
// src/client/execute-request/payload.ts
|
|
98
98
|
var makePayload = (body) => {
|
|
@@ -116,7 +116,7 @@ var makePayload = (body) => {
|
|
|
116
116
|
var execute = (config, method, input) => Micro.gen(function* () {
|
|
117
117
|
const httpResponse = yield* Micro.tryPromise({
|
|
118
118
|
try: () => fetch(
|
|
119
|
-
`${config
|
|
119
|
+
`${config.base_url}/bot${config.bot_token}/${String.snakeToCamel(method)}`,
|
|
120
120
|
{
|
|
121
121
|
body: makePayload(input) ?? null,
|
|
122
122
|
method: "POST"
|
|
@@ -179,7 +179,7 @@ var getFile = (fileId, config, execute2) => Micro3.gen(function* () {
|
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
181
|
const file_name = file_path.replaceAll("/", "-");
|
|
182
|
-
const url = `${config
|
|
182
|
+
const url = `${config.base_url}/file/bot${config.bot_token}/${file_path}`;
|
|
183
183
|
const fileContent = yield* Micro3.tryPromise({
|
|
184
184
|
try: () => fetch(url).then((_) => _.arrayBuffer()),
|
|
185
185
|
catch: (cause) => new TgBotClientError({
|
|
@@ -229,37 +229,12 @@ var Micro12 = __toESM(require("effect/Micro"));
|
|
|
229
229
|
var Micro11 = __toESM(require("effect/Micro"));
|
|
230
230
|
var Context5 = __toESM(require("effect/Context"));
|
|
231
231
|
|
|
232
|
-
// src/bot/factory/client-config.ts
|
|
233
|
-
var Micro6 = __toESM(require("effect/Micro"));
|
|
234
|
-
var makeClientConfigFrom = (input) => Micro6.gen(function* () {
|
|
235
|
-
if (input.type == "config") {
|
|
236
|
-
return makeTgBotClientConfig(input);
|
|
237
|
-
}
|
|
238
|
-
const config = yield* Micro6.tryPromise({
|
|
239
|
-
try: async () => {
|
|
240
|
-
const { readFile } = await import("fs/promises");
|
|
241
|
-
return JSON.parse(await readFile("config.json", "utf-8"));
|
|
242
|
-
},
|
|
243
|
-
catch: (error) => {
|
|
244
|
-
console.warn(error);
|
|
245
|
-
return "ReadingConfigError";
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
if (!isTgBotClientSettingsInput(config)) {
|
|
249
|
-
return yield* Micro6.fail("InvalidConfig");
|
|
250
|
-
}
|
|
251
|
-
return makeTgBotClientConfig(config);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// src/bot/factory/make-bot.ts
|
|
255
|
-
var Micro10 = __toESM(require("effect/Micro"));
|
|
256
|
-
|
|
257
232
|
// src/bot/update-poller/_service.ts
|
|
258
|
-
var
|
|
233
|
+
var Micro8 = __toESM(require("effect/Micro"));
|
|
259
234
|
var Context4 = __toESM(require("effect/Context"));
|
|
260
235
|
|
|
261
236
|
// src/bot/update-poller/poll-and-handle.ts
|
|
262
|
-
var
|
|
237
|
+
var Micro7 = __toESM(require("effect/Micro"));
|
|
263
238
|
|
|
264
239
|
// src/bot/update-poller/settings.ts
|
|
265
240
|
var makeSettingsFrom = (input) => {
|
|
@@ -286,7 +261,7 @@ var makeSettingsFrom = (input) => {
|
|
|
286
261
|
};
|
|
287
262
|
|
|
288
263
|
// src/bot/update-poller/fetch-updates.ts
|
|
289
|
-
var
|
|
264
|
+
var Micro6 = __toESM(require("effect/Micro"));
|
|
290
265
|
|
|
291
266
|
// src/bot/message-handler/utils.ts
|
|
292
267
|
var extractUpdate = (input) => {
|
|
@@ -303,14 +278,14 @@ var extractUpdate = (input) => {
|
|
|
303
278
|
};
|
|
304
279
|
|
|
305
280
|
// src/bot/update-poller/fetch-updates.ts
|
|
306
|
-
var fetchUpdates = ({ state, settings, execute: execute2, handlers }) =>
|
|
281
|
+
var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.gen(function* () {
|
|
307
282
|
const updateId = state.lastUpdateId;
|
|
308
283
|
console.info("getting updates", state);
|
|
309
284
|
const updates = yield* execute2("get_updates", {
|
|
310
285
|
...settings,
|
|
311
286
|
...updateId ? { offset: updateId } : void 0
|
|
312
287
|
}).pipe(
|
|
313
|
-
|
|
288
|
+
Micro6.andThen((_) => _.sort((_2) => _2.update_id))
|
|
314
289
|
);
|
|
315
290
|
let lastSuccessId = void 0;
|
|
316
291
|
let hasError = false;
|
|
@@ -362,7 +337,7 @@ var pollAndHandle = (input) => {
|
|
|
362
337
|
emptyResponses: 0
|
|
363
338
|
};
|
|
364
339
|
const settings = makeSettingsFrom(input.settings);
|
|
365
|
-
return
|
|
340
|
+
return Micro7.delay(1e3)(
|
|
366
341
|
fetchUpdates({
|
|
367
342
|
state,
|
|
368
343
|
settings,
|
|
@@ -370,7 +345,7 @@ var pollAndHandle = (input) => {
|
|
|
370
345
|
handlers: input.settings
|
|
371
346
|
})
|
|
372
347
|
).pipe(
|
|
373
|
-
|
|
348
|
+
Micro7.repeat({
|
|
374
349
|
while: ({ updates, lastSuccessId, hasError }) => {
|
|
375
350
|
if (hasError) {
|
|
376
351
|
console.warn("error in handler, quitting");
|
|
@@ -398,39 +373,74 @@ var pollAndHandle = (input) => {
|
|
|
398
373
|
// src/bot/update-poller/_service.ts
|
|
399
374
|
var BotUpdatePollerService = class extends Context4.Tag("BotUpdatePollerService")() {
|
|
400
375
|
};
|
|
401
|
-
var BotUpdatesPollerServiceDefault =
|
|
376
|
+
var BotUpdatesPollerServiceDefault = Micro8.gen(function* () {
|
|
377
|
+
console.log("Initiating BotUpdatesPollerServiceDefault");
|
|
402
378
|
const state = {
|
|
403
|
-
|
|
379
|
+
fiber: void 0
|
|
404
380
|
};
|
|
405
|
-
const client = yield*
|
|
406
|
-
const runBot = (messageHandler) =>
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
const fiber = yield* pollAndHandle({
|
|
381
|
+
const client = yield* Micro8.service(ClientExecuteRequestService);
|
|
382
|
+
const runBot = (messageHandler) => Micro8.gen(function* () {
|
|
383
|
+
console.log(state);
|
|
384
|
+
const startFiber = pollAndHandle({
|
|
411
385
|
settings: messageHandler,
|
|
412
386
|
execute: client.execute
|
|
413
|
-
}).pipe(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
387
|
+
}).pipe(
|
|
388
|
+
Micro8.forkDaemon,
|
|
389
|
+
Micro8.tap(
|
|
390
|
+
(fiber) => fiber.addObserver((exit) => {
|
|
391
|
+
console.log("bot's fiber has been closed", exit);
|
|
392
|
+
if (messageHandler.onExit) {
|
|
393
|
+
messageHandler.onExit(exit);
|
|
394
|
+
}
|
|
395
|
+
})
|
|
396
|
+
)
|
|
397
|
+
);
|
|
398
|
+
if (state.fiber) {
|
|
399
|
+
console.log("killing previous bot's fiber");
|
|
400
|
+
yield* Micro8.fiberInterrupt(state.fiber);
|
|
401
|
+
}
|
|
402
|
+
state.fiber = yield* startFiber;
|
|
403
|
+
console.log("Reading bot's updates.....", state.fiber == null);
|
|
404
|
+
return state.fiber;
|
|
420
405
|
});
|
|
421
406
|
return {
|
|
422
407
|
runBot
|
|
423
408
|
};
|
|
424
409
|
}).pipe(
|
|
425
|
-
|
|
410
|
+
Micro8.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault)
|
|
426
411
|
);
|
|
427
412
|
|
|
413
|
+
// src/bot/factory/client-config.ts
|
|
414
|
+
var Micro9 = __toESM(require("effect/Micro"));
|
|
415
|
+
var makeClientConfigFrom = (input) => Micro9.gen(function* () {
|
|
416
|
+
if (input.type == "config") {
|
|
417
|
+
return makeTgBotClientConfig(input);
|
|
418
|
+
}
|
|
419
|
+
const config = yield* Micro9.tryPromise({
|
|
420
|
+
try: async () => {
|
|
421
|
+
const { readFileSync } = await import("fs");
|
|
422
|
+
return JSON.parse(await readFileSync("config.json", "utf-8"));
|
|
423
|
+
},
|
|
424
|
+
catch: (error) => {
|
|
425
|
+
console.warn(error);
|
|
426
|
+
return "ReadingConfigError";
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
if (!isTgBotClientSettingsInput(config)) {
|
|
430
|
+
return yield* Micro9.fail("InvalidConfig");
|
|
431
|
+
}
|
|
432
|
+
return makeTgBotClientConfig(config);
|
|
433
|
+
});
|
|
434
|
+
|
|
428
435
|
// src/bot/factory/make-bot.ts
|
|
436
|
+
var Micro10 = __toESM(require("effect/Micro"));
|
|
429
437
|
var makeBot = (messageHandler) => Micro10.gen(function* () {
|
|
430
438
|
const { runBot } = yield* Micro10.service(BotUpdatePollerService);
|
|
431
|
-
return
|
|
439
|
+
return {
|
|
440
|
+
fiber: yield* runBot(messageHandler),
|
|
441
|
+
runBot
|
|
442
|
+
};
|
|
432
443
|
}).pipe(
|
|
433
|
-
Micro10.provideServiceEffect(BotUpdatePollerService, BotUpdatesPollerServiceDefault),
|
|
434
444
|
Micro10.tapError((error) => {
|
|
435
445
|
console.error(error);
|
|
436
446
|
return Micro10.void;
|
|
@@ -442,13 +452,24 @@ var BotFactoryService = class extends Context5.Tag("BotFactoryService")() {
|
|
|
442
452
|
};
|
|
443
453
|
var BotFactoryServiceDefault = {
|
|
444
454
|
makeBot,
|
|
445
|
-
runBot: (input) =>
|
|
446
|
-
|
|
447
|
-
|
|
455
|
+
runBot: (input) => Micro11.gen(function* () {
|
|
456
|
+
console.log("client");
|
|
457
|
+
const client = yield* makeClientConfigFrom(input);
|
|
458
|
+
const poller = yield* BotUpdatesPollerServiceDefault.pipe(
|
|
459
|
+
Micro11.provideService(TgBotClientConfig, client)
|
|
460
|
+
);
|
|
461
|
+
const bot = yield* makeBot(input).pipe(
|
|
462
|
+
Micro11.provideService(BotUpdatePollerService, poller)
|
|
463
|
+
);
|
|
464
|
+
const reload = (input2) => bot.runBot(input2).pipe(Micro11.runPromise);
|
|
465
|
+
return {
|
|
466
|
+
reload
|
|
467
|
+
};
|
|
468
|
+
})
|
|
448
469
|
};
|
|
449
470
|
|
|
450
471
|
// src/bot/run.ts
|
|
451
|
-
var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(Micro12.
|
|
472
|
+
var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(Micro12.runPromise);
|
|
452
473
|
// Annotate the CommonJS export names for ESM import in node:
|
|
453
474
|
0 && (module.exports = {
|
|
454
475
|
BotFactoryService,
|
package/dist/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ var isMessageEffect = (input) => {
|
|
|
22
22
|
// src/client/config.ts
|
|
23
23
|
var makeTgBotClientConfig = (input) => TgBotClientConfig.of({
|
|
24
24
|
...input,
|
|
25
|
-
|
|
25
|
+
base_url: input.base_url ?? defaultBaseUrl
|
|
26
26
|
});
|
|
27
27
|
var TgBotClientConfig = class extends Context.Tag("TgBotClientConfig")() {
|
|
28
28
|
};
|
|
@@ -49,7 +49,7 @@ var TgBotClientError = class _TgBotClientError extends Data.TaggedError("TgBotCl
|
|
|
49
49
|
// src/client/guards.ts
|
|
50
50
|
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
51
|
var isTgBotApiResponse = (input) => typeof input == "object" && input != null && ("ok" in input && typeof input.ok == "boolean");
|
|
52
|
-
var isTgBotClientSettingsInput = (input) => typeof input == "object" && input != null && ("
|
|
52
|
+
var isTgBotClientSettingsInput = (input) => typeof input == "object" && input != null && ("bot_token" in input && typeof input.bot_token == "string");
|
|
53
53
|
|
|
54
54
|
// src/client/execute-request/payload.ts
|
|
55
55
|
var makePayload = (body) => {
|
|
@@ -73,7 +73,7 @@ var makePayload = (body) => {
|
|
|
73
73
|
var execute = (config, method, input) => Micro.gen(function* () {
|
|
74
74
|
const httpResponse = yield* Micro.tryPromise({
|
|
75
75
|
try: () => fetch(
|
|
76
|
-
`${config
|
|
76
|
+
`${config.base_url}/bot${config.bot_token}/${String.snakeToCamel(method)}`,
|
|
77
77
|
{
|
|
78
78
|
body: makePayload(input) ?? null,
|
|
79
79
|
method: "POST"
|
|
@@ -136,7 +136,7 @@ var getFile = (fileId, config, execute2) => Micro3.gen(function* () {
|
|
|
136
136
|
);
|
|
137
137
|
}
|
|
138
138
|
const file_name = file_path.replaceAll("/", "-");
|
|
139
|
-
const url = `${config
|
|
139
|
+
const url = `${config.base_url}/file/bot${config.bot_token}/${file_path}`;
|
|
140
140
|
const fileContent = yield* Micro3.tryPromise({
|
|
141
141
|
try: () => fetch(url).then((_) => _.arrayBuffer()),
|
|
142
142
|
catch: (cause) => new TgBotClientError({
|
|
@@ -186,37 +186,12 @@ import * as Micro12 from "effect/Micro";
|
|
|
186
186
|
import * as Micro11 from "effect/Micro";
|
|
187
187
|
import * as Context5 from "effect/Context";
|
|
188
188
|
|
|
189
|
-
// src/bot/factory/client-config.ts
|
|
190
|
-
import * as Micro6 from "effect/Micro";
|
|
191
|
-
var makeClientConfigFrom = (input) => Micro6.gen(function* () {
|
|
192
|
-
if (input.type == "config") {
|
|
193
|
-
return makeTgBotClientConfig(input);
|
|
194
|
-
}
|
|
195
|
-
const config = yield* Micro6.tryPromise({
|
|
196
|
-
try: async () => {
|
|
197
|
-
const { readFile } = await import("fs/promises");
|
|
198
|
-
return JSON.parse(await readFile("config.json", "utf-8"));
|
|
199
|
-
},
|
|
200
|
-
catch: (error) => {
|
|
201
|
-
console.warn(error);
|
|
202
|
-
return "ReadingConfigError";
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
if (!isTgBotClientSettingsInput(config)) {
|
|
206
|
-
return yield* Micro6.fail("InvalidConfig");
|
|
207
|
-
}
|
|
208
|
-
return makeTgBotClientConfig(config);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// src/bot/factory/make-bot.ts
|
|
212
|
-
import * as Micro10 from "effect/Micro";
|
|
213
|
-
|
|
214
189
|
// src/bot/update-poller/_service.ts
|
|
215
|
-
import * as
|
|
190
|
+
import * as Micro8 from "effect/Micro";
|
|
216
191
|
import * as Context4 from "effect/Context";
|
|
217
192
|
|
|
218
193
|
// src/bot/update-poller/poll-and-handle.ts
|
|
219
|
-
import * as
|
|
194
|
+
import * as Micro7 from "effect/Micro";
|
|
220
195
|
|
|
221
196
|
// src/bot/update-poller/settings.ts
|
|
222
197
|
var makeSettingsFrom = (input) => {
|
|
@@ -243,7 +218,7 @@ var makeSettingsFrom = (input) => {
|
|
|
243
218
|
};
|
|
244
219
|
|
|
245
220
|
// src/bot/update-poller/fetch-updates.ts
|
|
246
|
-
import * as
|
|
221
|
+
import * as Micro6 from "effect/Micro";
|
|
247
222
|
|
|
248
223
|
// src/bot/message-handler/utils.ts
|
|
249
224
|
var extractUpdate = (input) => {
|
|
@@ -260,14 +235,14 @@ var extractUpdate = (input) => {
|
|
|
260
235
|
};
|
|
261
236
|
|
|
262
237
|
// src/bot/update-poller/fetch-updates.ts
|
|
263
|
-
var fetchUpdates = ({ state, settings, execute: execute2, handlers }) =>
|
|
238
|
+
var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.gen(function* () {
|
|
264
239
|
const updateId = state.lastUpdateId;
|
|
265
240
|
console.info("getting updates", state);
|
|
266
241
|
const updates = yield* execute2("get_updates", {
|
|
267
242
|
...settings,
|
|
268
243
|
...updateId ? { offset: updateId } : void 0
|
|
269
244
|
}).pipe(
|
|
270
|
-
|
|
245
|
+
Micro6.andThen((_) => _.sort((_2) => _2.update_id))
|
|
271
246
|
);
|
|
272
247
|
let lastSuccessId = void 0;
|
|
273
248
|
let hasError = false;
|
|
@@ -319,7 +294,7 @@ var pollAndHandle = (input) => {
|
|
|
319
294
|
emptyResponses: 0
|
|
320
295
|
};
|
|
321
296
|
const settings = makeSettingsFrom(input.settings);
|
|
322
|
-
return
|
|
297
|
+
return Micro7.delay(1e3)(
|
|
323
298
|
fetchUpdates({
|
|
324
299
|
state,
|
|
325
300
|
settings,
|
|
@@ -327,7 +302,7 @@ var pollAndHandle = (input) => {
|
|
|
327
302
|
handlers: input.settings
|
|
328
303
|
})
|
|
329
304
|
).pipe(
|
|
330
|
-
|
|
305
|
+
Micro7.repeat({
|
|
331
306
|
while: ({ updates, lastSuccessId, hasError }) => {
|
|
332
307
|
if (hasError) {
|
|
333
308
|
console.warn("error in handler, quitting");
|
|
@@ -355,39 +330,74 @@ var pollAndHandle = (input) => {
|
|
|
355
330
|
// src/bot/update-poller/_service.ts
|
|
356
331
|
var BotUpdatePollerService = class extends Context4.Tag("BotUpdatePollerService")() {
|
|
357
332
|
};
|
|
358
|
-
var BotUpdatesPollerServiceDefault =
|
|
333
|
+
var BotUpdatesPollerServiceDefault = Micro8.gen(function* () {
|
|
334
|
+
console.log("Initiating BotUpdatesPollerServiceDefault");
|
|
359
335
|
const state = {
|
|
360
|
-
|
|
336
|
+
fiber: void 0
|
|
361
337
|
};
|
|
362
|
-
const client = yield*
|
|
363
|
-
const runBot = (messageHandler) =>
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
const fiber = yield* pollAndHandle({
|
|
338
|
+
const client = yield* Micro8.service(ClientExecuteRequestService);
|
|
339
|
+
const runBot = (messageHandler) => Micro8.gen(function* () {
|
|
340
|
+
console.log(state);
|
|
341
|
+
const startFiber = pollAndHandle({
|
|
368
342
|
settings: messageHandler,
|
|
369
343
|
execute: client.execute
|
|
370
|
-
}).pipe(
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
344
|
+
}).pipe(
|
|
345
|
+
Micro8.forkDaemon,
|
|
346
|
+
Micro8.tap(
|
|
347
|
+
(fiber) => fiber.addObserver((exit) => {
|
|
348
|
+
console.log("bot's fiber has been closed", exit);
|
|
349
|
+
if (messageHandler.onExit) {
|
|
350
|
+
messageHandler.onExit(exit);
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
)
|
|
354
|
+
);
|
|
355
|
+
if (state.fiber) {
|
|
356
|
+
console.log("killing previous bot's fiber");
|
|
357
|
+
yield* Micro8.fiberInterrupt(state.fiber);
|
|
358
|
+
}
|
|
359
|
+
state.fiber = yield* startFiber;
|
|
360
|
+
console.log("Reading bot's updates.....", state.fiber == null);
|
|
361
|
+
return state.fiber;
|
|
377
362
|
});
|
|
378
363
|
return {
|
|
379
364
|
runBot
|
|
380
365
|
};
|
|
381
366
|
}).pipe(
|
|
382
|
-
|
|
367
|
+
Micro8.provideServiceEffect(ClientExecuteRequestService, ClientExecuteRequestServiceDefault)
|
|
383
368
|
);
|
|
384
369
|
|
|
370
|
+
// src/bot/factory/client-config.ts
|
|
371
|
+
import * as Micro9 from "effect/Micro";
|
|
372
|
+
var makeClientConfigFrom = (input) => Micro9.gen(function* () {
|
|
373
|
+
if (input.type == "config") {
|
|
374
|
+
return makeTgBotClientConfig(input);
|
|
375
|
+
}
|
|
376
|
+
const config = yield* Micro9.tryPromise({
|
|
377
|
+
try: async () => {
|
|
378
|
+
const { readFileSync } = await import("fs");
|
|
379
|
+
return JSON.parse(await readFileSync("config.json", "utf-8"));
|
|
380
|
+
},
|
|
381
|
+
catch: (error) => {
|
|
382
|
+
console.warn(error);
|
|
383
|
+
return "ReadingConfigError";
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
if (!isTgBotClientSettingsInput(config)) {
|
|
387
|
+
return yield* Micro9.fail("InvalidConfig");
|
|
388
|
+
}
|
|
389
|
+
return makeTgBotClientConfig(config);
|
|
390
|
+
});
|
|
391
|
+
|
|
385
392
|
// src/bot/factory/make-bot.ts
|
|
393
|
+
import * as Micro10 from "effect/Micro";
|
|
386
394
|
var makeBot = (messageHandler) => Micro10.gen(function* () {
|
|
387
395
|
const { runBot } = yield* Micro10.service(BotUpdatePollerService);
|
|
388
|
-
return
|
|
396
|
+
return {
|
|
397
|
+
fiber: yield* runBot(messageHandler),
|
|
398
|
+
runBot
|
|
399
|
+
};
|
|
389
400
|
}).pipe(
|
|
390
|
-
Micro10.provideServiceEffect(BotUpdatePollerService, BotUpdatesPollerServiceDefault),
|
|
391
401
|
Micro10.tapError((error) => {
|
|
392
402
|
console.error(error);
|
|
393
403
|
return Micro10.void;
|
|
@@ -399,13 +409,24 @@ var BotFactoryService = class extends Context5.Tag("BotFactoryService")() {
|
|
|
399
409
|
};
|
|
400
410
|
var BotFactoryServiceDefault = {
|
|
401
411
|
makeBot,
|
|
402
|
-
runBot: (input) =>
|
|
403
|
-
|
|
404
|
-
|
|
412
|
+
runBot: (input) => Micro11.gen(function* () {
|
|
413
|
+
console.log("client");
|
|
414
|
+
const client = yield* makeClientConfigFrom(input);
|
|
415
|
+
const poller = yield* BotUpdatesPollerServiceDefault.pipe(
|
|
416
|
+
Micro11.provideService(TgBotClientConfig, client)
|
|
417
|
+
);
|
|
418
|
+
const bot = yield* makeBot(input).pipe(
|
|
419
|
+
Micro11.provideService(BotUpdatePollerService, poller)
|
|
420
|
+
);
|
|
421
|
+
const reload = (input2) => bot.runBot(input2).pipe(Micro11.runPromise);
|
|
422
|
+
return {
|
|
423
|
+
reload
|
|
424
|
+
};
|
|
425
|
+
})
|
|
405
426
|
};
|
|
406
427
|
|
|
407
428
|
// src/bot/run.ts
|
|
408
|
-
var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(Micro12.
|
|
429
|
+
var runTgChatBot = (input) => BotFactoryServiceDefault.runBot(input).pipe(Micro12.runPromise);
|
|
409
430
|
export {
|
|
410
431
|
BotFactoryService,
|
|
411
432
|
BotFactoryServiceDefault,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-ak/tg-bot-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"homepage": "https://effect-ak.github.io/telegram-bot-client",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aleksandr Kondaurov",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"vitest": "^2.1.8"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"effect": "^3.
|
|
49
|
+
"effect": "^3.11.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"gen": "tsx ./codegen/main",
|
package/readme.md
CHANGED
|
@@ -13,6 +13,7 @@ This client facilitates interaction with the Telegram Bot API. It was created pr
|
|
|
13
13
|
|
|
14
14
|
## Features:
|
|
15
15
|
- **Typesafe Client**: This is a clean client written in TypeScript with no abstractions.
|
|
16
|
+
- **[Playground](https://effect-ak.github.io/telegram-bot-playground/)**: Develop/Run chat bots in your browser
|
|
16
17
|
- **Complete**: The entire API is generated from [the official documentation](https://core.telegram.org/bots/api) using a [code generator](./codegen/main.ts)
|
|
17
18
|
- **Readable Method Names**: Method names, such as `setChatAdministratorCustomTitle`, are converted to snake_case for easier code readability, e.g., `set_chat_administrator_custom_title`.
|
|
18
19
|
- **Type Mapping**: Types from the documentation are converted to TypeScript types:
|
|
@@ -30,7 +31,7 @@ This client facilitates interaction with the Telegram Bot API. It was created pr
|
|
|
30
31
|
import { makeTgBotClient } from "@effect-ak/tg-bot-client"
|
|
31
32
|
|
|
32
33
|
const client = makeTgBotClient({
|
|
33
|
-
|
|
34
|
+
bot_token: "" //your token taken from bot father
|
|
34
35
|
});
|
|
35
36
|
```
|
|
36
37
|
|