@effect-ak/tg-bot-client 0.2.3 → 0.3.1
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 +7 -4
- package/dist/index.js +56 -24
- package/dist/index.mjs +56 -24
- package/package.json +1 -5
- package/readme.md +1 -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>;
|
|
@@ -2764,15 +2764,18 @@ declare const pollAndHandle: (input: PollAndHandleInput) => Micro.Micro<{
|
|
|
2764
2764
|
}, TgBotClientError, never>;
|
|
2765
2765
|
|
|
2766
2766
|
type AvailableUpdateTypes = Exclude<keyof Update, 'update_id'>;
|
|
2767
|
+
type LogLevel = "info" | "debug";
|
|
2767
2768
|
type BotResponse = {
|
|
2768
2769
|
[K in keyof Api]: K extends `send_${infer R}` ? {
|
|
2769
2770
|
type: Lowercase<R>;
|
|
2770
2771
|
} & Omit<Parameters<Api[K]>[0], 'chat_id'> : never;
|
|
2771
2772
|
}[keyof Api];
|
|
2772
2773
|
type BotMessageHandlers = {
|
|
2773
|
-
[K in AvailableUpdateTypes as `on_${K}`]?: (update: NonNullable<Update[K]>) => BotResponse;
|
|
2774
|
+
[K in AvailableUpdateTypes as `on_${K}`]?: (update: NonNullable<Update[K]>) => BotResponse | undefined;
|
|
2774
2775
|
};
|
|
2775
2776
|
type BotMessageHandlerSettings = {
|
|
2777
|
+
readonly log_level?: LogLevel;
|
|
2778
|
+
readonly update_types?: AvailableUpdateTypes[];
|
|
2776
2779
|
readonly batch_size?: number;
|
|
2777
2780
|
readonly timeout?: number;
|
|
2778
2781
|
readonly max_empty_responses?: number;
|
|
@@ -2830,4 +2833,4 @@ type MessageEffect = keyof typeof MESSAGE_EFFECTS;
|
|
|
2830
2833
|
declare const messageEffectIdCodes: MessageEffect[];
|
|
2831
2834
|
declare const isMessageEffect: (input: unknown) => input is MessageEffect;
|
|
2832
2835
|
|
|
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 };
|
|
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 };
|
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({
|
|
@@ -241,6 +241,8 @@ var makeSettingsFrom = (input) => {
|
|
|
241
241
|
let limit = input.batch_size ?? 10;
|
|
242
242
|
let timeout = input.timeout ?? 10;
|
|
243
243
|
let max_empty_responses = input.max_empty_responses;
|
|
244
|
+
let update_types = input.update_types;
|
|
245
|
+
let log_level = input.log_level;
|
|
244
246
|
if (limit < 10 || limit > 100) {
|
|
245
247
|
console.warn("Wrong limit, must be in [10..100], using 10 instead");
|
|
246
248
|
limit = 10;
|
|
@@ -253,10 +255,23 @@ var makeSettingsFrom = (input) => {
|
|
|
253
255
|
console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
|
|
254
256
|
max_empty_responses = void 0;
|
|
255
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
|
+
}
|
|
256
269
|
return {
|
|
257
270
|
limit,
|
|
258
271
|
timeout,
|
|
259
|
-
max_empty_responses
|
|
272
|
+
max_empty_responses,
|
|
273
|
+
update_types,
|
|
274
|
+
log_level
|
|
260
275
|
};
|
|
261
276
|
};
|
|
262
277
|
|
|
@@ -274,13 +289,15 @@ var extractUpdate = (input) => {
|
|
|
274
289
|
...value
|
|
275
290
|
};
|
|
276
291
|
}
|
|
277
|
-
return
|
|
292
|
+
return;
|
|
278
293
|
};
|
|
279
294
|
|
|
280
295
|
// src/bot/update-poller/fetch-updates.ts
|
|
281
296
|
var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.gen(function* () {
|
|
282
297
|
const updateId = state.lastUpdateId;
|
|
283
|
-
|
|
298
|
+
if (settings.log_level == "debug") {
|
|
299
|
+
console.debug("getting updates", state);
|
|
300
|
+
}
|
|
284
301
|
const updates = yield* execute2("get_updates", {
|
|
285
302
|
...settings,
|
|
286
303
|
...updateId ? { offset: updateId } : void 0
|
|
@@ -298,34 +315,49 @@ var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.
|
|
|
298
315
|
}
|
|
299
316
|
const handler = handlers[`on_${update.type}`];
|
|
300
317
|
if (!handler) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
318
|
+
if (settings.update_types.includes(update.type)) {
|
|
319
|
+
console.error("Handler for update not defined", update);
|
|
320
|
+
hasError = true;
|
|
321
|
+
break;
|
|
322
|
+
} else {
|
|
323
|
+
if (settings.log_level == "debug") {
|
|
324
|
+
console.debug("Ignored update", update);
|
|
325
|
+
}
|
|
326
|
+
lastSuccessId = updateObject.update_id;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (update.type == "message" && "text" in update) {
|
|
331
|
+
console.info("Got new message", {
|
|
332
|
+
chatId: update.chat.id,
|
|
333
|
+
chatType: update.chat.type,
|
|
334
|
+
message: `${update.text.slice(0, 5)}...`
|
|
335
|
+
});
|
|
304
336
|
}
|
|
305
337
|
const handleResult = handler(update);
|
|
306
|
-
if ("chat" in update) {
|
|
338
|
+
if ("chat" in update && handleResult) {
|
|
307
339
|
const response = yield* execute2(`send_${handleResult.type}`, {
|
|
308
340
|
...handleResult,
|
|
309
341
|
chat_id: update.chat.id
|
|
310
342
|
});
|
|
311
|
-
|
|
343
|
+
if (settings.log_level == "debug" && "text") {
|
|
344
|
+
console.debug("bot response", response);
|
|
345
|
+
}
|
|
312
346
|
}
|
|
313
|
-
if (!handleResult) {
|
|
314
|
-
|
|
315
|
-
console.log(handleResult);
|
|
316
|
-
break;
|
|
347
|
+
if (!handleResult && settings.log_level == "debug") {
|
|
348
|
+
console.debug("handler returned no response for update", { update });
|
|
317
349
|
}
|
|
318
350
|
;
|
|
319
351
|
lastSuccessId = updateObject.update_id;
|
|
320
352
|
}
|
|
321
353
|
if (hasError && lastSuccessId) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
354
|
+
yield* execute2("get_updates", {
|
|
355
|
+
offset: lastSuccessId,
|
|
356
|
+
limit: 0
|
|
357
|
+
});
|
|
358
|
+
if (settings.log_level == "debug") {
|
|
359
|
+
console.debug("committed offset", lastSuccessId);
|
|
360
|
+
}
|
|
329
361
|
}
|
|
330
362
|
return { updates, lastSuccessId, hasError };
|
|
331
363
|
});
|
|
@@ -348,7 +380,7 @@ var pollAndHandle = (input) => {
|
|
|
348
380
|
Micro7.repeat({
|
|
349
381
|
while: ({ updates, lastSuccessId, hasError }) => {
|
|
350
382
|
if (hasError) {
|
|
351
|
-
console.
|
|
383
|
+
console.info("error in handler, quitting");
|
|
352
384
|
return false;
|
|
353
385
|
}
|
|
354
386
|
if (updates.length == 0) {
|
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({
|
|
@@ -198,6 +198,8 @@ var makeSettingsFrom = (input) => {
|
|
|
198
198
|
let limit = input.batch_size ?? 10;
|
|
199
199
|
let timeout = input.timeout ?? 10;
|
|
200
200
|
let max_empty_responses = input.max_empty_responses;
|
|
201
|
+
let update_types = input.update_types;
|
|
202
|
+
let log_level = input.log_level;
|
|
201
203
|
if (limit < 10 || limit > 100) {
|
|
202
204
|
console.warn("Wrong limit, must be in [10..100], using 10 instead");
|
|
203
205
|
limit = 10;
|
|
@@ -210,10 +212,23 @@ var makeSettingsFrom = (input) => {
|
|
|
210
212
|
console.warn("Wrong max_empty_responses, must be in [2..infinity], using infinity");
|
|
211
213
|
max_empty_responses = void 0;
|
|
212
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
|
+
}
|
|
213
226
|
return {
|
|
214
227
|
limit,
|
|
215
228
|
timeout,
|
|
216
|
-
max_empty_responses
|
|
229
|
+
max_empty_responses,
|
|
230
|
+
update_types,
|
|
231
|
+
log_level
|
|
217
232
|
};
|
|
218
233
|
};
|
|
219
234
|
|
|
@@ -231,13 +246,15 @@ var extractUpdate = (input) => {
|
|
|
231
246
|
...value
|
|
232
247
|
};
|
|
233
248
|
}
|
|
234
|
-
return
|
|
249
|
+
return;
|
|
235
250
|
};
|
|
236
251
|
|
|
237
252
|
// src/bot/update-poller/fetch-updates.ts
|
|
238
253
|
var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.gen(function* () {
|
|
239
254
|
const updateId = state.lastUpdateId;
|
|
240
|
-
|
|
255
|
+
if (settings.log_level == "debug") {
|
|
256
|
+
console.debug("getting updates", state);
|
|
257
|
+
}
|
|
241
258
|
const updates = yield* execute2("get_updates", {
|
|
242
259
|
...settings,
|
|
243
260
|
...updateId ? { offset: updateId } : void 0
|
|
@@ -255,34 +272,49 @@ var fetchUpdates = ({ state, settings, execute: execute2, handlers }) => Micro6.
|
|
|
255
272
|
}
|
|
256
273
|
const handler = handlers[`on_${update.type}`];
|
|
257
274
|
if (!handler) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
275
|
+
if (settings.update_types.includes(update.type)) {
|
|
276
|
+
console.error("Handler for update not defined", update);
|
|
277
|
+
hasError = true;
|
|
278
|
+
break;
|
|
279
|
+
} else {
|
|
280
|
+
if (settings.log_level == "debug") {
|
|
281
|
+
console.debug("Ignored update", update);
|
|
282
|
+
}
|
|
283
|
+
lastSuccessId = updateObject.update_id;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (update.type == "message" && "text" in update) {
|
|
288
|
+
console.info("Got new message", {
|
|
289
|
+
chatId: update.chat.id,
|
|
290
|
+
chatType: update.chat.type,
|
|
291
|
+
message: `${update.text.slice(0, 5)}...`
|
|
292
|
+
});
|
|
261
293
|
}
|
|
262
294
|
const handleResult = handler(update);
|
|
263
|
-
if ("chat" in update) {
|
|
295
|
+
if ("chat" in update && handleResult) {
|
|
264
296
|
const response = yield* execute2(`send_${handleResult.type}`, {
|
|
265
297
|
...handleResult,
|
|
266
298
|
chat_id: update.chat.id
|
|
267
299
|
});
|
|
268
|
-
|
|
300
|
+
if (settings.log_level == "debug" && "text") {
|
|
301
|
+
console.debug("bot response", response);
|
|
302
|
+
}
|
|
269
303
|
}
|
|
270
|
-
if (!handleResult) {
|
|
271
|
-
|
|
272
|
-
console.log(handleResult);
|
|
273
|
-
break;
|
|
304
|
+
if (!handleResult && settings.log_level == "debug") {
|
|
305
|
+
console.debug("handler returned no response for update", { update });
|
|
274
306
|
}
|
|
275
307
|
;
|
|
276
308
|
lastSuccessId = updateObject.update_id;
|
|
277
309
|
}
|
|
278
310
|
if (hasError && lastSuccessId) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
311
|
+
yield* execute2("get_updates", {
|
|
312
|
+
offset: lastSuccessId,
|
|
313
|
+
limit: 0
|
|
314
|
+
});
|
|
315
|
+
if (settings.log_level == "debug") {
|
|
316
|
+
console.debug("committed offset", lastSuccessId);
|
|
317
|
+
}
|
|
286
318
|
}
|
|
287
319
|
return { updates, lastSuccessId, hasError };
|
|
288
320
|
});
|
|
@@ -305,7 +337,7 @@ var pollAndHandle = (input) => {
|
|
|
305
337
|
Micro7.repeat({
|
|
306
338
|
while: ({ updates, lastSuccessId, hasError }) => {
|
|
307
339
|
if (hasError) {
|
|
308
|
-
console.
|
|
340
|
+
console.info("error in handler, quitting");
|
|
309
341
|
return false;
|
|
310
342
|
}
|
|
311
343
|
if (updates.length == 0) {
|
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.1",
|
|
4
4
|
"homepage": "https://effect-ak.github.io/telegram-bot-client",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aleksandr Kondaurov",
|
|
@@ -47,9 +47,5 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"effect": "^3.11.0"
|
|
50
|
-
},
|
|
51
|
-
"scripts": {
|
|
52
|
-
"gen": "tsx ./codegen/main",
|
|
53
|
-
"echo-bot": "tsx ./example/echo-bot.ts"
|
|
54
50
|
}
|
|
55
51
|
}
|
package/readme.md
CHANGED
|
@@ -31,7 +31,7 @@ This client facilitates interaction with the Telegram Bot API. It was created pr
|
|
|
31
31
|
import { makeTgBotClient } from "@effect-ak/tg-bot-client"
|
|
32
32
|
|
|
33
33
|
const client = makeTgBotClient({
|
|
34
|
-
|
|
34
|
+
bot_token: "" //your token taken from bot father
|
|
35
35
|
});
|
|
36
36
|
```
|
|
37
37
|
|