@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,58 @@
|
|
|
1
|
+
import { EpochMs, Id } from "./common.js";
|
|
2
|
+
import { BotStatus } from "./bots.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// src/contracts/health.ts
|
|
5
|
+
/** `GET /admin/health` (permission `telegram.ops.view`): tick freshness, outbox backlog, stuck schedule runs, bots, keyring and schema state. */
|
|
6
|
+
const HealthDto = z.object({
|
|
7
|
+
ok: z.boolean(),
|
|
8
|
+
/** Last cron/DO tick (epoch ms UTC), or null. */
|
|
9
|
+
lastTickAt: EpochMs.nullable(),
|
|
10
|
+
/** True when the last tick is older than 5 minutes. */
|
|
11
|
+
tickStale: z.boolean(),
|
|
12
|
+
deliveries: z.object({
|
|
13
|
+
queued: z.number().int().nonnegative(),
|
|
14
|
+
failed24h: z.number().int().nonnegative(),
|
|
15
|
+
oldestQueuedAgeMs: z.number().int().nonnegative().nullable()
|
|
16
|
+
}),
|
|
17
|
+
/** Schedule runs that need attention (the tick resumes stuck runs, then fails them with `run_stuck`). */
|
|
18
|
+
schedules: z.object({
|
|
19
|
+
/** Runs still `running` after `STUCK_RUN_MS` (10 min). */
|
|
20
|
+
stuckRuns: z.number().int().nonnegative(),
|
|
21
|
+
/** Runs marked `failed` with `run_stuck` in the last 24 h. */
|
|
22
|
+
runStuckFailed24h: z.number().int().nonnegative()
|
|
23
|
+
}),
|
|
24
|
+
bots: z.array(z.object({
|
|
25
|
+
id: Id,
|
|
26
|
+
username: z.string(),
|
|
27
|
+
status: BotStatus,
|
|
28
|
+
pendingUpdateCount: z.number().int().nonnegative().nullable()
|
|
29
|
+
})),
|
|
30
|
+
/** Active key id and encrypted row counts per key id (for rekey progress). */
|
|
31
|
+
keyring: z.object({
|
|
32
|
+
activeKid: z.string().nullable(),
|
|
33
|
+
rowsByKid: z.record(z.string(), z.number().int())
|
|
34
|
+
}),
|
|
35
|
+
/** Required vs applied plugin schema version. */
|
|
36
|
+
schema: z.object({
|
|
37
|
+
required: z.number().int(),
|
|
38
|
+
current: z.number().int().nullable(),
|
|
39
|
+
ok: z.boolean()
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
/** `GET /admin/stats?from=&to=`: window in epoch ms UTC, `[from, to)`. */
|
|
43
|
+
const StatsQuery = z.object({
|
|
44
|
+
from: z.coerce.number().int(),
|
|
45
|
+
to: z.coerce.number().int()
|
|
46
|
+
});
|
|
47
|
+
/** Delivery counts in `[from, to)`. `rateLimited` = deliveries whose last error was a 429; `updates` = inbound updates. */
|
|
48
|
+
const StatsDto = z.object({
|
|
49
|
+
from: EpochMs,
|
|
50
|
+
to: EpochMs,
|
|
51
|
+
sent: z.number().int().nonnegative(),
|
|
52
|
+
failed: z.number().int().nonnegative(),
|
|
53
|
+
dropped: z.number().int().nonnegative(),
|
|
54
|
+
rateLimited: z.number().int().nonnegative(),
|
|
55
|
+
bySource: z.record(z.string(), z.number().int().nonnegative()),
|
|
56
|
+
updates: z.number().int().nonnegative()
|
|
57
|
+
});
|
|
58
|
+
export { HealthDto, StatsDto, StatsQuery };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BOT_MODES, BOT_STATUSES, BotCreate, BotDto, BotFeatures, BotMode, BotPatch, BotRotateToken, BotStatus, BotTestResult, BotToken } from "./bots.js";
|
|
2
|
+
import { BROADCAST_STATUSES, BroadcastDto, BroadcastPreviewRequest, BroadcastQuery, BroadcastSave, BroadcastStats, BroadcastStatus, FileRef } from "./broadcasts.js";
|
|
3
|
+
import { Audience, CHAT_KINDS, CHAT_STATUSES, ChatDto, ChatKind, ChatPatch, ChatQuery, ChatStatus, ChatTopics } from "./chats.js";
|
|
4
|
+
import { BUILTIN_COMMANDS, BuiltinCommand, CommandConfigDto, CommandConfigSave, CommandName, CommandSyncResult } from "./commands.js";
|
|
5
|
+
import { ClockTime, EpochMs, Id, JsonObject, Key, Locale, LocalizedText, Page, PageQuery, TelegramChatId, TimeZone, page } from "./common.js";
|
|
6
|
+
import { DELIVERY_KINDS, DELIVERY_SOURCES, DELIVERY_STATUSES, DeliveryDto, DeliveryKind, DeliveryQuery, DeliverySource, DeliveryStatus } from "./deliveries.js";
|
|
7
|
+
import { DestinationDto, DestinationSave, Slug } from "./destinations.js";
|
|
8
|
+
import { EVENT_STATUSES, EventFilter, EventRuleDto, EventRuleQuery, EventRuleSave, EventRuleTestRequest, EventRuleTestResult, EventStatus, FILTER_OPS, FilterOp, RegisteredEventDto, Throttle } from "./events.js";
|
|
9
|
+
import { FEATURE_KEYS, FeatureKey } from "./features.js";
|
|
10
|
+
import { HealthDto, StatsDto, StatsQuery } from "./health.js";
|
|
11
|
+
import { LABELLED_ENUMS, LabelGroup, labelKey } from "./labels.js";
|
|
12
|
+
import { LINK_PURPOSES, LinkCreate, LinkPurpose, LinkResult, PendingLinkDto, SelfLinkCreate } from "./links.js";
|
|
13
|
+
import { JsonSchema, MetaAction, MetaAudience, MetaCommand, MetaDialog, MetaEvent, MetaFilter, MetaProvider, PluginMeta } from "./meta.js";
|
|
14
|
+
import { PERMISSION_NAMES, PermissionName, permissionName } from "./permissions.js";
|
|
15
|
+
import { FieldIssue, PROBLEM_CONTENT_TYPE, PROBLEM_STATUS, TELEGRAM_PROBLEM_CODES, TelegramProblem, TelegramProblemCode, TemplateError } from "./problems.js";
|
|
16
|
+
import { RecipientSpec, Recipients } from "./recipients.js";
|
|
17
|
+
import { CronExpr, LocalDateTime, MISSED_POLICIES, MissedPolicy, NextRunsRequest, NextRunsResponse, PAUSED_INDEFINITELY, SCHEDULE_RULE_KINDS, SCHEDULE_RUN_STATUSES, SCHEDULE_RUN_TRIGGERS, ScheduleDto, SchedulePause, ScheduleRule, ScheduleRuleKind, ScheduleRunDto, ScheduleRunStatus, ScheduleRunTrigger, ScheduleSave, WEEKDAYS, Weekday } from "./schedules.js";
|
|
18
|
+
import { SendIntent, SendPreview, SendResult, SendTarget, SendWhat } from "./send.js";
|
|
19
|
+
import { QuietHours, SubscriptionDto, SubscriptionSave, SubscriptionTopic } from "./subscriptions.js";
|
|
20
|
+
import { BUTTON_STYLES, ButtonRows, ButtonSpec, ButtonStyle, PreviewAs, PreviewButton, PreviewFile, REPORT_COLUMN_FORMATS, REPORT_FORMATS, ReportColumn, ReportColumnFormat, ReportFormat, ReportLayout, ReportRenderRequest, ReportSpec, TEMPLATE_FORMATS, TEMPLATE_KINDS, TemplateDto, TemplateFormat, TemplateKind, TemplateOptions, TemplatePreviewRequest, TemplatePreviewResponse, TemplateQuery, TemplateSave, TemplateVersionDto } from "./templates.js";
|
|
21
|
+
import { UserDto, UserQuery } from "./users.js";
|
|
22
|
+
export { Audience, BOT_MODES, BOT_STATUSES, BROADCAST_STATUSES, BUILTIN_COMMANDS, BUTTON_STYLES, BotCreate, BotDto, BotFeatures, BotMode, BotPatch, BotRotateToken, BotStatus, BotTestResult, BotToken, BroadcastDto, BroadcastPreviewRequest, BroadcastQuery, BroadcastSave, BroadcastStats, BroadcastStatus, BuiltinCommand, ButtonRows, ButtonSpec, ButtonStyle, CHAT_KINDS, CHAT_STATUSES, ChatDto, ChatKind, ChatPatch, ChatQuery, ChatStatus, ChatTopics, ClockTime, CommandConfigDto, CommandConfigSave, CommandName, CommandSyncResult, CronExpr, DELIVERY_KINDS, DELIVERY_SOURCES, DELIVERY_STATUSES, DeliveryDto, DeliveryKind, DeliveryQuery, DeliverySource, DeliveryStatus, DestinationDto, DestinationSave, EVENT_STATUSES, EpochMs, EventFilter, EventRuleDto, EventRuleQuery, EventRuleSave, EventRuleTestRequest, EventRuleTestResult, EventStatus, FEATURE_KEYS, FILTER_OPS, FeatureKey, FieldIssue, FileRef, FilterOp, HealthDto, Id, JsonObject, JsonSchema, Key, LABELLED_ENUMS, LINK_PURPOSES, LabelGroup, LinkCreate, LinkPurpose, LinkResult, LocalDateTime, Locale, LocalizedText, MISSED_POLICIES, MetaAction, MetaAudience, MetaCommand, MetaDialog, MetaEvent, MetaFilter, MetaProvider, MissedPolicy, NextRunsRequest, NextRunsResponse, PAUSED_INDEFINITELY, PERMISSION_NAMES, PROBLEM_CONTENT_TYPE, PROBLEM_STATUS, Page, PageQuery, PendingLinkDto, PermissionName, PluginMeta, PreviewAs, PreviewButton, PreviewFile, QuietHours, REPORT_COLUMN_FORMATS, REPORT_FORMATS, RecipientSpec, Recipients, RegisteredEventDto, ReportColumn, ReportColumnFormat, ReportFormat, ReportLayout, ReportRenderRequest, ReportSpec, SCHEDULE_RULE_KINDS, SCHEDULE_RUN_STATUSES, SCHEDULE_RUN_TRIGGERS, ScheduleDto, SchedulePause, ScheduleRule, ScheduleRuleKind, ScheduleRunDto, ScheduleRunStatus, ScheduleRunTrigger, ScheduleSave, SelfLinkCreate, SendIntent, SendPreview, SendResult, SendTarget, SendWhat, Slug, StatsDto, StatsQuery, SubscriptionDto, SubscriptionSave, SubscriptionTopic, TELEGRAM_PROBLEM_CODES, TEMPLATE_FORMATS, TEMPLATE_KINDS, TelegramChatId, TelegramProblem, TelegramProblemCode, TemplateDto, TemplateError, TemplateFormat, TemplateKind, TemplateOptions, TemplatePreviewRequest, TemplatePreviewResponse, TemplateQuery, TemplateSave, TemplateVersionDto, Throttle, TimeZone, UserDto, UserQuery, WEEKDAYS, Weekday, labelKey, page, permissionName };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClockTime, EpochMs, Id, JsonObject, Key, Locale, LocalizedText, PageQuery, TelegramChatId, TimeZone, page } from "./common.js";
|
|
2
|
+
import { FEATURE_KEYS, FeatureKey } from "./features.js";
|
|
3
|
+
import { BOT_MODES, BOT_STATUSES, BotCreate, BotDto, BotFeatures, BotMode, BotPatch, BotRotateToken, BotStatus, BotTestResult, BotToken } from "./bots.js";
|
|
4
|
+
import { DestinationDto, DestinationSave, Slug } from "./destinations.js";
|
|
5
|
+
import { RecipientSpec, Recipients } from "./recipients.js";
|
|
6
|
+
import { FieldIssue, PROBLEM_CONTENT_TYPE, PROBLEM_STATUS, TELEGRAM_PROBLEM_CODES, TelegramProblem, TelegramProblemCode, TemplateError } from "./problems.js";
|
|
7
|
+
import { BUTTON_STYLES, ButtonRows, ButtonSpec, ButtonStyle, PreviewAs, PreviewButton, PreviewFile, REPORT_COLUMN_FORMATS, REPORT_FORMATS, ReportColumn, ReportColumnFormat, ReportFormat, ReportLayout, ReportRenderRequest, ReportSpec, TEMPLATE_FORMATS, TEMPLATE_KINDS, TemplateDto, TemplateFormat, TemplateKind, TemplateOptions, TemplatePreviewRequest, TemplatePreviewResponse, TemplateQuery, TemplateSave, TemplateVersionDto } from "./templates.js";
|
|
8
|
+
import { BROADCAST_STATUSES, BroadcastDto, BroadcastPreviewRequest, BroadcastQuery, BroadcastSave, BroadcastStats, BroadcastStatus, FileRef } from "./broadcasts.js";
|
|
9
|
+
import { Audience, CHAT_KINDS, CHAT_STATUSES, ChatDto, ChatKind, ChatPatch, ChatQuery, ChatStatus, ChatTopics } from "./chats.js";
|
|
10
|
+
import { BUILTIN_COMMANDS, BuiltinCommand, CommandConfigDto, CommandConfigSave, CommandName, CommandSyncResult } from "./commands.js";
|
|
11
|
+
import { DELIVERY_KINDS, DELIVERY_SOURCES, DELIVERY_STATUSES, DeliveryDto, DeliveryKind, DeliveryQuery, DeliverySource, DeliveryStatus } from "./deliveries.js";
|
|
12
|
+
import { EVENT_STATUSES, EventFilter, EventRuleDto, EventRuleQuery, EventRuleSave, EventRuleTestRequest, EventRuleTestResult, EventStatus, FILTER_OPS, FilterOp, RegisteredEventDto, Throttle } from "./events.js";
|
|
13
|
+
import { HealthDto, StatsDto, StatsQuery } from "./health.js";
|
|
14
|
+
import { LINK_PURPOSES, LinkCreate, LinkPurpose, LinkResult, PendingLinkDto, SelfLinkCreate } from "./links.js";
|
|
15
|
+
import { PERMISSION_NAMES, PermissionName, permissionName } from "./permissions.js";
|
|
16
|
+
import { CronExpr, LocalDateTime, MISSED_POLICIES, MissedPolicy, NextRunsRequest, NextRunsResponse, PAUSED_INDEFINITELY, SCHEDULE_RULE_KINDS, SCHEDULE_RUN_STATUSES, SCHEDULE_RUN_TRIGGERS, ScheduleDto, SchedulePause, ScheduleRule, ScheduleRuleKind, ScheduleRunDto, ScheduleRunStatus, ScheduleRunTrigger, ScheduleSave, WEEKDAYS, Weekday } from "./schedules.js";
|
|
17
|
+
import { LABELLED_ENUMS, labelKey } from "./labels.js";
|
|
18
|
+
import { JsonSchema, MetaAction, MetaAudience, MetaCommand, MetaDialog, MetaEvent, MetaFilter, MetaProvider, PluginMeta } from "./meta.js";
|
|
19
|
+
import { SendIntent, SendPreview, SendResult, SendTarget, SendWhat } from "./send.js";
|
|
20
|
+
import { QuietHours, SubscriptionDto, SubscriptionSave, SubscriptionTopic } from "./subscriptions.js";
|
|
21
|
+
import { UserDto, UserQuery } from "./users.js";
|
|
22
|
+
export { Audience, BOT_MODES, BOT_STATUSES, BROADCAST_STATUSES, BUILTIN_COMMANDS, BUTTON_STYLES, BotCreate, BotDto, BotFeatures, BotMode, BotPatch, BotRotateToken, BotStatus, BotTestResult, BotToken, BroadcastDto, BroadcastPreviewRequest, BroadcastQuery, BroadcastSave, BroadcastStats, BroadcastStatus, BuiltinCommand, ButtonRows, ButtonSpec, ButtonStyle, CHAT_KINDS, CHAT_STATUSES, ChatDto, ChatKind, ChatPatch, ChatQuery, ChatStatus, ChatTopics, ClockTime, CommandConfigDto, CommandConfigSave, CommandName, CommandSyncResult, CronExpr, DELIVERY_KINDS, DELIVERY_SOURCES, DELIVERY_STATUSES, DeliveryDto, DeliveryKind, DeliveryQuery, DeliverySource, DeliveryStatus, DestinationDto, DestinationSave, EVENT_STATUSES, EpochMs, EventFilter, EventRuleDto, EventRuleQuery, EventRuleSave, EventRuleTestRequest, EventRuleTestResult, EventStatus, FEATURE_KEYS, FILTER_OPS, FeatureKey, FieldIssue, FileRef, FilterOp, HealthDto, Id, JsonObject, JsonSchema, Key, LABELLED_ENUMS, LINK_PURPOSES, LinkCreate, LinkPurpose, LinkResult, LocalDateTime, Locale, LocalizedText, MISSED_POLICIES, MetaAction, MetaAudience, MetaCommand, MetaDialog, MetaEvent, MetaFilter, MetaProvider, MissedPolicy, NextRunsRequest, NextRunsResponse, PAUSED_INDEFINITELY, PERMISSION_NAMES, PROBLEM_CONTENT_TYPE, PROBLEM_STATUS, PageQuery, PendingLinkDto, PermissionName, PluginMeta, PreviewAs, PreviewButton, PreviewFile, QuietHours, REPORT_COLUMN_FORMATS, REPORT_FORMATS, RecipientSpec, Recipients, RegisteredEventDto, ReportColumn, ReportColumnFormat, ReportFormat, ReportLayout, ReportRenderRequest, ReportSpec, SCHEDULE_RULE_KINDS, SCHEDULE_RUN_STATUSES, SCHEDULE_RUN_TRIGGERS, ScheduleDto, SchedulePause, ScheduleRule, ScheduleRuleKind, ScheduleRunDto, ScheduleRunStatus, ScheduleRunTrigger, ScheduleSave, SelfLinkCreate, SendIntent, SendPreview, SendResult, SendTarget, SendWhat, Slug, StatsDto, StatsQuery, SubscriptionDto, SubscriptionSave, SubscriptionTopic, TELEGRAM_PROBLEM_CODES, TEMPLATE_FORMATS, TEMPLATE_KINDS, TelegramChatId, TelegramProblem, TelegramProblemCode, TemplateDto, TemplateError, TemplateFormat, TemplateKind, TemplateOptions, TemplatePreviewRequest, TemplatePreviewResponse, TemplateQuery, TemplateSave, TemplateVersionDto, Throttle, TimeZone, UserDto, UserQuery, WEEKDAYS, Weekday, labelKey, page, permissionName };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every enum that app UIs show, by label group. Each value has a label in `@prajwalshete/telegram-plugin/locales/{en,mr}.json`
|
|
3
|
+
* at `labelKey(group, value)`, so app UIs need no literal strings.
|
|
4
|
+
*/
|
|
5
|
+
export declare const LABELLED_ENUMS: {
|
|
6
|
+
readonly botMode: readonly ["webhook", "polling"];
|
|
7
|
+
readonly botStatus: readonly ["active", "disabled", "invalid_token", "webhook_error"];
|
|
8
|
+
readonly chatKind: readonly ["private", "group", "supergroup", "channel"];
|
|
9
|
+
readonly chatStatus: readonly ["pending", "active", "blocked", "left", "migrated"];
|
|
10
|
+
readonly linkPurpose: readonly ["user", "group"];
|
|
11
|
+
readonly builtinCommand: readonly ["start", "help", "stop", "settings", "whoami", "language"];
|
|
12
|
+
readonly templateKind: readonly ["message", "report"];
|
|
13
|
+
readonly templateFormat: readonly ["html", "text"];
|
|
14
|
+
readonly reportFormat: readonly ["pdf", "csv"];
|
|
15
|
+
readonly reportColumnFormat: readonly ["text", "number", "money", "date", "datetime", "yesno"];
|
|
16
|
+
readonly buttonStyle: readonly ["primary", "success", "danger"];
|
|
17
|
+
readonly weekday: readonly ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
18
|
+
readonly scheduleRuleKind: readonly ["daily", "weekly", "monthly", "cron", "once"];
|
|
19
|
+
readonly missedPolicy: readonly ["skip", "run_once"];
|
|
20
|
+
readonly scheduleRunStatus: readonly ["running", "done", "partial", "failed", "skipped"];
|
|
21
|
+
readonly scheduleRunTrigger: readonly ["schedule", "manual"];
|
|
22
|
+
readonly filterOp: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "in", "contains"];
|
|
23
|
+
readonly eventStatus: readonly ["pending", "processing", "done", "failed", "ignored"];
|
|
24
|
+
readonly broadcastStatus: readonly ["draft", "queued", "sending", "done"];
|
|
25
|
+
readonly deliverySource: readonly ["schedule", "event", "broadcast", "command", "ai", "api", "system"];
|
|
26
|
+
readonly deliveryKind: readonly ["text", "document", "photo", "edit", "delete"];
|
|
27
|
+
readonly deliveryStatus: readonly ["queued", "sending", "sent", "failed", "dropped", "cancelled"];
|
|
28
|
+
readonly feature: readonly ["core", "commands", "templates", "schedules", "reports", "events", "broadcasts", "actions", "dialogs", "inbound", "subscriptions", "ai", "ops"];
|
|
29
|
+
readonly permission: readonly ["telegram.view", "telegram.bots.manage", "telegram.chats.manage", "telegram.self.link", "telegram.destinations.manage", "telegram.commands.manage", "telegram.templates.manage", "telegram.schedules.manage", "telegram.events.manage", "telegram.broadcasts.send", "telegram.reports.run", "telegram.send", "telegram.ops.view", "telegram.ops.manage", "telegram.ops.content"];
|
|
30
|
+
readonly problem: readonly ["feature_disabled", "bot_token_invalid", "bot_token_mismatch", "bot_unreachable", "webhook_url_missing", "webhook_failed", "chat_not_found", "chat_blocked", "link_expired", "link_used", "destination_not_allowed", "template_invalid", "template_variable_unknown", "provider_unknown", "provider_forbidden", "schedule_rule_invalid", "timezone_invalid", "recipient_empty", "send_text_rejected", "file_too_large", "renderer_unavailable", "delivery_not_retryable", "schema_outdated", "unauthenticated", "forbidden", "not_found", "validation_failed", "rate_limited", "internal_error"];
|
|
31
|
+
};
|
|
32
|
+
/** A key of {@link LABELLED_ENUMS}. */
|
|
33
|
+
export type LabelGroup = keyof typeof LABELLED_ENUMS;
|
|
34
|
+
/**
|
|
35
|
+
* Locale key for an enum value label, for example `labels.botStatus.active`. Dots inside a value become `_`
|
|
36
|
+
* (`telegram.bots.manage` → `labels.permission.telegram_bots_manage`) so the key works with nested lookups.
|
|
37
|
+
*/
|
|
38
|
+
export declare function labelKey<G extends LabelGroup>(group: G, value: (typeof LABELLED_ENUMS)[G][number]): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FEATURE_KEYS } from "./features.js";
|
|
2
|
+
import { BOT_MODES, BOT_STATUSES } from "./bots.js";
|
|
3
|
+
import { TELEGRAM_PROBLEM_CODES } from "./problems.js";
|
|
4
|
+
import { BUTTON_STYLES, REPORT_COLUMN_FORMATS, REPORT_FORMATS, TEMPLATE_FORMATS, TEMPLATE_KINDS } from "./templates.js";
|
|
5
|
+
import { BROADCAST_STATUSES } from "./broadcasts.js";
|
|
6
|
+
import { CHAT_KINDS, CHAT_STATUSES } from "./chats.js";
|
|
7
|
+
import { BUILTIN_COMMANDS } from "./commands.js";
|
|
8
|
+
import { DELIVERY_KINDS, DELIVERY_SOURCES, DELIVERY_STATUSES } from "./deliveries.js";
|
|
9
|
+
import { EVENT_STATUSES, FILTER_OPS } from "./events.js";
|
|
10
|
+
import { LINK_PURPOSES } from "./links.js";
|
|
11
|
+
import { PERMISSION_NAMES } from "./permissions.js";
|
|
12
|
+
import { MISSED_POLICIES, SCHEDULE_RULE_KINDS, SCHEDULE_RUN_STATUSES, SCHEDULE_RUN_TRIGGERS, WEEKDAYS } from "./schedules.js";
|
|
13
|
+
// src/contracts/labels.ts
|
|
14
|
+
/**
|
|
15
|
+
* Every enum that app UIs show, by label group. Each value has a label in `@prajwalshete/telegram-plugin/locales/{en,mr}.json`
|
|
16
|
+
* at `labelKey(group, value)`, so app UIs need no literal strings.
|
|
17
|
+
*/
|
|
18
|
+
const LABELLED_ENUMS = {
|
|
19
|
+
botMode: BOT_MODES,
|
|
20
|
+
botStatus: BOT_STATUSES,
|
|
21
|
+
chatKind: CHAT_KINDS,
|
|
22
|
+
chatStatus: CHAT_STATUSES,
|
|
23
|
+
linkPurpose: LINK_PURPOSES,
|
|
24
|
+
builtinCommand: BUILTIN_COMMANDS,
|
|
25
|
+
templateKind: TEMPLATE_KINDS,
|
|
26
|
+
templateFormat: TEMPLATE_FORMATS,
|
|
27
|
+
reportFormat: REPORT_FORMATS,
|
|
28
|
+
reportColumnFormat: REPORT_COLUMN_FORMATS,
|
|
29
|
+
buttonStyle: BUTTON_STYLES,
|
|
30
|
+
weekday: WEEKDAYS,
|
|
31
|
+
scheduleRuleKind: SCHEDULE_RULE_KINDS,
|
|
32
|
+
missedPolicy: MISSED_POLICIES,
|
|
33
|
+
scheduleRunStatus: SCHEDULE_RUN_STATUSES,
|
|
34
|
+
scheduleRunTrigger: SCHEDULE_RUN_TRIGGERS,
|
|
35
|
+
filterOp: FILTER_OPS,
|
|
36
|
+
eventStatus: EVENT_STATUSES,
|
|
37
|
+
broadcastStatus: BROADCAST_STATUSES,
|
|
38
|
+
deliverySource: DELIVERY_SOURCES,
|
|
39
|
+
deliveryKind: DELIVERY_KINDS,
|
|
40
|
+
deliveryStatus: DELIVERY_STATUSES,
|
|
41
|
+
feature: FEATURE_KEYS,
|
|
42
|
+
permission: PERMISSION_NAMES,
|
|
43
|
+
problem: TELEGRAM_PROBLEM_CODES
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Locale key for an enum value label, for example `labels.botStatus.active`. Dots inside a value become `_`
|
|
47
|
+
* (`telegram.bots.manage` → `labels.permission.telegram_bots_manage`) so the key works with nested lookups.
|
|
48
|
+
*/
|
|
49
|
+
function labelKey(group, value) {
|
|
50
|
+
return `labels.${group}.${value.replaceAll(".", "_")}`;
|
|
51
|
+
}
|
|
52
|
+
export { LABELLED_ENUMS, labelKey };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** What a one-time link code links: a user's private chat, or a group. */
|
|
3
|
+
export declare const LINK_PURPOSES: readonly ["user", "group"];
|
|
4
|
+
/** Zod enum of {@link LINK_PURPOSES}. */
|
|
5
|
+
export declare const LinkPurpose: z.ZodEnum<{
|
|
6
|
+
group: "group";
|
|
7
|
+
user: "user";
|
|
8
|
+
}>;
|
|
9
|
+
export type LinkPurpose = z.infer<typeof LinkPurpose>;
|
|
10
|
+
/** `POST /admin/links`: invite a user, or make a `startgroup` link for a group with an audience. */
|
|
11
|
+
export declare const LinkCreate: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
12
|
+
bot: z.ZodString;
|
|
13
|
+
purpose: z.ZodLiteral<"user">;
|
|
14
|
+
userId: z.ZodString;
|
|
15
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
16
|
+
bot: z.ZodString;
|
|
17
|
+
purpose: z.ZodLiteral<"group">;
|
|
18
|
+
audience: z.ZodUnion<readonly [z.ZodObject<{
|
|
19
|
+
role: z.ZodString;
|
|
20
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
21
|
+
users: z.ZodArray<z.ZodString>;
|
|
22
|
+
}, z.core.$strict>]>;
|
|
23
|
+
}, z.core.$strip>], "purpose">;
|
|
24
|
+
export type LinkCreate = z.infer<typeof LinkCreate>;
|
|
25
|
+
/** `POST /me/link`: link the caller's own Telegram. */
|
|
26
|
+
export declare const SelfLinkCreate: z.ZodObject<{
|
|
27
|
+
bot: z.ZodString;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
export type SelfLinkCreate = z.infer<typeof SelfLinkCreate>;
|
|
30
|
+
/** The one-time link. The code inside `url` is shown once and never stored in plain text. */
|
|
31
|
+
export declare const LinkResult: z.ZodObject<{
|
|
32
|
+
url: z.ZodURL;
|
|
33
|
+
qrPayload: z.ZodString;
|
|
34
|
+
expiresAt: z.ZodNumber;
|
|
35
|
+
requiresConfirmation: z.ZodBoolean;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
export type LinkResult = z.infer<typeof LinkResult>;
|
|
38
|
+
/**
|
|
39
|
+
* `GET /me/links/pending`: a Telegram account that redeemed an admin invite for the caller and waits for the
|
|
40
|
+
* caller's confirmation. Confirm only when the Telegram account is yours.
|
|
41
|
+
*/
|
|
42
|
+
export declare const PendingLinkDto: z.ZodObject<{
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
bot: z.ZodString;
|
|
45
|
+
telegramName: z.ZodNullable<z.ZodString>;
|
|
46
|
+
telegramUsername: z.ZodNullable<z.ZodString>;
|
|
47
|
+
invitedBy: z.ZodNullable<z.ZodString>;
|
|
48
|
+
createdAt: z.ZodNumber;
|
|
49
|
+
expiresAt: z.ZodNumber;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
export type PendingLinkDto = z.infer<typeof PendingLinkDto>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { EpochMs, Id } from "./common.js";
|
|
2
|
+
import { Audience } from "./chats.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// src/contracts/links.ts
|
|
5
|
+
/** What a one-time link code links: a user's private chat, or a group. */
|
|
6
|
+
const LINK_PURPOSES = ["user", "group"];
|
|
7
|
+
/** Zod enum of {@link LINK_PURPOSES}. */
|
|
8
|
+
const LinkPurpose = z.enum(LINK_PURPOSES);
|
|
9
|
+
/** `POST /admin/links`: invite a user, or make a `startgroup` link for a group with an audience. */
|
|
10
|
+
const LinkCreate = z.discriminatedUnion("purpose", [z.object({
|
|
11
|
+
bot: Id,
|
|
12
|
+
purpose: z.literal("user"),
|
|
13
|
+
userId: z.string().min(1)
|
|
14
|
+
}), z.object({
|
|
15
|
+
bot: Id,
|
|
16
|
+
purpose: z.literal("group"),
|
|
17
|
+
audience: Audience
|
|
18
|
+
})]);
|
|
19
|
+
/** `POST /me/link`: link the caller's own Telegram. */
|
|
20
|
+
const SelfLinkCreate = z.object({ bot: Id });
|
|
21
|
+
/** The one-time link. The code inside `url` is shown once and never stored in plain text. */
|
|
22
|
+
const LinkResult = z.object({
|
|
23
|
+
url: z.url(),
|
|
24
|
+
/** Text to encode in a QR code (same deep link as `url`). */
|
|
25
|
+
qrPayload: z.string(),
|
|
26
|
+
/** Code expiry (epoch ms UTC). */
|
|
27
|
+
expiresAt: EpochMs,
|
|
28
|
+
/**
|
|
29
|
+
* True for an admin invite for another user: redeeming it in Telegram does not link yet; the invited user
|
|
30
|
+
* confirms it in the app (`GET /me/links/pending`, `POST /me/links/pending/:id/confirm`).
|
|
31
|
+
*/
|
|
32
|
+
requiresConfirmation: z.boolean()
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* `GET /me/links/pending`: a Telegram account that redeemed an admin invite for the caller and waits for the
|
|
36
|
+
* caller's confirmation. Confirm only when the Telegram account is yours.
|
|
37
|
+
*/
|
|
38
|
+
const PendingLinkDto = z.object({
|
|
39
|
+
id: z.string(),
|
|
40
|
+
bot: Id,
|
|
41
|
+
/** Telegram display name of the account that used the invite. */
|
|
42
|
+
telegramName: z.string().nullable(),
|
|
43
|
+
/** Telegram @username (without @), if any. */
|
|
44
|
+
telegramUsername: z.string().nullable(),
|
|
45
|
+
/** App user who made the invite, or null (an API key / system actor). */
|
|
46
|
+
invitedBy: z.string().nullable(),
|
|
47
|
+
createdAt: EpochMs,
|
|
48
|
+
expiresAt: EpochMs
|
|
49
|
+
});
|
|
50
|
+
export { LINK_PURPOSES, LinkCreate, LinkPurpose, LinkResult, PendingLinkDto, SelfLinkCreate };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** JSON Schema (from Zod) describing params or variables. */
|
|
3
|
+
export declare const JsonSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
4
|
+
/** A host data provider (`defineProvider`) as listed in {@link PluginMeta}. */
|
|
5
|
+
export declare const MetaProvider: z.ZodObject<{
|
|
6
|
+
key: z.ZodString;
|
|
7
|
+
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
8
|
+
permission: z.ZodNullable<z.ZodString>;
|
|
9
|
+
params: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
10
|
+
variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
11
|
+
hasSample: z.ZodBoolean;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
/** A host or built-in command as listed in {@link PluginMeta}. */
|
|
14
|
+
export declare const MetaCommand: z.ZodObject<{
|
|
15
|
+
command: z.ZodString;
|
|
16
|
+
description: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
17
|
+
builtin: z.ZodBoolean;
|
|
18
|
+
permission: z.ZodNullable<z.ZodString>;
|
|
19
|
+
scope: z.ZodArray<z.ZodEnum<{
|
|
20
|
+
private: "private";
|
|
21
|
+
group: "group";
|
|
22
|
+
supergroup: "supergroup";
|
|
23
|
+
channel: "channel";
|
|
24
|
+
}>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
/** A host event (`defineEvent`) as listed in {@link PluginMeta}. */
|
|
27
|
+
export declare const MetaEvent: z.ZodObject<{
|
|
28
|
+
key: z.ZodString;
|
|
29
|
+
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
30
|
+
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
31
|
+
filterable: z.ZodArray<z.ZodString>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
/** A button action (`defineAction`); `confirm` = asks before running. */
|
|
34
|
+
export declare const MetaAction: z.ZodObject<{
|
|
35
|
+
key: z.ZodString;
|
|
36
|
+
permission: z.ZodNullable<z.ZodString>;
|
|
37
|
+
confirm: z.ZodBoolean;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
/** A dialog (`defineDialog`) with its step keys in order. */
|
|
40
|
+
export declare const MetaDialog: z.ZodObject<{
|
|
41
|
+
key: z.ZodString;
|
|
42
|
+
permission: z.ZodNullable<z.ZodString>;
|
|
43
|
+
steps: z.ZodArray<z.ZodString>;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
/** A named audience (`defineAudience`). */
|
|
46
|
+
export declare const MetaAudience: z.ZodObject<{
|
|
47
|
+
key: z.ZodString;
|
|
48
|
+
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
/** A template filter usable in `{{ value | name: args }}`: built-in, or the host's (`options.filters`). */
|
|
51
|
+
export declare const MetaFilter: z.ZodObject<{
|
|
52
|
+
name: z.ZodString;
|
|
53
|
+
builtin: z.ZodBoolean;
|
|
54
|
+
minArgs: z.ZodNumber;
|
|
55
|
+
maxArgs: z.ZodNullable<z.ZodNumber>;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
/** `GET /admin/meta`: one call to build any settings UI. */
|
|
58
|
+
export declare const PluginMeta: z.ZodObject<{
|
|
59
|
+
pluginVersion: z.ZodString;
|
|
60
|
+
schemaVersion: z.ZodNumber;
|
|
61
|
+
features: z.ZodRecord<z.ZodEnum<{
|
|
62
|
+
core: "core";
|
|
63
|
+
commands: "commands";
|
|
64
|
+
templates: "templates";
|
|
65
|
+
schedules: "schedules";
|
|
66
|
+
reports: "reports";
|
|
67
|
+
events: "events";
|
|
68
|
+
broadcasts: "broadcasts";
|
|
69
|
+
actions: "actions";
|
|
70
|
+
dialogs: "dialogs";
|
|
71
|
+
inbound: "inbound";
|
|
72
|
+
subscriptions: "subscriptions";
|
|
73
|
+
ai: "ai";
|
|
74
|
+
ops: "ops";
|
|
75
|
+
}>, z.ZodObject<{
|
|
76
|
+
enabled: z.ZodBoolean;
|
|
77
|
+
}, z.core.$strip>>;
|
|
78
|
+
locales: z.ZodArray<z.ZodString>;
|
|
79
|
+
defaultLocale: z.ZodString;
|
|
80
|
+
timezone: z.ZodString;
|
|
81
|
+
providers: z.ZodArray<z.ZodObject<{
|
|
82
|
+
key: z.ZodString;
|
|
83
|
+
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
84
|
+
permission: z.ZodNullable<z.ZodString>;
|
|
85
|
+
params: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
86
|
+
variables: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
87
|
+
hasSample: z.ZodBoolean;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
commands: z.ZodArray<z.ZodObject<{
|
|
90
|
+
command: z.ZodString;
|
|
91
|
+
description: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
92
|
+
builtin: z.ZodBoolean;
|
|
93
|
+
permission: z.ZodNullable<z.ZodString>;
|
|
94
|
+
scope: z.ZodArray<z.ZodEnum<{
|
|
95
|
+
private: "private";
|
|
96
|
+
group: "group";
|
|
97
|
+
supergroup: "supergroup";
|
|
98
|
+
channel: "channel";
|
|
99
|
+
}>>;
|
|
100
|
+
}, z.core.$strip>>;
|
|
101
|
+
events: z.ZodArray<z.ZodObject<{
|
|
102
|
+
key: z.ZodString;
|
|
103
|
+
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
104
|
+
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
105
|
+
filterable: z.ZodArray<z.ZodString>;
|
|
106
|
+
}, z.core.$strip>>;
|
|
107
|
+
actions: z.ZodArray<z.ZodObject<{
|
|
108
|
+
key: z.ZodString;
|
|
109
|
+
permission: z.ZodNullable<z.ZodString>;
|
|
110
|
+
confirm: z.ZodBoolean;
|
|
111
|
+
}, z.core.$strip>>;
|
|
112
|
+
dialogs: z.ZodArray<z.ZodObject<{
|
|
113
|
+
key: z.ZodString;
|
|
114
|
+
permission: z.ZodNullable<z.ZodString>;
|
|
115
|
+
steps: z.ZodArray<z.ZodString>;
|
|
116
|
+
}, z.core.$strip>>;
|
|
117
|
+
audiences: z.ZodArray<z.ZodObject<{
|
|
118
|
+
key: z.ZodString;
|
|
119
|
+
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
120
|
+
}, z.core.$strip>>;
|
|
121
|
+
fileSources: z.ZodArray<z.ZodString>;
|
|
122
|
+
renderers: z.ZodArray<z.ZodString>;
|
|
123
|
+
filters: z.ZodArray<z.ZodObject<{
|
|
124
|
+
name: z.ZodString;
|
|
125
|
+
builtin: z.ZodBoolean;
|
|
126
|
+
minArgs: z.ZodNumber;
|
|
127
|
+
maxArgs: z.ZodNullable<z.ZodNumber>;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
userSearch: z.ZodBoolean;
|
|
130
|
+
permissions: z.ZodArray<z.ZodString>;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
export type PluginMeta = z.infer<typeof PluginMeta>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Key, LocalizedText } from "./common.js";
|
|
2
|
+
import { FeatureKey } from "./features.js";
|
|
3
|
+
import { ChatKind } from "./chats.js";
|
|
4
|
+
import { CommandName } from "./commands.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// src/contracts/meta.ts
|
|
7
|
+
/** JSON Schema (from Zod) describing params or variables. */
|
|
8
|
+
const JsonSchema = z.record(z.string(), z.unknown());
|
|
9
|
+
/** A host data provider (`defineProvider`) as listed in {@link PluginMeta}. */
|
|
10
|
+
const MetaProvider = z.object({
|
|
11
|
+
key: Key,
|
|
12
|
+
label: LocalizedText,
|
|
13
|
+
permission: z.string().nullable(),
|
|
14
|
+
params: JsonSchema,
|
|
15
|
+
variables: JsonSchema,
|
|
16
|
+
/** Whether the provider defines `sample()` for previews. */
|
|
17
|
+
hasSample: z.boolean()
|
|
18
|
+
});
|
|
19
|
+
/** A host or built-in command as listed in {@link PluginMeta}. */
|
|
20
|
+
const MetaCommand = z.object({
|
|
21
|
+
command: CommandName,
|
|
22
|
+
description: LocalizedText,
|
|
23
|
+
builtin: z.boolean(),
|
|
24
|
+
permission: z.string().nullable(),
|
|
25
|
+
scope: z.array(ChatKind)
|
|
26
|
+
});
|
|
27
|
+
/** A host event (`defineEvent`) as listed in {@link PluginMeta}. */
|
|
28
|
+
const MetaEvent = z.object({
|
|
29
|
+
key: Key,
|
|
30
|
+
label: LocalizedText,
|
|
31
|
+
payload: JsonSchema,
|
|
32
|
+
filterable: z.array(z.string())
|
|
33
|
+
});
|
|
34
|
+
/** A button action (`defineAction`); `confirm` = asks before running. */
|
|
35
|
+
const MetaAction = z.object({
|
|
36
|
+
key: Key,
|
|
37
|
+
permission: z.string().nullable(),
|
|
38
|
+
confirm: z.boolean()
|
|
39
|
+
});
|
|
40
|
+
/** A dialog (`defineDialog`) with its step keys in order. */
|
|
41
|
+
const MetaDialog = z.object({
|
|
42
|
+
key: Key,
|
|
43
|
+
permission: z.string().nullable(),
|
|
44
|
+
steps: z.array(z.string())
|
|
45
|
+
});
|
|
46
|
+
/** A named audience (`defineAudience`). */
|
|
47
|
+
const MetaAudience = z.object({
|
|
48
|
+
key: z.string(),
|
|
49
|
+
label: LocalizedText
|
|
50
|
+
});
|
|
51
|
+
/** A template filter usable in `{{ value | name: args }}`: built-in, or the host's (`options.filters`). */
|
|
52
|
+
const MetaFilter = z.object({
|
|
53
|
+
name: z.string(),
|
|
54
|
+
builtin: z.boolean(),
|
|
55
|
+
minArgs: z.number().int().nonnegative(),
|
|
56
|
+
/** Null = no upper bound. */
|
|
57
|
+
maxArgs: z.number().int().nonnegative().nullable()
|
|
58
|
+
});
|
|
59
|
+
/** `GET /admin/meta`: one call to build any settings UI. */
|
|
60
|
+
const PluginMeta = z.object({
|
|
61
|
+
pluginVersion: z.string(),
|
|
62
|
+
schemaVersion: z.number().int(),
|
|
63
|
+
features: z.record(FeatureKey, z.object({ enabled: z.boolean() })),
|
|
64
|
+
locales: z.array(z.string()),
|
|
65
|
+
defaultLocale: z.string(),
|
|
66
|
+
/** Plugin default IANA time zone. */
|
|
67
|
+
timezone: z.string(),
|
|
68
|
+
providers: z.array(MetaProvider),
|
|
69
|
+
commands: z.array(MetaCommand),
|
|
70
|
+
events: z.array(MetaEvent),
|
|
71
|
+
actions: z.array(MetaAction),
|
|
72
|
+
dialogs: z.array(MetaDialog),
|
|
73
|
+
audiences: z.array(MetaAudience),
|
|
74
|
+
/** Registered file-source keys (`defineFileSource`). */
|
|
75
|
+
fileSources: z.array(z.string()),
|
|
76
|
+
/** Report formats with a renderer (`ports.renderers`). */
|
|
77
|
+
renderers: z.array(z.string()),
|
|
78
|
+
/** Template filters (built-ins first, then the host's). */
|
|
79
|
+
filters: z.array(MetaFilter),
|
|
80
|
+
/** True when `GET /admin/users?q=` works (the host gave `ports.users.search`). */
|
|
81
|
+
userSearch: z.boolean(),
|
|
82
|
+
/** Plugin permissions the caller holds. */
|
|
83
|
+
permissions: z.array(z.string())
|
|
84
|
+
});
|
|
85
|
+
export { JsonSchema, MetaAction, MetaAudience, MetaCommand, MetaDialog, MetaEvent, MetaFilter, MetaProvider, PluginMeta };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Permission names the plugin checks through `ports.authorize` (docs/05 §4), with the default `telegram` prefix. */
|
|
3
|
+
export declare const PERMISSION_NAMES: readonly ["telegram.view", "telegram.bots.manage", "telegram.chats.manage", "telegram.self.link", "telegram.destinations.manage", "telegram.commands.manage", "telegram.templates.manage", "telegram.schedules.manage", "telegram.events.manage", "telegram.broadcasts.send", "telegram.reports.run", "telegram.send", "telegram.ops.view", "telegram.ops.manage", "telegram.ops.content"];
|
|
4
|
+
/** Zod enum of {@link PERMISSION_NAMES}. */
|
|
5
|
+
export declare const PermissionName: z.ZodEnum<{
|
|
6
|
+
"telegram.view": "telegram.view";
|
|
7
|
+
"telegram.bots.manage": "telegram.bots.manage";
|
|
8
|
+
"telegram.chats.manage": "telegram.chats.manage";
|
|
9
|
+
"telegram.self.link": "telegram.self.link";
|
|
10
|
+
"telegram.destinations.manage": "telegram.destinations.manage";
|
|
11
|
+
"telegram.commands.manage": "telegram.commands.manage";
|
|
12
|
+
"telegram.templates.manage": "telegram.templates.manage";
|
|
13
|
+
"telegram.schedules.manage": "telegram.schedules.manage";
|
|
14
|
+
"telegram.events.manage": "telegram.events.manage";
|
|
15
|
+
"telegram.broadcasts.send": "telegram.broadcasts.send";
|
|
16
|
+
"telegram.reports.run": "telegram.reports.run";
|
|
17
|
+
"telegram.send": "telegram.send";
|
|
18
|
+
"telegram.ops.view": "telegram.ops.view";
|
|
19
|
+
"telegram.ops.manage": "telegram.ops.manage";
|
|
20
|
+
"telegram.ops.content": "telegram.ops.content";
|
|
21
|
+
}>;
|
|
22
|
+
export type PermissionName = z.infer<typeof PermissionName>;
|
|
23
|
+
/** Permission name with a host-chosen prefix (`permissions.prefix`), for example `tg.bots.manage`. */
|
|
24
|
+
export declare function permissionName(name: PermissionName, prefix?: string): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// src/contracts/permissions.ts
|
|
3
|
+
/** Permission names the plugin checks through `ports.authorize` (docs/05 §4), with the default `telegram` prefix. */
|
|
4
|
+
const PERMISSION_NAMES = [
|
|
5
|
+
"telegram.view",
|
|
6
|
+
"telegram.bots.manage",
|
|
7
|
+
"telegram.chats.manage",
|
|
8
|
+
"telegram.self.link",
|
|
9
|
+
"telegram.destinations.manage",
|
|
10
|
+
"telegram.commands.manage",
|
|
11
|
+
"telegram.templates.manage",
|
|
12
|
+
"telegram.schedules.manage",
|
|
13
|
+
"telegram.events.manage",
|
|
14
|
+
"telegram.broadcasts.send",
|
|
15
|
+
"telegram.reports.run",
|
|
16
|
+
"telegram.send",
|
|
17
|
+
"telegram.ops.view",
|
|
18
|
+
"telegram.ops.manage",
|
|
19
|
+
"telegram.ops.content"
|
|
20
|
+
];
|
|
21
|
+
/** Zod enum of {@link PERMISSION_NAMES}. */
|
|
22
|
+
const PermissionName = z.enum(PERMISSION_NAMES);
|
|
23
|
+
/** Permission name with a host-chosen prefix (`permissions.prefix`), for example `tg.bots.manage`. */
|
|
24
|
+
function permissionName(name, prefix = "telegram") {
|
|
25
|
+
return prefix === "telegram" ? name : `${prefix}${name.slice(8)}`;
|
|
26
|
+
}
|
|
27
|
+
export { PERMISSION_NAMES, PermissionName, permissionName };
|