@effect-ak/tg-bot 1.0.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.
@@ -0,0 +1,113 @@
1
+ import * as effect_Types from 'effect/Types';
2
+ import { Api, Update } from '@effect-ak/tg-bot-api';
3
+ import * as effect_Cause from 'effect/Cause';
4
+ import * as _effect_ak_tg_bot_client from '@effect-ak/tg-bot-client';
5
+ import { TgBotClientError } from '@effect-ak/tg-bot-client';
6
+ import * as Micro from 'effect/Micro';
7
+ import * as Data from 'effect/Data';
8
+ import * as Context from 'effect/Context';
9
+
10
+ type BotResult = {
11
+ [K in keyof Api]: K extends `send_${infer R}` ? {
12
+ type: R;
13
+ } & Omit<Parameters<Api[K]>[0], "chat_id"> : never;
14
+ }[keyof Api];
15
+ declare const BotResponse_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
16
+ readonly _tag: "BotResponse";
17
+ };
18
+ declare class BotResponse extends BotResponse_base<{
19
+ response?: BotResult;
20
+ }> {
21
+ static make(result: BotResult): BotResponse;
22
+ static readonly ignore: BotResponse;
23
+ }
24
+
25
+ declare const BotUpdateHandlersTag_base: Context.TagClass<BotUpdateHandlersTag, "BotUpdateHandlers", BotMode>;
26
+ declare class BotUpdateHandlersTag extends BotUpdateHandlersTag_base {
27
+ }
28
+ interface PollSettings {
29
+ log_level: "info" | "debug";
30
+ on_error: "stop" | "continue";
31
+ batch_size: number;
32
+ poll_timeout: number;
33
+ max_empty_responses: number | undefined;
34
+ }
35
+ declare class BotPollSettings extends Data.Class<PollSettings> {
36
+ static make(input: Partial<PollSettings>): BotPollSettings;
37
+ }
38
+ declare const BotPollSettingsTag_base: Context.ReferenceClass<BotPollSettings, "BotSettings", BotPollSettings>;
39
+ declare class BotPollSettingsTag extends BotPollSettingsTag_base {
40
+ }
41
+
42
+ interface RunBotInput {
43
+ bot_token: string;
44
+ mode: BotMode;
45
+ poll?: Partial<PollSettings>;
46
+ }
47
+ type ExtractedUpdate<K extends AvailableUpdateTypes> = {
48
+ type: K;
49
+ } & Update[K];
50
+ type AvailableUpdateTypes = Exclude<keyof Update, "update_id">;
51
+ type HandleUpdateFunction<U> = (update: U) => BotResponse | PromiseLike<BotResponse>;
52
+ type BotUpdatesHandlers = {
53
+ readonly [K in AvailableUpdateTypes as `on_${K}`]?: HandleUpdateFunction<NonNullable<Update[K]>>;
54
+ };
55
+ interface HandleBatchUpdateFunction {
56
+ readonly on_batch: (update: Update[]) => boolean | PromiseLike<boolean>;
57
+ }
58
+ interface BotSingleMode extends BotUpdatesHandlers {
59
+ type: "single";
60
+ }
61
+ interface BotBatchMode extends HandleBatchUpdateFunction {
62
+ type: "batch";
63
+ }
64
+ type BotMode = BotSingleMode | BotBatchMode;
65
+
66
+ declare const extractUpdate: <U extends AvailableUpdateTypes>(input: Update) => ExtractedUpdate<U> | undefined;
67
+ declare class BatchUpdateResult extends Data.Class<{
68
+ hasErrors: boolean;
69
+ updates: Update[];
70
+ }> {
71
+ }
72
+ declare const handleUpdates: (updates: Update[]) => Micro.Micro<BatchUpdateResult, never, BotUpdateHandlersTag | _effect_ak_tg_bot_client.TgBotApiToken>;
73
+ declare const handleEntireBatch: (updates: Update[], handlers: HandleBatchUpdateFunction) => Micro.Micro<BatchUpdateResult, never, never>;
74
+ declare const HandleUpdateError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
75
+ readonly _tag: "HandleUpdateError";
76
+ } & Readonly<A>;
77
+ declare class HandleUpdateError extends HandleUpdateError_base<{
78
+ name: "UnknownUpdate" | "HandlerNotDefined" | "BotHandlerError";
79
+ update: Update;
80
+ cause?: unknown;
81
+ }> {
82
+ }
83
+ declare const handleOneByOne: (updates: Update[], handlers: BotUpdatesHandlers, pollSettings: PollSettings) => Micro.Micro<BatchUpdateResult, never, _effect_ak_tg_bot_client.TgBotApiToken>;
84
+ declare const handleOneUpdate: (updateObject: Update, handlers: BotUpdatesHandlers) => Micro.Micro<HandleUpdateError | undefined, HandleUpdateError | _effect_ak_tg_bot_client.TgBotClientError, _effect_ak_tg_bot_client.TgBotApiToken>;
85
+
86
+ declare const FetchUpdatesError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
87
+ readonly _tag: "FetchUpdatesError";
88
+ } & Readonly<A>;
89
+ declare class FetchUpdatesError extends FetchUpdatesError_base<{
90
+ name: "TooManyEmptyResponses" | "NoUpdatesToCommit";
91
+ }> {
92
+ }
93
+
94
+ type BotInstance = Micro.Micro.Success<ReturnType<typeof launchBot>>;
95
+ declare const launchBot: (input: RunBotInput) => Micro.Micro<{
96
+ readonly reload: (mode: BotMode) => Promise<void>;
97
+ readonly fiber: () => Micro.MicroFiber<BatchUpdateResult, _effect_ak_tg_bot_client.TgBotClientError | FetchUpdatesError> | undefined;
98
+ }, never, never>;
99
+
100
+ declare const BotRunService_base: Context.ReferenceClass<BotRunService, "BotRunService", {
101
+ readonly runBotInBackground: Micro.Micro<void, never, BotUpdateHandlersTag | _effect_ak_tg_bot_client.TgBotApiToken>;
102
+ readonly getFiber: () => Micro.MicroFiber<BatchUpdateResult, TgBotClientError | FetchUpdatesError> | undefined;
103
+ }>;
104
+ declare class BotRunService extends BotRunService_base {
105
+ }
106
+
107
+ declare const runTgChatBot: (input: RunBotInput) => Promise<{
108
+ readonly reload: (mode: BotMode) => Promise<void>;
109
+ readonly fiber: () => Micro.MicroFiber<BatchUpdateResult, _effect_ak_tg_bot_client.TgBotClientError | FetchUpdatesError> | undefined;
110
+ }>;
111
+ declare const defineBot: (input: BotUpdatesHandlers) => BotUpdatesHandlers;
112
+
113
+ export { type AvailableUpdateTypes, BatchUpdateResult, type BotBatchMode, type BotInstance, type BotMode, BotPollSettings, BotPollSettingsTag, BotResponse, BotRunService, type BotSingleMode, BotUpdateHandlersTag, type BotUpdatesHandlers, type ExtractedUpdate, type HandleBatchUpdateFunction, HandleUpdateError, type HandleUpdateFunction, type PollSettings, type RunBotInput, defineBot, extractUpdate, handleEntireBatch, handleOneByOne, handleOneUpdate, handleUpdates, launchBot, runTgChatBot };