@prajwalshete/telegram-plugin 0.0.0-stage → 0.1.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/CHANGELOG.md +91 -0
- package/LICENSE +21 -0
- package/README.md +109 -2
- package/dist/adapters/clock.d.ts +3 -0
- package/dist/adapters/clock.js +4 -0
- package/dist/adapters/console-log.d.ts +13 -0
- package/dist/adapters/console-log.js +41 -0
- package/dist/adapters/d1-db.d.ts +5 -0
- package/dist/adapters/d1-db.js +37 -0
- package/dist/adapters/ids.d.ts +5 -0
- package/dist/adapters/ids.js +25 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/keyring.d.ts +50 -0
- package/dist/adapters/keyring.js +174 -0
- package/dist/adapters/metrics.d.ts +28 -0
- package/dist/adapters/metrics.js +48 -0
- package/dist/adapters/r2-files.d.ts +20 -0
- package/dist/adapters/r2-files.js +53 -0
- package/dist/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +45 -0
- package/dist/client/broadcasts.d.ts +35 -0
- package/dist/client/commands.d.ts +23 -0
- package/dist/client/endpoint.d.ts +34 -0
- package/dist/client/events.d.ts +33 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.js +3 -0
- package/dist/client/schedules.d.ts +42 -0
- package/dist/client/schema.d.ts +181 -0
- package/dist/client/send.d.ts +15 -0
- package/dist/client/templates.d.ts +47 -0
- package/dist/contracts/bots.d.ts +129 -0
- package/dist/contracts/bots.js +70 -0
- package/dist/contracts/broadcasts.d.ts +116 -0
- package/dist/contracts/broadcasts.js +63 -0
- package/dist/contracts/chats.d.ts +97 -0
- package/dist/contracts/chats.js +66 -0
- package/dist/contracts/commands.d.ts +52 -0
- package/dist/contracts/commands.js +53 -0
- package/dist/contracts/common.d.ts +38 -0
- package/dist/contracts/common.js +41 -0
- package/dist/contracts/deliveries.d.ts +103 -0
- package/dist/contracts/deliveries.js +74 -0
- package/dist/contracts/destinations.d.ts +24 -0
- package/dist/contracts/destinations.js +28 -0
- package/dist/contracts/events.d.ts +165 -0
- package/dist/contracts/events.js +98 -0
- package/dist/contracts/features.d.ts +20 -0
- package/dist/contracts/features.js +21 -0
- package/dist/contracts/health.d.ts +55 -0
- package/dist/contracts/health.js +58 -0
- package/dist/contracts/index.d.ts +22 -0
- package/dist/contracts/index.js +22 -0
- package/dist/contracts/labels.d.ts +38 -0
- package/dist/contracts/labels.js +52 -0
- package/dist/contracts/links.d.ts +51 -0
- package/dist/contracts/links.js +50 -0
- package/dist/contracts/meta.d.ts +132 -0
- package/dist/contracts/meta.js +85 -0
- package/dist/contracts/permissions.d.ts +24 -0
- package/dist/contracts/permissions.js +27 -0
- package/dist/contracts/problems.d.ts +106 -0
- package/dist/contracts/problems.js +101 -0
- package/dist/contracts/recipients.d.ts +36 -0
- package/dist/contracts/recipients.js +22 -0
- package/dist/contracts/schedules.d.ts +276 -0
- package/dist/contracts/schedules.js +143 -0
- package/dist/contracts/send.d.ts +126 -0
- package/dist/contracts/send.js +69 -0
- package/dist/contracts/subscriptions.d.ts +38 -0
- package/dist/contracts/subscriptions.js +31 -0
- package/dist/contracts/templates.d.ts +358 -0
- package/dist/contracts/templates.js +174 -0
- package/dist/contracts/users.d.ts +15 -0
- package/dist/contracts/users.js +19 -0
- package/dist/core/guards.d.ts +22 -0
- package/dist/core/guards.js +47 -0
- package/dist/core/html/escape.d.ts +2 -0
- package/dist/core/html/escape.js +36 -0
- package/dist/core/html/tokenize.js +65 -0
- package/dist/core/index.d.ts +18 -0
- package/dist/core/pacing.d.ts +1 -0
- package/dist/core/pacing.js +86 -0
- package/dist/core/random.d.ts +2 -0
- package/dist/core/random.js +38 -0
- package/dist/core/recipients.d.ts +1 -0
- package/dist/core/recipients.js +86 -0
- package/dist/core/schedule/describe.d.ts +3 -0
- package/dist/core/schedule/describe.js +74 -0
- package/dist/core/schedule/index.d.ts +4 -0
- package/dist/core/schedule/policy.d.ts +1 -0
- package/dist/core/schedule/policy.js +37 -0
- package/dist/core/schedule/rule.d.ts +25 -0
- package/dist/core/schedule/rule.js +142 -0
- package/dist/core/schedule/tz.d.ts +2 -0
- package/dist/core/schedule/tz.js +59 -0
- package/dist/core/split/plain.d.ts +2 -0
- package/dist/core/split/plain.js +23 -0
- package/dist/core/split/split.d.ts +15 -0
- package/dist/core/split/split.js +158 -0
- package/dist/core/template/ast.d.ts +58 -0
- package/dist/core/template/ast.js +5 -0
- package/dist/core/template/expr.js +108 -0
- package/dist/core/template/filters.d.ts +20 -0
- package/dist/core/template/filters.js +127 -0
- package/dist/core/template/format.d.ts +17 -0
- package/dist/core/template/format.js +88 -0
- package/dist/core/template/index.d.ts +20 -0
- package/dist/core/template/index.js +29 -0
- package/dist/core/template/parse.d.ts +8 -0
- package/dist/core/template/parse.js +369 -0
- package/dist/core/template/render.d.ts +17 -0
- package/dist/core/template/render.js +118 -0
- package/dist/core/template/shape.d.ts +28 -0
- package/dist/core/template/shape.js +151 -0
- package/dist/core/template/tags.js +105 -0
- package/dist/core/template/validate.d.ts +10 -0
- package/dist/core/template/validate.js +144 -0
- package/dist/core/template/variables.d.ts +15 -0
- package/dist/core/template/variables.js +41 -0
- package/dist/do/index.d.ts +3 -0
- package/dist/do/index.js +3 -0
- package/dist/do/telegram-bot-do.d.ts +45 -0
- package/dist/do/telegram-bot-do.js +219 -0
- package/dist/engine/actions/callback.js +256 -0
- package/dist/engine/actions/tokens.d.ts +2 -0
- package/dist/engine/actions/tokens.js +51 -0
- package/dist/engine/bot-api.js +20 -0
- package/dist/engine/bot-features.js +39 -0
- package/dist/engine/chat-state.js +66 -0
- package/dist/engine/content/audience.js +54 -0
- package/dist/engine/content/buttons.d.ts +1 -0
- package/dist/engine/content/buttons.js +113 -0
- package/dist/engine/content/fanout.js +284 -0
- package/dist/engine/content/intersect.d.ts +6 -0
- package/dist/engine/content/intersect.js +26 -0
- package/dist/engine/content/providers.d.ts +6 -0
- package/dist/engine/content/providers.js +142 -0
- package/dist/engine/content/recipients.js +128 -0
- package/dist/engine/content/render.js +138 -0
- package/dist/engine/content/reply.js +156 -0
- package/dist/engine/content/report-files.js +78 -0
- package/dist/engine/content/template-rows.js +74 -0
- package/dist/engine/dialogs/dialog.d.ts +2 -0
- package/dist/engine/dialogs/dialog.js +375 -0
- package/dist/engine/dispatch/builtins.js +198 -0
- package/dist/engine/dispatch/commands.js +194 -0
- package/dist/engine/dispatch/context.d.ts +2 -0
- package/dist/engine/dispatch/context.js +194 -0
- package/dist/engine/dispatch/dispatcher.js +66 -0
- package/dist/engine/dispatch/handlers.d.ts +1 -0
- package/dist/engine/dispatch/handlers.js +103 -0
- package/dist/engine/dispatch/lifecycle.js +85 -0
- package/dist/engine/dispatch/link-chat.js +31 -0
- package/dist/engine/dispatch/linking.js +273 -0
- package/dist/engine/errors.d.ts +60 -0
- package/dist/engine/errors.js +72 -0
- package/dist/engine/events/filters.d.ts +5 -0
- package/dist/engine/events/filters.js +82 -0
- package/dist/engine/events/kick.js +30 -0
- package/dist/engine/events/payload.d.ts +3 -0
- package/dist/engine/events/payload.js +16 -0
- package/dist/engine/events/tick.js +208 -0
- package/dist/engine/i18n.d.ts +12 -0
- package/dist/engine/i18n.js +55 -0
- package/dist/engine/inbound/files.js +121 -0
- package/dist/engine/inbound/handler.js +46 -0
- package/dist/engine/jobs.d.ts +32 -0
- package/dist/engine/jobs.js +85 -0
- package/dist/engine/link-codes.js +46 -0
- package/dist/engine/metrics.js +12 -0
- package/dist/engine/options.d.ts +369 -0
- package/dist/engine/options.js +81 -0
- package/dist/engine/outbox/dead-letter.js +78 -0
- package/dist/engine/outbox/do-registry.d.ts +10 -0
- package/dist/engine/outbox/do-registry.js +10 -0
- package/dist/engine/outbox/do-transport.d.ts +33 -0
- package/dist/engine/outbox/do-transport.js +73 -0
- package/dist/engine/outbox/drain.d.ts +13 -0
- package/dist/engine/outbox/drain.js +381 -0
- package/dist/engine/outbox/enqueue.d.ts +1 -0
- package/dist/engine/outbox/enqueue.js +63 -0
- package/dist/engine/outbox/select.js +24 -0
- package/dist/engine/outbox/send.js +362 -0
- package/dist/engine/outbox/transport.d.ts +35 -0
- package/dist/engine/outbox/transport.js +175 -0
- package/dist/engine/outbox/wake.js +28 -0
- package/dist/engine/registry.d.ts +502 -0
- package/dist/engine/registry.js +258 -0
- package/dist/engine/rows.d.ts +25 -0
- package/dist/engine/rows.js +131 -0
- package/dist/engine/runtime.d.ts +95 -0
- package/dist/engine/runtime.js +149 -0
- package/dist/engine/schedules/fire.js +208 -0
- package/dist/engine/schedules/resume.js +75 -0
- package/dist/engine/schedules/rows.js +69 -0
- package/dist/engine/schedules/tick.js +30 -0
- package/dist/engine/schedules/wake.js +50 -0
- package/dist/engine/state.d.ts +11 -0
- package/dist/engine/state.js +78 -0
- package/dist/locales/en.js +339 -0
- package/dist/locales/en.json +341 -0
- package/dist/locales/mr.js +339 -0
- package/dist/locales/mr.json +341 -0
- package/dist/ports/db.d.ts +22 -0
- package/dist/ports/index.d.ts +4 -0
- package/dist/ports/ports.d.ts +257 -0
- package/dist/ports/sql.d.ts +39 -0
- package/dist/ports/sql.js +76 -0
- package/dist/renderers/csv.d.ts +14 -0
- package/dist/renderers/csv.js +51 -0
- package/dist/renderers/html.d.ts +44 -0
- package/dist/renderers/html.js +81 -0
- package/dist/renderers/index.d.ts +5 -0
- package/dist/renderers/index.js +4 -0
- package/dist/renderers/table.d.ts +30 -0
- package/dist/renderers/table.js +114 -0
- package/dist/routes/admin.js +146 -0
- package/dist/routes/app.d.ts +3111 -0
- package/dist/routes/app.js +9 -0
- package/dist/routes/broadcasts.js +37 -0
- package/dist/routes/commands.js +35 -0
- package/dist/routes/content.js +12 -0
- package/dist/routes/events.js +36 -0
- package/dist/routes/http.d.ts +30 -0
- package/dist/routes/http.js +223 -0
- package/dist/routes/me.js +59 -0
- package/dist/routes/schedules.js +62 -0
- package/dist/routes/send.js +24 -0
- package/dist/routes/templates.js +70 -0
- package/dist/routes/webhook.js +147 -0
- package/dist/schema/columns.js +307 -0
- package/dist/schema/ddl.d.ts +7 -0
- package/dist/schema/ddl.js +45 -0
- package/dist/schema/index.d.ts +4255 -0
- package/dist/schema/index.js +44 -0
- package/dist/schema/reference.sql +359 -0
- package/dist/schema/tables.d.ts +4243 -0
- package/dist/schema/tables.js +327 -0
- package/dist/schema/version.d.ts +5 -0
- package/dist/schema/version.js +7 -0
- package/dist/server/index.d.ts +55 -0
- package/dist/server/index.js +46 -0
- package/dist/server/plugin.d.ts +81 -0
- package/dist/server/plugin.js +247 -0
- package/dist/server/version.d.ts +2 -0
- package/dist/server/version.js +4 -0
- package/dist/services/ai-tool.d.ts +26 -0
- package/dist/services/ai-tool.js +148 -0
- package/dist/services/bots.js +300 -0
- package/dist/services/broadcasts.js +390 -0
- package/dist/services/chats.js +83 -0
- package/dist/services/cleanup.js +83 -0
- package/dist/services/commands.js +140 -0
- package/dist/services/deliveries.js +53 -0
- package/dist/services/destinations.js +91 -0
- package/dist/services/event-rules.js +229 -0
- package/dist/services/events.js +20 -0
- package/dist/services/idempotency.js +64 -0
- package/dist/services/links.js +200 -0
- package/dist/services/menu.js +95 -0
- package/dist/services/ops.js +90 -0
- package/dist/services/rekey.js +63 -0
- package/dist/services/reports.js +87 -0
- package/dist/services/schedules.js +214 -0
- package/dist/services/send.d.ts +14 -0
- package/dist/services/send.js +421 -0
- package/dist/services/subscriptions.js +28 -0
- package/dist/services/templates.js +259 -0
- package/dist/telegram/classify.d.ts +30 -0
- package/dist/telegram/classify.js +164 -0
- package/dist/telegram/client.d.ts +73 -0
- package/dist/telegram/client.js +135 -0
- package/dist/telegram/errors.d.ts +37 -0
- package/dist/telegram/errors.js +62 -0
- package/dist/telegram/inbound.d.ts +40 -0
- package/dist/telegram/inbound.js +72 -0
- package/dist/telegram/index.d.ts +8 -0
- package/dist/telegram/multipart.d.ts +5 -0
- package/dist/telegram/multipart.js +47 -0
- package/dist/telegram/types.d.ts +271 -0
- package/dist/telegram/update.d.ts +833 -0
- package/dist/telegram/update.js +129 -0
- package/dist/testing/fake-html.d.ts +9 -0
- package/dist/testing/fake-html.js +83 -0
- package/dist/testing/fake-telegram.d.ts +206 -0
- package/dist/testing/fake-telegram.js +856 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/reference-sql.d.ts +4 -0
- package/dist/testing/reference-sql.js +8 -0
- package/dist/testing/test-plugin.d.ts +126 -0
- package/dist/testing/test-plugin.js +182 -0
- package/dist/testing/updates.d.ts +100 -0
- package/dist/testing/updates.js +212 -0
- package/package.json +113 -3
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Plugin row id (UUIDv7 text). */
|
|
3
|
+
export declare const Id: z.ZodString;
|
|
4
|
+
/** Epoch milliseconds, UTC. */
|
|
5
|
+
export declare const EpochMs: z.ZodNumber;
|
|
6
|
+
/** BCP 47-ish locale tag the plugin understands (`en`, `mr`, `pt-BR`). */
|
|
7
|
+
export declare const Locale: z.ZodString;
|
|
8
|
+
export type Locale = z.infer<typeof Locale>;
|
|
9
|
+
/** Text in several locales, for example `{ en: "Approve", mr: "मंजूर" }`. At least one entry. */
|
|
10
|
+
export declare const LocalizedText: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
11
|
+
export type LocalizedText = z.infer<typeof LocalizedText>;
|
|
12
|
+
/** IANA time zone name (`Asia/Kolkata`). Checked with `Intl`. */
|
|
13
|
+
export declare const TimeZone: z.ZodString;
|
|
14
|
+
/** Local wall-clock time `HH:MM` (24 h). */
|
|
15
|
+
export declare const ClockTime: z.ZodString;
|
|
16
|
+
/** Telegram chat id as text (ids exceed 2^53 in JS). */
|
|
17
|
+
export declare const TelegramChatId: z.ZodString;
|
|
18
|
+
/** Stable machine key (`daily-summary`, `payment.received`). */
|
|
19
|
+
export declare const Key: z.ZodString;
|
|
20
|
+
/** Free-form JSON object (provider params, action params). */
|
|
21
|
+
export declare const JsonObject: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
22
|
+
export type JsonObject = z.infer<typeof JsonObject>;
|
|
23
|
+
/** `?cursor=&limit=` for every list. */
|
|
24
|
+
export declare const PageQuery: z.ZodObject<{
|
|
25
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
26
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type PageQuery = z.infer<typeof PageQuery>;
|
|
29
|
+
/** `{ items, next }` page wrapper. `next` is the cursor for the following page, or null at the end. */
|
|
30
|
+
export declare function page<T extends z.ZodType>(item: T): z.ZodObject<{
|
|
31
|
+
items: z.ZodArray<T>;
|
|
32
|
+
next: z.ZodNullable<z.ZodString>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
/** Inferred shape of a {@link page} response. */
|
|
35
|
+
export type Page<T> = {
|
|
36
|
+
items: T[];
|
|
37
|
+
next: string | null;
|
|
38
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// src/contracts/common.ts
|
|
3
|
+
/** Plugin row id (UUIDv7 text). */
|
|
4
|
+
const Id = z.string().min(1).max(64);
|
|
5
|
+
/** Epoch milliseconds, UTC. */
|
|
6
|
+
const EpochMs = z.number().int().nonnegative();
|
|
7
|
+
/** BCP 47-ish locale tag the plugin understands (`en`, `mr`, `pt-BR`). */
|
|
8
|
+
const Locale = z.string().regex(/^[a-z]{2,3}(-[A-Za-z]{2,4})?$/, "locale");
|
|
9
|
+
/** Text in several locales, for example `{ en: "Approve", mr: "मंजूर" }`. At least one entry. */
|
|
10
|
+
const LocalizedText = z.record(Locale, z.string().min(1).max(4096)).refine((v) => Object.keys(v).length > 0, "at least one locale");
|
|
11
|
+
function isTimeZone(tz) {
|
|
12
|
+
try {
|
|
13
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
14
|
+
return true;
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** IANA time zone name (`Asia/Kolkata`). Checked with `Intl`. */
|
|
20
|
+
const TimeZone = z.string().min(1).max(64).refine(isTimeZone, "timezone_invalid");
|
|
21
|
+
/** Local wall-clock time `HH:MM` (24 h). */
|
|
22
|
+
const ClockTime = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "HH:MM");
|
|
23
|
+
/** Telegram chat id as text (ids exceed 2^53 in JS). */
|
|
24
|
+
const TelegramChatId = z.string().regex(/^-?\d{1,20}$/, "chat id");
|
|
25
|
+
/** Stable machine key (`daily-summary`, `payment.received`). */
|
|
26
|
+
const Key = z.string().regex(/^[a-z0-9][a-z0-9._:-]{0,63}$/, "key");
|
|
27
|
+
/** Free-form JSON object (provider params, action params). */
|
|
28
|
+
const JsonObject = z.record(z.string(), z.unknown());
|
|
29
|
+
/** `?cursor=&limit=` for every list. */
|
|
30
|
+
const PageQuery = z.object({
|
|
31
|
+
cursor: z.string().max(512).optional(),
|
|
32
|
+
limit: z.coerce.number().int().min(1).max(200).default(50)
|
|
33
|
+
});
|
|
34
|
+
/** `{ items, next }` page wrapper. `next` is the cursor for the following page, or null at the end. */
|
|
35
|
+
function page(item) {
|
|
36
|
+
return z.object({
|
|
37
|
+
items: z.array(item),
|
|
38
|
+
next: z.string().nullable()
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export { ClockTime, EpochMs, Id, JsonObject, Key, Locale, LocalizedText, PageQuery, TelegramChatId, TimeZone, page };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** What produced a delivery row. */
|
|
3
|
+
export declare const DELIVERY_SOURCES: readonly ["schedule", "event", "broadcast", "command", "ai", "api", "system"];
|
|
4
|
+
/** Zod enum of {@link DELIVERY_SOURCES}. */
|
|
5
|
+
export declare const DeliverySource: z.ZodEnum<{
|
|
6
|
+
command: "command";
|
|
7
|
+
schedule: "schedule";
|
|
8
|
+
event: "event";
|
|
9
|
+
broadcast: "broadcast";
|
|
10
|
+
ai: "ai";
|
|
11
|
+
api: "api";
|
|
12
|
+
system: "system";
|
|
13
|
+
}>;
|
|
14
|
+
export type DeliverySource = z.infer<typeof DeliverySource>;
|
|
15
|
+
/** Bot API operation a delivery performs (`edit`/`delete` act on an earlier message). */
|
|
16
|
+
export declare const DELIVERY_KINDS: readonly ["text", "document", "photo", "edit", "delete"];
|
|
17
|
+
/** Zod enum of {@link DELIVERY_KINDS}. */
|
|
18
|
+
export declare const DeliveryKind: z.ZodEnum<{
|
|
19
|
+
text: "text";
|
|
20
|
+
document: "document";
|
|
21
|
+
photo: "photo";
|
|
22
|
+
edit: "edit";
|
|
23
|
+
delete: "delete";
|
|
24
|
+
}>;
|
|
25
|
+
export type DeliveryKind = z.infer<typeof DeliveryKind>;
|
|
26
|
+
/** Outbox row status. `dropped` = not deliverable (chat not active); `cancelled` = cancelled by an operator or the source. */
|
|
27
|
+
export declare const DELIVERY_STATUSES: readonly ["queued", "sending", "sent", "failed", "dropped", "cancelled"];
|
|
28
|
+
/** Zod enum of {@link DELIVERY_STATUSES}. */
|
|
29
|
+
export declare const DeliveryStatus: z.ZodEnum<{
|
|
30
|
+
queued: "queued";
|
|
31
|
+
sending: "sending";
|
|
32
|
+
sent: "sent";
|
|
33
|
+
failed: "failed";
|
|
34
|
+
dropped: "dropped";
|
|
35
|
+
cancelled: "cancelled";
|
|
36
|
+
}>;
|
|
37
|
+
export type DeliveryStatus = z.infer<typeof DeliveryStatus>;
|
|
38
|
+
/** One outbox row (`/admin/deliveries`, permission `telegram.ops.view`). */
|
|
39
|
+
export declare const DeliveryDto: z.ZodObject<{
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
botId: z.ZodString;
|
|
42
|
+
chatRef: z.ZodString;
|
|
43
|
+
messageThreadId: z.ZodNullable<z.ZodNumber>;
|
|
44
|
+
source: z.ZodEnum<{
|
|
45
|
+
command: "command";
|
|
46
|
+
schedule: "schedule";
|
|
47
|
+
event: "event";
|
|
48
|
+
broadcast: "broadcast";
|
|
49
|
+
ai: "ai";
|
|
50
|
+
api: "api";
|
|
51
|
+
system: "system";
|
|
52
|
+
}>;
|
|
53
|
+
sourceId: z.ZodNullable<z.ZodString>;
|
|
54
|
+
kind: z.ZodEnum<{
|
|
55
|
+
text: "text";
|
|
56
|
+
document: "document";
|
|
57
|
+
photo: "photo";
|
|
58
|
+
edit: "edit";
|
|
59
|
+
delete: "delete";
|
|
60
|
+
}>;
|
|
61
|
+
bodyHtml: z.ZodNullable<z.ZodString>;
|
|
62
|
+
part: z.ZodNumber;
|
|
63
|
+
parts: z.ZodNumber;
|
|
64
|
+
fileName: z.ZodNullable<z.ZodString>;
|
|
65
|
+
status: z.ZodEnum<{
|
|
66
|
+
queued: "queued";
|
|
67
|
+
sending: "sending";
|
|
68
|
+
sent: "sent";
|
|
69
|
+
failed: "failed";
|
|
70
|
+
dropped: "dropped";
|
|
71
|
+
cancelled: "cancelled";
|
|
72
|
+
}>;
|
|
73
|
+
attempts: z.ZodNumber;
|
|
74
|
+
nextAttemptAt: z.ZodNullable<z.ZodNumber>;
|
|
75
|
+
tgMessageId: z.ZodNullable<z.ZodNumber>;
|
|
76
|
+
errorCode: z.ZodNullable<z.ZodString>;
|
|
77
|
+
errorDetail: z.ZodNullable<z.ZodString>;
|
|
78
|
+
createdAt: z.ZodNumber;
|
|
79
|
+
sentAt: z.ZodNullable<z.ZodNumber>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
export type DeliveryDto = z.infer<typeof DeliveryDto>;
|
|
82
|
+
/** Filters for `GET /admin/deliveries`. */
|
|
83
|
+
export declare const DeliveryQuery: z.ZodObject<{
|
|
84
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
85
|
+
queued: "queued";
|
|
86
|
+
sending: "sending";
|
|
87
|
+
sent: "sent";
|
|
88
|
+
failed: "failed";
|
|
89
|
+
dropped: "dropped";
|
|
90
|
+
cancelled: "cancelled";
|
|
91
|
+
}>>;
|
|
92
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
93
|
+
command: "command";
|
|
94
|
+
schedule: "schedule";
|
|
95
|
+
event: "event";
|
|
96
|
+
broadcast: "broadcast";
|
|
97
|
+
ai: "ai";
|
|
98
|
+
api: "api";
|
|
99
|
+
system: "system";
|
|
100
|
+
}>>;
|
|
101
|
+
bot: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
export type DeliveryQuery = z.infer<typeof DeliveryQuery>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { EpochMs, Id } from "./common.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/contracts/deliveries.ts
|
|
4
|
+
/** What produced a delivery row. */
|
|
5
|
+
const DELIVERY_SOURCES = [
|
|
6
|
+
"schedule",
|
|
7
|
+
"event",
|
|
8
|
+
"broadcast",
|
|
9
|
+
"command",
|
|
10
|
+
"ai",
|
|
11
|
+
"api",
|
|
12
|
+
"system"
|
|
13
|
+
];
|
|
14
|
+
/** Zod enum of {@link DELIVERY_SOURCES}. */
|
|
15
|
+
const DeliverySource = z.enum(DELIVERY_SOURCES);
|
|
16
|
+
/** Bot API operation a delivery performs (`edit`/`delete` act on an earlier message). */
|
|
17
|
+
const DELIVERY_KINDS = [
|
|
18
|
+
"text",
|
|
19
|
+
"document",
|
|
20
|
+
"photo",
|
|
21
|
+
"edit",
|
|
22
|
+
"delete"
|
|
23
|
+
];
|
|
24
|
+
/** Zod enum of {@link DELIVERY_KINDS}. */
|
|
25
|
+
const DeliveryKind = z.enum(DELIVERY_KINDS);
|
|
26
|
+
/** Outbox row status. `dropped` = not deliverable (chat not active); `cancelled` = cancelled by an operator or the source. */
|
|
27
|
+
const DELIVERY_STATUSES = [
|
|
28
|
+
"queued",
|
|
29
|
+
"sending",
|
|
30
|
+
"sent",
|
|
31
|
+
"failed",
|
|
32
|
+
"dropped",
|
|
33
|
+
"cancelled"
|
|
34
|
+
];
|
|
35
|
+
/** Zod enum of {@link DELIVERY_STATUSES}. */
|
|
36
|
+
const DeliveryStatus = z.enum(DELIVERY_STATUSES);
|
|
37
|
+
/** One outbox row (`/admin/deliveries`, permission `telegram.ops.view`). */
|
|
38
|
+
const DeliveryDto = z.object({
|
|
39
|
+
id: Id,
|
|
40
|
+
botId: Id,
|
|
41
|
+
/** Plugin chat row id (not the Telegram chat id). */
|
|
42
|
+
chatRef: Id,
|
|
43
|
+
/** Forum topic id, or null. */
|
|
44
|
+
messageThreadId: z.number().int().nullable(),
|
|
45
|
+
source: DeliverySource,
|
|
46
|
+
/** Id of the schedule run, event, broadcast… that produced it, or null. */
|
|
47
|
+
sourceId: z.string().nullable(),
|
|
48
|
+
kind: DeliveryKind,
|
|
49
|
+
/** Only for callers with `telegram.ops.content`; otherwise null. */
|
|
50
|
+
bodyHtml: z.string().nullable(),
|
|
51
|
+
/** 0-based part index of a split message. */
|
|
52
|
+
part: z.number().int().nonnegative(),
|
|
53
|
+
/** Total parts of the split message. */
|
|
54
|
+
parts: z.number().int().positive(),
|
|
55
|
+
fileName: z.string().nullable(),
|
|
56
|
+
status: DeliveryStatus,
|
|
57
|
+
attempts: z.number().int().nonnegative(),
|
|
58
|
+
/** Next retry time (epoch ms UTC), or null. */
|
|
59
|
+
nextAttemptAt: EpochMs.nullable(),
|
|
60
|
+
/** Telegram `message_id` once sent. */
|
|
61
|
+
tgMessageId: z.number().int().nullable(),
|
|
62
|
+
/** Last error code (plugin problem code or `chat_<status>`), or null. */
|
|
63
|
+
errorCode: z.string().nullable(),
|
|
64
|
+
errorDetail: z.string().nullable(),
|
|
65
|
+
createdAt: EpochMs,
|
|
66
|
+
sentAt: EpochMs.nullable()
|
|
67
|
+
});
|
|
68
|
+
/** Filters for `GET /admin/deliveries`. */
|
|
69
|
+
const DeliveryQuery = z.object({
|
|
70
|
+
status: DeliveryStatus.optional(),
|
|
71
|
+
source: DeliverySource.optional(),
|
|
72
|
+
bot: Id.optional()
|
|
73
|
+
});
|
|
74
|
+
export { DELIVERY_KINDS, DELIVERY_SOURCES, DELIVERY_STATUSES, DeliveryDto, DeliveryKind, DeliveryQuery, DeliverySource, DeliveryStatus };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** URL-safe slug: lowercase letters, digits, `-`; ≤ 63 chars. */
|
|
3
|
+
export declare const Slug: z.ZodString;
|
|
4
|
+
/** A named, reusable target ("Site Team group"). */
|
|
5
|
+
export declare const DestinationDto: z.ZodObject<{
|
|
6
|
+
id: z.ZodString;
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
slug: z.ZodString;
|
|
9
|
+
botId: z.ZodString;
|
|
10
|
+
chatRef: z.ZodString;
|
|
11
|
+
messageThreadId: z.ZodNullable<z.ZodNumber>;
|
|
12
|
+
aiAllowed: z.ZodBoolean;
|
|
13
|
+
createdAt: z.ZodNumber;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type DestinationDto = z.infer<typeof DestinationDto>;
|
|
16
|
+
/** Body to create or replace a destination (defaults: no topic, `aiAllowed: false`). */
|
|
17
|
+
export declare const DestinationSave: z.ZodObject<{
|
|
18
|
+
name: z.ZodString;
|
|
19
|
+
slug: z.ZodString;
|
|
20
|
+
chatRef: z.ZodString;
|
|
21
|
+
messageThreadId: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
22
|
+
aiAllowed: z.ZodDefault<z.ZodBoolean>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type DestinationSave = z.infer<typeof DestinationSave>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EpochMs, Id } from "./common.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/contracts/destinations.ts
|
|
4
|
+
/** URL-safe slug: lowercase letters, digits, `-`; ≤ 63 chars. */
|
|
5
|
+
const Slug = z.string().regex(/^[a-z0-9][a-z0-9-]{0,62}$/, "slug");
|
|
6
|
+
/** A named, reusable target ("Site Team group"). */
|
|
7
|
+
const DestinationDto = z.object({
|
|
8
|
+
id: Id,
|
|
9
|
+
name: z.string(),
|
|
10
|
+
slug: Slug,
|
|
11
|
+
botId: Id,
|
|
12
|
+
/** Plugin chat row id. */
|
|
13
|
+
chatRef: Id,
|
|
14
|
+
/** Forum topic to post in, or null. */
|
|
15
|
+
messageThreadId: z.number().int().positive().nullable(),
|
|
16
|
+
/** Whether the AI send tool may target this destination. */
|
|
17
|
+
aiAllowed: z.boolean(),
|
|
18
|
+
createdAt: EpochMs
|
|
19
|
+
});
|
|
20
|
+
/** Body to create or replace a destination (defaults: no topic, `aiAllowed: false`). */
|
|
21
|
+
const DestinationSave = z.object({
|
|
22
|
+
name: z.string().trim().min(1).max(80),
|
|
23
|
+
slug: Slug,
|
|
24
|
+
chatRef: Id,
|
|
25
|
+
messageThreadId: z.number().int().positive().nullable().default(null),
|
|
26
|
+
aiAllowed: z.boolean().default(false)
|
|
27
|
+
});
|
|
28
|
+
export { DestinationDto, DestinationSave, Slug };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Comparison operators for {@link EventFilter}. */
|
|
3
|
+
export declare const FILTER_OPS: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "in", "contains"];
|
|
4
|
+
/** Zod enum of {@link FILTER_OPS}. */
|
|
5
|
+
export declare const FilterOp: z.ZodEnum<{
|
|
6
|
+
in: "in";
|
|
7
|
+
eq: "eq";
|
|
8
|
+
ne: "ne";
|
|
9
|
+
gt: "gt";
|
|
10
|
+
gte: "gte";
|
|
11
|
+
lt: "lt";
|
|
12
|
+
lte: "lte";
|
|
13
|
+
contains: "contains";
|
|
14
|
+
}>;
|
|
15
|
+
export type FilterOp = z.infer<typeof FilterOp>;
|
|
16
|
+
/** One condition on an event payload field (only fields the event marks `filterable`). All conditions must hold. */
|
|
17
|
+
export declare const EventFilter: z.ZodObject<{
|
|
18
|
+
field: z.ZodString;
|
|
19
|
+
op: z.ZodEnum<{
|
|
20
|
+
in: "in";
|
|
21
|
+
eq: "eq";
|
|
22
|
+
ne: "ne";
|
|
23
|
+
gt: "gt";
|
|
24
|
+
gte: "gte";
|
|
25
|
+
lt: "lt";
|
|
26
|
+
lte: "lte";
|
|
27
|
+
contains: "contains";
|
|
28
|
+
}>;
|
|
29
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>]>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export type EventFilter = z.infer<typeof EventFilter>;
|
|
32
|
+
/** At most one message per `key` (a payload field, or the whole rule when absent) every `perMinutes`. */
|
|
33
|
+
export declare const Throttle: z.ZodObject<{
|
|
34
|
+
perMinutes: z.ZodNumber;
|
|
35
|
+
key: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
export type Throttle = z.infer<typeof Throttle>;
|
|
38
|
+
/** Lifecycle of an emitted event row; `ignored` = processed but nothing was sent (see its error). */
|
|
39
|
+
export declare const EVENT_STATUSES: readonly ["pending", "processing", "done", "failed", "ignored"];
|
|
40
|
+
/** Zod enum of {@link EVENT_STATUSES}. */
|
|
41
|
+
export declare const EventStatus: z.ZodEnum<{
|
|
42
|
+
pending: "pending";
|
|
43
|
+
failed: "failed";
|
|
44
|
+
done: "done";
|
|
45
|
+
processing: "processing";
|
|
46
|
+
ignored: "ignored";
|
|
47
|
+
}>;
|
|
48
|
+
export type EventStatus = z.infer<typeof EventStatus>;
|
|
49
|
+
/** A rule that turns a host event into messages (`/admin/event-rules`, permission `telegram.events.manage`). */
|
|
50
|
+
export declare const EventRuleDto: z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
event: z.ZodString;
|
|
53
|
+
name: z.ZodString;
|
|
54
|
+
filters: z.ZodArray<z.ZodObject<{
|
|
55
|
+
field: z.ZodString;
|
|
56
|
+
op: z.ZodEnum<{
|
|
57
|
+
in: "in";
|
|
58
|
+
eq: "eq";
|
|
59
|
+
ne: "ne";
|
|
60
|
+
gt: "gt";
|
|
61
|
+
gte: "gte";
|
|
62
|
+
lt: "lt";
|
|
63
|
+
lte: "lte";
|
|
64
|
+
contains: "contains";
|
|
65
|
+
}>;
|
|
66
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>]>;
|
|
67
|
+
}, z.core.$strip>>;
|
|
68
|
+
templateId: z.ZodString;
|
|
69
|
+
recipients: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
70
|
+
destination: z.ZodString;
|
|
71
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
72
|
+
chat: z.ZodString;
|
|
73
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
74
|
+
user: z.ZodString;
|
|
75
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
76
|
+
role: z.ZodString;
|
|
77
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
78
|
+
allLinked: z.ZodLiteral<true>;
|
|
79
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
80
|
+
audience: z.ZodString;
|
|
81
|
+
ref: z.ZodString;
|
|
82
|
+
}, z.core.$strict>]>>;
|
|
83
|
+
throttle: z.ZodNullable<z.ZodObject<{
|
|
84
|
+
perMinutes: z.ZodNumber;
|
|
85
|
+
key: z.ZodOptional<z.ZodString>;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
enabled: z.ZodBoolean;
|
|
88
|
+
createdBy: z.ZodNullable<z.ZodString>;
|
|
89
|
+
updatedAt: z.ZodNumber;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
export type EventRuleDto = z.infer<typeof EventRuleDto>;
|
|
92
|
+
/** `POST`/`PUT /admin/event-rules` body (defaults: no filters, no throttle, enabled). */
|
|
93
|
+
export declare const EventRuleSave: z.ZodObject<{
|
|
94
|
+
event: z.ZodString;
|
|
95
|
+
name: z.ZodString;
|
|
96
|
+
filters: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
97
|
+
field: z.ZodString;
|
|
98
|
+
op: z.ZodEnum<{
|
|
99
|
+
in: "in";
|
|
100
|
+
eq: "eq";
|
|
101
|
+
ne: "ne";
|
|
102
|
+
gt: "gt";
|
|
103
|
+
gte: "gte";
|
|
104
|
+
lt: "lt";
|
|
105
|
+
lte: "lte";
|
|
106
|
+
contains: "contains";
|
|
107
|
+
}>;
|
|
108
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>]>;
|
|
109
|
+
}, z.core.$strip>>>;
|
|
110
|
+
templateId: z.ZodString;
|
|
111
|
+
recipients: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
112
|
+
destination: z.ZodString;
|
|
113
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
114
|
+
chat: z.ZodString;
|
|
115
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
116
|
+
user: z.ZodString;
|
|
117
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
118
|
+
role: z.ZodString;
|
|
119
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
120
|
+
allLinked: z.ZodLiteral<true>;
|
|
121
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
122
|
+
audience: z.ZodString;
|
|
123
|
+
ref: z.ZodString;
|
|
124
|
+
}, z.core.$strict>]>>;
|
|
125
|
+
throttle: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
126
|
+
perMinutes: z.ZodNumber;
|
|
127
|
+
key: z.ZodOptional<z.ZodString>;
|
|
128
|
+
}, z.core.$strip>>>;
|
|
129
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
130
|
+
}, z.core.$strip>;
|
|
131
|
+
export type EventRuleSave = z.infer<typeof EventRuleSave>;
|
|
132
|
+
/** A host-registered event, as listed by `GET /admin/events`. */
|
|
133
|
+
export declare const RegisteredEventDto: z.ZodObject<{
|
|
134
|
+
key: z.ZodString;
|
|
135
|
+
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
136
|
+
filterable: z.ZodArray<z.ZodString>;
|
|
137
|
+
sensitive: z.ZodArray<z.ZodString>;
|
|
138
|
+
provider: z.ZodNullable<z.ZodString>;
|
|
139
|
+
payloadSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
140
|
+
}, z.core.$strip>;
|
|
141
|
+
export type RegisteredEventDto = z.infer<typeof RegisteredEventDto>;
|
|
142
|
+
/** `GET /admin/event-rules?event=`. */
|
|
143
|
+
export declare const EventRuleQuery: z.ZodObject<{
|
|
144
|
+
event: z.ZodOptional<z.ZodString>;
|
|
145
|
+
}, z.core.$strip>;
|
|
146
|
+
export type EventRuleQuery = z.infer<typeof EventRuleQuery>;
|
|
147
|
+
/** `POST /admin/event-rules/:id/test`: a sample payload, validated by the event's schema. */
|
|
148
|
+
export declare const EventRuleTestRequest: z.ZodObject<{
|
|
149
|
+
payload: z.ZodUnknown;
|
|
150
|
+
}, z.core.$strip>;
|
|
151
|
+
export type EventRuleTestRequest = z.infer<typeof EventRuleTestRequest>;
|
|
152
|
+
/** What a rule test queued to the caller's own private chats, and how it rendered for the caller. */
|
|
153
|
+
export declare const EventRuleTestResult: z.ZodObject<{
|
|
154
|
+
filtersMatch: z.ZodBoolean;
|
|
155
|
+
chats: z.ZodNumber;
|
|
156
|
+
deliveries: z.ZodNumber;
|
|
157
|
+
parts: z.ZodArray<z.ZodString>;
|
|
158
|
+
warnings: z.ZodArray<z.ZodObject<{
|
|
159
|
+
line: z.ZodNumber;
|
|
160
|
+
column: z.ZodNumber;
|
|
161
|
+
message: z.ZodString;
|
|
162
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
163
|
+
}, z.core.$strip>>;
|
|
164
|
+
}, z.core.$strip>;
|
|
165
|
+
export type EventRuleTestResult = z.infer<typeof EventRuleTestResult>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { EpochMs, Id, Key, LocalizedText } from "./common.js";
|
|
2
|
+
import { Recipients } from "./recipients.js";
|
|
3
|
+
import { TemplateError } from "./problems.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// src/contracts/events.ts
|
|
6
|
+
/** Comparison operators for {@link EventFilter}. */
|
|
7
|
+
const FILTER_OPS = [
|
|
8
|
+
"eq",
|
|
9
|
+
"ne",
|
|
10
|
+
"gt",
|
|
11
|
+
"gte",
|
|
12
|
+
"lt",
|
|
13
|
+
"lte",
|
|
14
|
+
"in",
|
|
15
|
+
"contains"
|
|
16
|
+
];
|
|
17
|
+
/** Zod enum of {@link FILTER_OPS}. */
|
|
18
|
+
const FilterOp = z.enum(FILTER_OPS);
|
|
19
|
+
const FilterValue = z.union([
|
|
20
|
+
z.string(),
|
|
21
|
+
z.number(),
|
|
22
|
+
z.boolean(),
|
|
23
|
+
z.array(z.union([z.string(), z.number()]))
|
|
24
|
+
]);
|
|
25
|
+
/** One condition on an event payload field (only fields the event marks `filterable`). All conditions must hold. */
|
|
26
|
+
const EventFilter = z.object({
|
|
27
|
+
field: z.string().min(1).max(64),
|
|
28
|
+
op: FilterOp,
|
|
29
|
+
value: FilterValue
|
|
30
|
+
});
|
|
31
|
+
/** At most one message per `key` (a payload field, or the whole rule when absent) every `perMinutes`. */
|
|
32
|
+
const Throttle = z.object({
|
|
33
|
+
perMinutes: z.number().int().min(1).max(10080),
|
|
34
|
+
key: z.string().max(64).optional()
|
|
35
|
+
});
|
|
36
|
+
/** Lifecycle of an emitted event row; `ignored` = processed but nothing was sent (see its error). */
|
|
37
|
+
const EVENT_STATUSES = [
|
|
38
|
+
"pending",
|
|
39
|
+
"processing",
|
|
40
|
+
"done",
|
|
41
|
+
"failed",
|
|
42
|
+
"ignored"
|
|
43
|
+
];
|
|
44
|
+
/** Zod enum of {@link EVENT_STATUSES}. */
|
|
45
|
+
const EventStatus = z.enum(EVENT_STATUSES);
|
|
46
|
+
/** A rule that turns a host event into messages (`/admin/event-rules`, permission `telegram.events.manage`). */
|
|
47
|
+
const EventRuleDto = z.object({
|
|
48
|
+
id: Id,
|
|
49
|
+
event: Key,
|
|
50
|
+
name: z.string(),
|
|
51
|
+
filters: z.array(EventFilter),
|
|
52
|
+
templateId: Id,
|
|
53
|
+
recipients: Recipients,
|
|
54
|
+
throttle: Throttle.nullable(),
|
|
55
|
+
enabled: z.boolean(),
|
|
56
|
+
createdBy: z.string().nullable(),
|
|
57
|
+
updatedAt: EpochMs
|
|
58
|
+
});
|
|
59
|
+
/** `POST`/`PUT /admin/event-rules` body (defaults: no filters, no throttle, enabled). */
|
|
60
|
+
const EventRuleSave = z.object({
|
|
61
|
+
event: Key,
|
|
62
|
+
name: z.string().trim().min(1).max(120),
|
|
63
|
+
filters: z.array(EventFilter).max(10).default([]),
|
|
64
|
+
templateId: Id,
|
|
65
|
+
recipients: Recipients,
|
|
66
|
+
throttle: Throttle.nullable().default(null),
|
|
67
|
+
enabled: z.boolean().default(true)
|
|
68
|
+
});
|
|
69
|
+
/** A host-registered event, as listed by `GET /admin/events`. */
|
|
70
|
+
const RegisteredEventDto = z.object({
|
|
71
|
+
key: Key,
|
|
72
|
+
label: LocalizedText,
|
|
73
|
+
/** Payload fields rules may filter on. */
|
|
74
|
+
filterable: z.array(z.string()),
|
|
75
|
+
/** Payload fields hidden from audiences without the event's `sensitivePermission`. */
|
|
76
|
+
sensitive: z.array(z.string()),
|
|
77
|
+
/** Provider that supplies extra template data, or null. */
|
|
78
|
+
provider: Key.nullable(),
|
|
79
|
+
/** JSON Schema of the event payload. */
|
|
80
|
+
payloadSchema: z.record(z.string(), z.unknown())
|
|
81
|
+
});
|
|
82
|
+
/** `GET /admin/event-rules?event=`. */
|
|
83
|
+
const EventRuleQuery = z.object({ event: Key.optional() });
|
|
84
|
+
/** `POST /admin/event-rules/:id/test`: a sample payload, validated by the event's schema. */
|
|
85
|
+
const EventRuleTestRequest = z.object({ payload: z.unknown() });
|
|
86
|
+
/** What a rule test queued to the caller's own private chats, and how it rendered for the caller. */
|
|
87
|
+
const EventRuleTestResult = z.object({
|
|
88
|
+
/** Whether the sample payload passes the rule's filters (the test sends either way). */
|
|
89
|
+
filtersMatch: z.boolean(),
|
|
90
|
+
/** Chats that got messages (the caller's linked private chats). */
|
|
91
|
+
chats: z.number().int().nonnegative(),
|
|
92
|
+
/** Delivery rows queued (parts × chats). */
|
|
93
|
+
deliveries: z.number().int().nonnegative(),
|
|
94
|
+
/** Telegram HTML as the caller sees it, one entry per part. */
|
|
95
|
+
parts: z.array(z.string()),
|
|
96
|
+
warnings: z.array(TemplateError)
|
|
97
|
+
});
|
|
98
|
+
export { EVENT_STATUSES, EventFilter, EventRuleDto, EventRuleQuery, EventRuleSave, EventRuleTestRequest, EventRuleTestResult, EventStatus, FILTER_OPS, FilterOp, RegisteredEventDto, Throttle };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Feature modules (docs/01 §3). `core` is always on. */
|
|
3
|
+
export declare const FEATURE_KEYS: readonly ["core", "commands", "templates", "schedules", "reports", "events", "broadcasts", "actions", "dialogs", "inbound", "subscriptions", "ai", "ops"];
|
|
4
|
+
/** Zod enum of {@link FEATURE_KEYS}. */
|
|
5
|
+
export declare const FeatureKey: z.ZodEnum<{
|
|
6
|
+
core: "core";
|
|
7
|
+
commands: "commands";
|
|
8
|
+
templates: "templates";
|
|
9
|
+
schedules: "schedules";
|
|
10
|
+
reports: "reports";
|
|
11
|
+
events: "events";
|
|
12
|
+
broadcasts: "broadcasts";
|
|
13
|
+
actions: "actions";
|
|
14
|
+
dialogs: "dialogs";
|
|
15
|
+
inbound: "inbound";
|
|
16
|
+
subscriptions: "subscriptions";
|
|
17
|
+
ai: "ai";
|
|
18
|
+
ops: "ops";
|
|
19
|
+
}>;
|
|
20
|
+
export type FeatureKey = z.infer<typeof FeatureKey>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// src/contracts/features.ts
|
|
3
|
+
/** Feature modules (docs/01 §3). `core` is always on. */
|
|
4
|
+
const FEATURE_KEYS = [
|
|
5
|
+
"core",
|
|
6
|
+
"commands",
|
|
7
|
+
"templates",
|
|
8
|
+
"schedules",
|
|
9
|
+
"reports",
|
|
10
|
+
"events",
|
|
11
|
+
"broadcasts",
|
|
12
|
+
"actions",
|
|
13
|
+
"dialogs",
|
|
14
|
+
"inbound",
|
|
15
|
+
"subscriptions",
|
|
16
|
+
"ai",
|
|
17
|
+
"ops"
|
|
18
|
+
];
|
|
19
|
+
/** Zod enum of {@link FEATURE_KEYS}. */
|
|
20
|
+
const FeatureKey = z.enum(FEATURE_KEYS);
|
|
21
|
+
export { FEATURE_KEYS, FeatureKey };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** `GET /admin/health` (permission `telegram.ops.view`): tick freshness, outbox backlog, stuck schedule runs, bots, keyring and schema state. */
|
|
3
|
+
export declare const HealthDto: z.ZodObject<{
|
|
4
|
+
ok: z.ZodBoolean;
|
|
5
|
+
lastTickAt: z.ZodNullable<z.ZodNumber>;
|
|
6
|
+
tickStale: z.ZodBoolean;
|
|
7
|
+
deliveries: z.ZodObject<{
|
|
8
|
+
queued: z.ZodNumber;
|
|
9
|
+
failed24h: z.ZodNumber;
|
|
10
|
+
oldestQueuedAgeMs: z.ZodNullable<z.ZodNumber>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
schedules: z.ZodObject<{
|
|
13
|
+
stuckRuns: z.ZodNumber;
|
|
14
|
+
runStuckFailed24h: z.ZodNumber;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
bots: z.ZodArray<z.ZodObject<{
|
|
17
|
+
id: z.ZodString;
|
|
18
|
+
username: z.ZodString;
|
|
19
|
+
status: z.ZodEnum<{
|
|
20
|
+
active: "active";
|
|
21
|
+
disabled: "disabled";
|
|
22
|
+
invalid_token: "invalid_token";
|
|
23
|
+
webhook_error: "webhook_error";
|
|
24
|
+
}>;
|
|
25
|
+
pendingUpdateCount: z.ZodNullable<z.ZodNumber>;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
keyring: z.ZodObject<{
|
|
28
|
+
activeKid: z.ZodNullable<z.ZodString>;
|
|
29
|
+
rowsByKid: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
schema: z.ZodObject<{
|
|
32
|
+
required: z.ZodNumber;
|
|
33
|
+
current: z.ZodNullable<z.ZodNumber>;
|
|
34
|
+
ok: z.ZodBoolean;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
export type HealthDto = z.infer<typeof HealthDto>;
|
|
38
|
+
/** `GET /admin/stats?from=&to=`: window in epoch ms UTC, `[from, to)`. */
|
|
39
|
+
export declare const StatsQuery: z.ZodObject<{
|
|
40
|
+
from: z.ZodCoercedNumber<unknown>;
|
|
41
|
+
to: z.ZodCoercedNumber<unknown>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
export type StatsQuery = z.infer<typeof StatsQuery>;
|
|
44
|
+
/** Delivery counts in `[from, to)`. `rateLimited` = deliveries whose last error was a 429; `updates` = inbound updates. */
|
|
45
|
+
export declare const StatsDto: z.ZodObject<{
|
|
46
|
+
from: z.ZodNumber;
|
|
47
|
+
to: z.ZodNumber;
|
|
48
|
+
sent: z.ZodNumber;
|
|
49
|
+
failed: z.ZodNumber;
|
|
50
|
+
dropped: z.ZodNumber;
|
|
51
|
+
rateLimited: z.ZodNumber;
|
|
52
|
+
bySource: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
53
|
+
updates: z.ZodNumber;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export type StatsDto = z.infer<typeof StatsDto>;
|