@agents24/telegram 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -2
- package/compatibility.json +54 -0
- package/dist/contracts-C3NXzqar.d.cts +212 -0
- package/dist/contracts-C3NXzqar.d.ts +212 -0
- package/dist/gateway.cjs +647 -0
- package/dist/gateway.cjs.map +1 -0
- package/dist/gateway.d.cts +15 -0
- package/dist/gateway.d.ts +15 -0
- package/dist/gateway.js +624 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.cjs +661 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +60 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +628 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Talmudpedia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @agents24/telegram
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Last Updated: 2026-10-21
|
|
4
|
+
|
|
5
|
+
Reusable Telegram gateway and local/server conversation host for Agents24.
|
|
6
|
+
|
|
7
|
+
The gateway owns the shared bot token, verified webhook, device pairing, offline inbox, and delivery outbox. The host holds the Agents24 key and resolves application-owned conversations through the existing SDK. PA24 is the first consumer. Both entrypoints require explicit durable storage; there is no implicit in-memory production mode.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createTelegramHost, createAgents24TelegramDriver, createTelegramFileStore, emptyHostState } from '@agents24/telegram';
|
|
11
|
+
import { Agents24 } from '@agents24/node';
|
|
12
|
+
|
|
13
|
+
const driver = createAgents24TelegramDriver({
|
|
14
|
+
client: new Agents24({ baseUrl, apiKey }),
|
|
15
|
+
resolve: async (conversationId) => authenticatedConversation(conversationId),
|
|
16
|
+
});
|
|
17
|
+
const store = await createTelegramFileStore(privateStatePath, emptyHostState());
|
|
18
|
+
const host = createTelegramHost({ gatewayUrl, credential: installationCredential, driver, store, applicationName: 'My app' });
|
|
19
|
+
await host.run(abortController.signal);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`resolve` returns the existing thread, allowed Agent IDs, opaque runtime customer principal, integration ID, and optional session/chat scope. It must authorize the application's conversation; Telegram input never supplies runtime identity. `admitMessage` can route input through an application's own durable queue, and `beforeStop` can pause that queue before cancelling the exact remote run.
|
|
23
|
+
|
|
24
|
+
Use `enrollTelegramInstallation` once and persist its credential in a secret store. Call `beginPairing`, open the returned link, show the claimant from `status`, then explicitly call `confirmPairing`. This records the history baseline before activating delivery. `disconnect` revokes routing without deleting history. `resolveDelivery` requires an explicit retry/skip decision for uncertain external sends; retries never repeat Agent execution.
|
|
25
|
+
|
|
26
|
+
The portable `@agents24/telegram/gateway` exports `createTelegramGateway`, the storage contract, state factory, and protocol types. Mount its `/telegram/*` HTTP routes. Supply a trusted network key for enrollment rate limiting, a bot token, bot username, and a separate webhook secret. Register `/telegram/webhook` using Telegram's `setWebhook` with `allowed_updates: ["message", "callback_query"]`. Call `flushDeliveries` from a durable scheduler until pending delivery is drained. The Cloudflare PA24 adapter demonstrates per-record transactions, alarms and authenticated WebSocket wake hints. HTTP polling owns replay; wake hints are disposable.
|
|
27
|
+
|
|
28
|
+
V1 covers private text chats, queued admission, completed reply mirroring, questions, approval/rejection, Stop and disconnect. Offline text expires after 24 hours; controls require an online host. Media and groups receive bounded unsupported behavior. No old completed history is mirrored at activation. Each binding pins its installation and conversation generation.
|
|
29
|
+
|
|
30
|
+
Replies beyond 60,000 UTF-16 units include a bounded excerpt and a notice to read the full response in the consuming app. Oversized/unsupported questions hand off to that app. Confirmed deliveries and revoked/skipped output bodies are scrubbed. Unknown conversation replies require explicit Retry/Skip; disposable setup notices can be skipped after ambiguity and never block a conversation indefinitely. Disconnect abandons undelivered work for that generation, allowing a later connection to progress.
|
|
31
|
+
|
|
32
|
+
Set `applicationName` on both gateway and host for customer-facing notices. The SDK driver resumes scoped thread-event leases with a saved cursor and reconciles paginated canonical message history on reconnect or `snapshot_required`. An active run is attached for its authoritative pending interactions. Observation never starts another run. Local file transactions use private atomic commits and an exclusive writer; unchanged reads do not rewrite the file.
|
|
33
|
+
|
|
34
|
+
Never upload an organization key to the gateway or place secrets in URLs/logs. The gateway's transaction callback must be synchronous, isolated, atomic and durable before acknowledgment. `createMemoryTelegramStore` is an explicitly named test fixture, not durable storage. Node hosts support Node 22/24; the gateway entrypoint contains no Node imports and is tested in workerd by PA24.
|
|
35
|
+
|
|
36
|
+
This source package is pending canonical coordinated publication. See the repository Telegram architecture and execution evidence for the pilot's current verification status.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contractHash": "f99c7561fa9af69a90994868112704eb4bd78b01a1d56e63ce4d5ef42a0fbd0d",
|
|
3
|
+
"contractVersion": "0.3.0",
|
|
4
|
+
"corpus": "conformance/v1/corpus.json",
|
|
5
|
+
"generatedBy": "@agents24/sdk-contract",
|
|
6
|
+
"packages": {
|
|
7
|
+
"@agents24/ai-sdk": {
|
|
8
|
+
"ai": ">=7 <8",
|
|
9
|
+
"aiSdkReact": ">=4 <5",
|
|
10
|
+
"peer": "@agents24/client"
|
|
11
|
+
},
|
|
12
|
+
"@agents24/chat-react": {
|
|
13
|
+
"peer": "@agents24/react",
|
|
14
|
+
"react": ">=19 <20",
|
|
15
|
+
"reactDom": ">=19 <20"
|
|
16
|
+
},
|
|
17
|
+
"@agents24/client": {
|
|
18
|
+
"contract": "904701fe1c173854cd4154f2156020da471397fbc6bb644cea60f44c71a1a0d2",
|
|
19
|
+
"runtime": "run-stream.v3"
|
|
20
|
+
},
|
|
21
|
+
"@agents24/node": {
|
|
22
|
+
"contract": "f99c7561fa9af69a90994868112704eb4bd78b01a1d56e63ce4d5ef42a0fbd0d",
|
|
23
|
+
"node": "^22.0.0 || ^24.0.0"
|
|
24
|
+
},
|
|
25
|
+
"@agents24/react": {
|
|
26
|
+
"peer": "@agents24/client",
|
|
27
|
+
"react": ">=19 <20"
|
|
28
|
+
},
|
|
29
|
+
"@talmudpedia/runtime-sdk": {
|
|
30
|
+
"contract": "904701fe1c173854cd4154f2156020da471397fbc6bb644cea60f44c71a1a0d2",
|
|
31
|
+
"protocolOwner": "@agents24/client"
|
|
32
|
+
},
|
|
33
|
+
"agents24": {
|
|
34
|
+
"contract": "f99c7561fa9af69a90994868112704eb4bd78b01a1d56e63ce4d5ef42a0fbd0d",
|
|
35
|
+
"python": ">=3.10"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"protocols": {
|
|
39
|
+
"runtime": {
|
|
40
|
+
"minimum": "2.0.0",
|
|
41
|
+
"wire": "run-stream.v3"
|
|
42
|
+
},
|
|
43
|
+
"threadSummary": {
|
|
44
|
+
"minimum": "1.0.0",
|
|
45
|
+
"wire": "agents24.thread_summary_event.v1"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"schemaVersion": "agents24.compatibility.v1",
|
|
49
|
+
"targetOperationCounts": {
|
|
50
|
+
"client": 36,
|
|
51
|
+
"node": 193,
|
|
52
|
+
"python": 187
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
declare const TELEGRAM_PROTOCOL = "agents24.telegram.v1";
|
|
2
|
+
declare const TEXT_TTL_MS: number;
|
|
3
|
+
declare const PAIRING_TTL_MS: number;
|
|
4
|
+
declare const ACTION_TTL_MS: number;
|
|
5
|
+
declare const HOST_LEASE_MS = 45000;
|
|
6
|
+
declare const MAX_TELEGRAM_BUTTONS = 40;
|
|
7
|
+
/** The callback must be synchronous, atomic, isolated, and durably committed before resolving. */
|
|
8
|
+
interface TelegramStore<S> {
|
|
9
|
+
transaction<T>(change: (state: S) => T): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
declare class TelegramError extends Error {
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly status: number;
|
|
14
|
+
constructor(code: string, status?: number);
|
|
15
|
+
}
|
|
16
|
+
interface TelegramBinding {
|
|
17
|
+
id: string;
|
|
18
|
+
installationId: string;
|
|
19
|
+
conversationId: string;
|
|
20
|
+
generation: string;
|
|
21
|
+
chatId: string;
|
|
22
|
+
userId: string;
|
|
23
|
+
displayName: string;
|
|
24
|
+
createdAt: number;
|
|
25
|
+
status: "active" | "revoked";
|
|
26
|
+
}
|
|
27
|
+
interface TelegramPairing {
|
|
28
|
+
id: string;
|
|
29
|
+
installationId: string;
|
|
30
|
+
conversationId: string;
|
|
31
|
+
tokenHash: string;
|
|
32
|
+
expiresAt: number;
|
|
33
|
+
status: "pending" | "awaiting_confirmation" | "active" | "expired";
|
|
34
|
+
claimant?: {
|
|
35
|
+
chatId: string;
|
|
36
|
+
userId: string;
|
|
37
|
+
displayName: string;
|
|
38
|
+
};
|
|
39
|
+
bindingId?: string;
|
|
40
|
+
}
|
|
41
|
+
interface TelegramInstallation {
|
|
42
|
+
id: string;
|
|
43
|
+
credentialHash: string;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
lastSeenAt: number;
|
|
46
|
+
revoked: boolean;
|
|
47
|
+
}
|
|
48
|
+
interface TelegramInbound {
|
|
49
|
+
id: string;
|
|
50
|
+
bindingId: string;
|
|
51
|
+
generation: string;
|
|
52
|
+
receivedAt: number;
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
kind: "text" | "action";
|
|
55
|
+
text?: string;
|
|
56
|
+
actionRef?: string;
|
|
57
|
+
status: "pending" | "accepted" | "expired";
|
|
58
|
+
}
|
|
59
|
+
interface TelegramButton {
|
|
60
|
+
label: string;
|
|
61
|
+
actionRef: string;
|
|
62
|
+
kind?: "stop" | "answer";
|
|
63
|
+
}
|
|
64
|
+
interface TelegramDelivery {
|
|
65
|
+
id: string;
|
|
66
|
+
bindingId?: string;
|
|
67
|
+
generation?: string;
|
|
68
|
+
sourceId: string;
|
|
69
|
+
chatId: string;
|
|
70
|
+
text: string;
|
|
71
|
+
buttons?: TelegramButton[];
|
|
72
|
+
replyRef?: string;
|
|
73
|
+
fingerprint: string;
|
|
74
|
+
order: number;
|
|
75
|
+
status: "pending" | "sending" | "sent" | "unknown" | "rejected" | "skipped";
|
|
76
|
+
createdAt: number;
|
|
77
|
+
retryAt: number;
|
|
78
|
+
attemptAt?: number;
|
|
79
|
+
attempts: number;
|
|
80
|
+
messageId?: string;
|
|
81
|
+
failureCode?: string;
|
|
82
|
+
}
|
|
83
|
+
interface TelegramAction {
|
|
84
|
+
id: string;
|
|
85
|
+
bindingId: string;
|
|
86
|
+
generation: string;
|
|
87
|
+
actionRef: string;
|
|
88
|
+
kind?: "stop" | "answer";
|
|
89
|
+
expiresAt: number;
|
|
90
|
+
}
|
|
91
|
+
interface TelegramGatewayState {
|
|
92
|
+
version: typeof TELEGRAM_PROTOCOL;
|
|
93
|
+
installations: Record<string, TelegramInstallation>;
|
|
94
|
+
pairings: Record<string, TelegramPairing>;
|
|
95
|
+
bindings: Record<string, TelegramBinding>;
|
|
96
|
+
inbox: Record<string, TelegramInbound>;
|
|
97
|
+
deliveries: Record<string, TelegramDelivery>;
|
|
98
|
+
actions: Record<string, TelegramAction>;
|
|
99
|
+
updates: Record<string, number>;
|
|
100
|
+
rates: Record<string, {
|
|
101
|
+
start: number;
|
|
102
|
+
count: number;
|
|
103
|
+
}>;
|
|
104
|
+
nextDeliveryOrder: number;
|
|
105
|
+
}
|
|
106
|
+
declare function emptyGatewayState(): TelegramGatewayState;
|
|
107
|
+
interface TelegramGatewayOptions {
|
|
108
|
+
applicationName?: string;
|
|
109
|
+
store: TelegramStore<TelegramGatewayState>;
|
|
110
|
+
botToken: string;
|
|
111
|
+
botUsername: string;
|
|
112
|
+
webhookSecret: string;
|
|
113
|
+
fetch?: typeof fetch;
|
|
114
|
+
now?: () => number;
|
|
115
|
+
/** Required for public enrollment. Supply a trusted network-derived value, never a body field. */
|
|
116
|
+
enrollmentKey?: (request: Request) => string | null;
|
|
117
|
+
notifyHost?: (installationId: string) => void;
|
|
118
|
+
}
|
|
119
|
+
interface TelegramConversation {
|
|
120
|
+
threadId: string;
|
|
121
|
+
agentId: string;
|
|
122
|
+
agentIds?: string[];
|
|
123
|
+
externalUserId: string;
|
|
124
|
+
integrationId: string;
|
|
125
|
+
externalSessionId?: string;
|
|
126
|
+
chatScope?: string;
|
|
127
|
+
runtimeTarget?: "published" | "draft";
|
|
128
|
+
}
|
|
129
|
+
interface TelegramMessage {
|
|
130
|
+
id: string;
|
|
131
|
+
sequence: number;
|
|
132
|
+
runId: string | null;
|
|
133
|
+
text: string;
|
|
134
|
+
completed: boolean;
|
|
135
|
+
terminal?: boolean;
|
|
136
|
+
}
|
|
137
|
+
interface TelegramQuestion {
|
|
138
|
+
id: string;
|
|
139
|
+
text: string;
|
|
140
|
+
multiple: boolean;
|
|
141
|
+
options: {
|
|
142
|
+
id: string;
|
|
143
|
+
label: string;
|
|
144
|
+
}[];
|
|
145
|
+
allowText: boolean;
|
|
146
|
+
}
|
|
147
|
+
interface TelegramInterrupt {
|
|
148
|
+
runId: string;
|
|
149
|
+
interruptId: string;
|
|
150
|
+
message: string;
|
|
151
|
+
actions: ("approve" | "reject")[];
|
|
152
|
+
questions: TelegramQuestion[];
|
|
153
|
+
unsupported: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface TelegramObservation {
|
|
156
|
+
messages: TelegramMessage[];
|
|
157
|
+
activeRunId: string | null;
|
|
158
|
+
cancellable: boolean;
|
|
159
|
+
interrupts: TelegramInterrupt[];
|
|
160
|
+
cursor?: number;
|
|
161
|
+
runId?: string;
|
|
162
|
+
threadCursor?: number;
|
|
163
|
+
}
|
|
164
|
+
interface TelegramRuntimeAction {
|
|
165
|
+
runId: string;
|
|
166
|
+
interruptId?: string;
|
|
167
|
+
action: "approve" | "reject" | "respond" | "stop";
|
|
168
|
+
answers?: {
|
|
169
|
+
question_id: string;
|
|
170
|
+
selected_option_ids: string[];
|
|
171
|
+
custom_text?: string;
|
|
172
|
+
}[];
|
|
173
|
+
}
|
|
174
|
+
interface TelegramConversationDriver {
|
|
175
|
+
resolve(conversationId: string): Promise<TelegramConversation | null>;
|
|
176
|
+
submit(conversation: TelegramConversation | null, conversationId: string, text: string, submissionId: string, expiresAt: number): Promise<void>;
|
|
177
|
+
read(conversation: TelegramConversation, afterSequence: number, threadCursor?: number, includeRunIds?: string[]): Promise<TelegramObservation>;
|
|
178
|
+
control(conversation: TelegramConversation, action: TelegramRuntimeAction, idempotencyKey: string): Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
interface TelegramLocalBinding {
|
|
181
|
+
conversationId: string;
|
|
182
|
+
generation?: string;
|
|
183
|
+
baseline: number;
|
|
184
|
+
initialRuns: string[];
|
|
185
|
+
delivered: Record<string, boolean>;
|
|
186
|
+
cursor: number;
|
|
187
|
+
runId?: string;
|
|
188
|
+
threadCursor?: number;
|
|
189
|
+
watermark?: number;
|
|
190
|
+
actions: Record<string, {
|
|
191
|
+
action: TelegramRuntimeAction;
|
|
192
|
+
expiresAt: number;
|
|
193
|
+
choice?: {
|
|
194
|
+
questionId?: string;
|
|
195
|
+
optionId?: string;
|
|
196
|
+
submit?: boolean;
|
|
197
|
+
freeText?: boolean;
|
|
198
|
+
};
|
|
199
|
+
}>;
|
|
200
|
+
prompts: Record<string, string>;
|
|
201
|
+
selections: Record<string, string[]>;
|
|
202
|
+
custom: Record<string, string>;
|
|
203
|
+
interrupts: Record<string, TelegramInterrupt>;
|
|
204
|
+
}
|
|
205
|
+
interface TelegramHostState {
|
|
206
|
+
version: typeof TELEGRAM_PROTOCOL;
|
|
207
|
+
bindings: Record<string, TelegramLocalBinding>;
|
|
208
|
+
accepted: Record<string, number>;
|
|
209
|
+
}
|
|
210
|
+
declare function emptyHostState(): TelegramHostState;
|
|
211
|
+
|
|
212
|
+
export { ACTION_TTL_MS as A, HOST_LEASE_MS as H, MAX_TELEGRAM_BUTTONS as M, PAIRING_TTL_MS as P, type TelegramStore as T, type TelegramGatewayOptions as a, TELEGRAM_PROTOCOL as b, TEXT_TTL_MS as c, type TelegramAction as d, type TelegramBinding as e, type TelegramButton as f, type TelegramConversation as g, type TelegramConversationDriver as h, type TelegramDelivery as i, TelegramError as j, type TelegramGatewayState as k, type TelegramHostState as l, type TelegramInbound as m, type TelegramInstallation as n, type TelegramInterrupt as o, type TelegramLocalBinding as p, type TelegramMessage as q, type TelegramObservation as r, type TelegramPairing as s, type TelegramQuestion as t, type TelegramRuntimeAction as u, emptyGatewayState as v, emptyHostState as w };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
declare const TELEGRAM_PROTOCOL = "agents24.telegram.v1";
|
|
2
|
+
declare const TEXT_TTL_MS: number;
|
|
3
|
+
declare const PAIRING_TTL_MS: number;
|
|
4
|
+
declare const ACTION_TTL_MS: number;
|
|
5
|
+
declare const HOST_LEASE_MS = 45000;
|
|
6
|
+
declare const MAX_TELEGRAM_BUTTONS = 40;
|
|
7
|
+
/** The callback must be synchronous, atomic, isolated, and durably committed before resolving. */
|
|
8
|
+
interface TelegramStore<S> {
|
|
9
|
+
transaction<T>(change: (state: S) => T): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
declare class TelegramError extends Error {
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly status: number;
|
|
14
|
+
constructor(code: string, status?: number);
|
|
15
|
+
}
|
|
16
|
+
interface TelegramBinding {
|
|
17
|
+
id: string;
|
|
18
|
+
installationId: string;
|
|
19
|
+
conversationId: string;
|
|
20
|
+
generation: string;
|
|
21
|
+
chatId: string;
|
|
22
|
+
userId: string;
|
|
23
|
+
displayName: string;
|
|
24
|
+
createdAt: number;
|
|
25
|
+
status: "active" | "revoked";
|
|
26
|
+
}
|
|
27
|
+
interface TelegramPairing {
|
|
28
|
+
id: string;
|
|
29
|
+
installationId: string;
|
|
30
|
+
conversationId: string;
|
|
31
|
+
tokenHash: string;
|
|
32
|
+
expiresAt: number;
|
|
33
|
+
status: "pending" | "awaiting_confirmation" | "active" | "expired";
|
|
34
|
+
claimant?: {
|
|
35
|
+
chatId: string;
|
|
36
|
+
userId: string;
|
|
37
|
+
displayName: string;
|
|
38
|
+
};
|
|
39
|
+
bindingId?: string;
|
|
40
|
+
}
|
|
41
|
+
interface TelegramInstallation {
|
|
42
|
+
id: string;
|
|
43
|
+
credentialHash: string;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
lastSeenAt: number;
|
|
46
|
+
revoked: boolean;
|
|
47
|
+
}
|
|
48
|
+
interface TelegramInbound {
|
|
49
|
+
id: string;
|
|
50
|
+
bindingId: string;
|
|
51
|
+
generation: string;
|
|
52
|
+
receivedAt: number;
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
kind: "text" | "action";
|
|
55
|
+
text?: string;
|
|
56
|
+
actionRef?: string;
|
|
57
|
+
status: "pending" | "accepted" | "expired";
|
|
58
|
+
}
|
|
59
|
+
interface TelegramButton {
|
|
60
|
+
label: string;
|
|
61
|
+
actionRef: string;
|
|
62
|
+
kind?: "stop" | "answer";
|
|
63
|
+
}
|
|
64
|
+
interface TelegramDelivery {
|
|
65
|
+
id: string;
|
|
66
|
+
bindingId?: string;
|
|
67
|
+
generation?: string;
|
|
68
|
+
sourceId: string;
|
|
69
|
+
chatId: string;
|
|
70
|
+
text: string;
|
|
71
|
+
buttons?: TelegramButton[];
|
|
72
|
+
replyRef?: string;
|
|
73
|
+
fingerprint: string;
|
|
74
|
+
order: number;
|
|
75
|
+
status: "pending" | "sending" | "sent" | "unknown" | "rejected" | "skipped";
|
|
76
|
+
createdAt: number;
|
|
77
|
+
retryAt: number;
|
|
78
|
+
attemptAt?: number;
|
|
79
|
+
attempts: number;
|
|
80
|
+
messageId?: string;
|
|
81
|
+
failureCode?: string;
|
|
82
|
+
}
|
|
83
|
+
interface TelegramAction {
|
|
84
|
+
id: string;
|
|
85
|
+
bindingId: string;
|
|
86
|
+
generation: string;
|
|
87
|
+
actionRef: string;
|
|
88
|
+
kind?: "stop" | "answer";
|
|
89
|
+
expiresAt: number;
|
|
90
|
+
}
|
|
91
|
+
interface TelegramGatewayState {
|
|
92
|
+
version: typeof TELEGRAM_PROTOCOL;
|
|
93
|
+
installations: Record<string, TelegramInstallation>;
|
|
94
|
+
pairings: Record<string, TelegramPairing>;
|
|
95
|
+
bindings: Record<string, TelegramBinding>;
|
|
96
|
+
inbox: Record<string, TelegramInbound>;
|
|
97
|
+
deliveries: Record<string, TelegramDelivery>;
|
|
98
|
+
actions: Record<string, TelegramAction>;
|
|
99
|
+
updates: Record<string, number>;
|
|
100
|
+
rates: Record<string, {
|
|
101
|
+
start: number;
|
|
102
|
+
count: number;
|
|
103
|
+
}>;
|
|
104
|
+
nextDeliveryOrder: number;
|
|
105
|
+
}
|
|
106
|
+
declare function emptyGatewayState(): TelegramGatewayState;
|
|
107
|
+
interface TelegramGatewayOptions {
|
|
108
|
+
applicationName?: string;
|
|
109
|
+
store: TelegramStore<TelegramGatewayState>;
|
|
110
|
+
botToken: string;
|
|
111
|
+
botUsername: string;
|
|
112
|
+
webhookSecret: string;
|
|
113
|
+
fetch?: typeof fetch;
|
|
114
|
+
now?: () => number;
|
|
115
|
+
/** Required for public enrollment. Supply a trusted network-derived value, never a body field. */
|
|
116
|
+
enrollmentKey?: (request: Request) => string | null;
|
|
117
|
+
notifyHost?: (installationId: string) => void;
|
|
118
|
+
}
|
|
119
|
+
interface TelegramConversation {
|
|
120
|
+
threadId: string;
|
|
121
|
+
agentId: string;
|
|
122
|
+
agentIds?: string[];
|
|
123
|
+
externalUserId: string;
|
|
124
|
+
integrationId: string;
|
|
125
|
+
externalSessionId?: string;
|
|
126
|
+
chatScope?: string;
|
|
127
|
+
runtimeTarget?: "published" | "draft";
|
|
128
|
+
}
|
|
129
|
+
interface TelegramMessage {
|
|
130
|
+
id: string;
|
|
131
|
+
sequence: number;
|
|
132
|
+
runId: string | null;
|
|
133
|
+
text: string;
|
|
134
|
+
completed: boolean;
|
|
135
|
+
terminal?: boolean;
|
|
136
|
+
}
|
|
137
|
+
interface TelegramQuestion {
|
|
138
|
+
id: string;
|
|
139
|
+
text: string;
|
|
140
|
+
multiple: boolean;
|
|
141
|
+
options: {
|
|
142
|
+
id: string;
|
|
143
|
+
label: string;
|
|
144
|
+
}[];
|
|
145
|
+
allowText: boolean;
|
|
146
|
+
}
|
|
147
|
+
interface TelegramInterrupt {
|
|
148
|
+
runId: string;
|
|
149
|
+
interruptId: string;
|
|
150
|
+
message: string;
|
|
151
|
+
actions: ("approve" | "reject")[];
|
|
152
|
+
questions: TelegramQuestion[];
|
|
153
|
+
unsupported: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface TelegramObservation {
|
|
156
|
+
messages: TelegramMessage[];
|
|
157
|
+
activeRunId: string | null;
|
|
158
|
+
cancellable: boolean;
|
|
159
|
+
interrupts: TelegramInterrupt[];
|
|
160
|
+
cursor?: number;
|
|
161
|
+
runId?: string;
|
|
162
|
+
threadCursor?: number;
|
|
163
|
+
}
|
|
164
|
+
interface TelegramRuntimeAction {
|
|
165
|
+
runId: string;
|
|
166
|
+
interruptId?: string;
|
|
167
|
+
action: "approve" | "reject" | "respond" | "stop";
|
|
168
|
+
answers?: {
|
|
169
|
+
question_id: string;
|
|
170
|
+
selected_option_ids: string[];
|
|
171
|
+
custom_text?: string;
|
|
172
|
+
}[];
|
|
173
|
+
}
|
|
174
|
+
interface TelegramConversationDriver {
|
|
175
|
+
resolve(conversationId: string): Promise<TelegramConversation | null>;
|
|
176
|
+
submit(conversation: TelegramConversation | null, conversationId: string, text: string, submissionId: string, expiresAt: number): Promise<void>;
|
|
177
|
+
read(conversation: TelegramConversation, afterSequence: number, threadCursor?: number, includeRunIds?: string[]): Promise<TelegramObservation>;
|
|
178
|
+
control(conversation: TelegramConversation, action: TelegramRuntimeAction, idempotencyKey: string): Promise<void>;
|
|
179
|
+
}
|
|
180
|
+
interface TelegramLocalBinding {
|
|
181
|
+
conversationId: string;
|
|
182
|
+
generation?: string;
|
|
183
|
+
baseline: number;
|
|
184
|
+
initialRuns: string[];
|
|
185
|
+
delivered: Record<string, boolean>;
|
|
186
|
+
cursor: number;
|
|
187
|
+
runId?: string;
|
|
188
|
+
threadCursor?: number;
|
|
189
|
+
watermark?: number;
|
|
190
|
+
actions: Record<string, {
|
|
191
|
+
action: TelegramRuntimeAction;
|
|
192
|
+
expiresAt: number;
|
|
193
|
+
choice?: {
|
|
194
|
+
questionId?: string;
|
|
195
|
+
optionId?: string;
|
|
196
|
+
submit?: boolean;
|
|
197
|
+
freeText?: boolean;
|
|
198
|
+
};
|
|
199
|
+
}>;
|
|
200
|
+
prompts: Record<string, string>;
|
|
201
|
+
selections: Record<string, string[]>;
|
|
202
|
+
custom: Record<string, string>;
|
|
203
|
+
interrupts: Record<string, TelegramInterrupt>;
|
|
204
|
+
}
|
|
205
|
+
interface TelegramHostState {
|
|
206
|
+
version: typeof TELEGRAM_PROTOCOL;
|
|
207
|
+
bindings: Record<string, TelegramLocalBinding>;
|
|
208
|
+
accepted: Record<string, number>;
|
|
209
|
+
}
|
|
210
|
+
declare function emptyHostState(): TelegramHostState;
|
|
211
|
+
|
|
212
|
+
export { ACTION_TTL_MS as A, HOST_LEASE_MS as H, MAX_TELEGRAM_BUTTONS as M, PAIRING_TTL_MS as P, type TelegramStore as T, type TelegramGatewayOptions as a, TELEGRAM_PROTOCOL as b, TEXT_TTL_MS as c, type TelegramAction as d, type TelegramBinding as e, type TelegramButton as f, type TelegramConversation as g, type TelegramConversationDriver as h, type TelegramDelivery as i, TelegramError as j, type TelegramGatewayState as k, type TelegramHostState as l, type TelegramInbound as m, type TelegramInstallation as n, type TelegramInterrupt as o, type TelegramLocalBinding as p, type TelegramMessage as q, type TelegramObservation as r, type TelegramPairing as s, type TelegramQuestion as t, type TelegramRuntimeAction as u, emptyGatewayState as v, emptyHostState as w };
|