Skip to content

Commit 7cd70ed

Browse files
committed
feat: add local telegram channel driver
1 parent ae55252 commit 7cd70ed

16 files changed

Lines changed: 1006 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project used to be called `multipass`, but was renamed to `crabline` to avo
1111
The v1 shape is:
1212

1313
- built-in `loopback` provider for local development and contract tests
14+
- deterministic local channel SDK provider, starting with `telegram-local-v1`
1415
- native `discord` provider backed by the Chat SDK Discord adapter
1516
- native `slack` provider backed by the Chat SDK Slack adapter
1617
- native community adapters for `matrix` and `imessage`
@@ -70,7 +71,7 @@ configVersion: 1
7071
userName: crabline
7172
providers:
7273
local:
73-
adapter: loopback | script | slack | discord | matrix | imessage
74+
adapter: channel | loopback | script | slack | discord | matrix | imessage
7475
platform: see support matrix below
7576
fixtures:
7677
- id: string
@@ -100,6 +101,7 @@ Credentials stay in env, never in fixtures.
100101
101102
- `ready`: `loopback`, native `slack`, native `discord`, native-community `matrix`, native-community `imessage`
102103
- `bridge`: `bluebubbles`, `feishu`, `googlechat`, `irc`, `line`, `mattermost`, `msteams`, `nextcloudtalk`, `nostr`, `signal`, `synologychat`, `telegram`, `tlon`, `twitch`, `webchat`, `whatsapp`, `zalo`, `zalouser`
104+
- deterministic local channel driver: `telegram-local-v1` via `adapter: channel`, `platform: telegram`
103105
- Plugin-backed in OpenClaw, still supported through the bridge: `feishu`, `line`, `mattermost`, `msteams`, `nextcloudtalk`, `nostr`, `synologychat`, `tlon`, `twitch`, `zalo`, `zalouser`
104106
- Recommended bridge-only path today: `bluebubbles`, `googlechat`, `irc`, `signal`, `telegram`, `webchat`, `whatsapp`
105107

@@ -110,6 +112,32 @@ Telegram bridge notes:
110112
- Best operator path: DM-first, then group/topic once DM roundtrip is stable.
111113
- For unattended automation, drive the user side with MTProto (for example Telethon), not a second bot.
112114

115+
Local Telegram channel SDK driver:
116+
117+
```yaml
118+
providers:
119+
telegram-local:
120+
adapter: channel
121+
platform: telegram
122+
channel:
123+
driver: telegram-local-v1
124+
botUserName: multipass_telegram_bot
125+
qaResponse:
126+
mode: ack # QA-fixture response only; no model call is made
127+
```
128+
129+
`telegram-local-v1` is a deterministic local upstream shim. It records Telegram-shaped
130+
inbound events, outbound actions, and transcript entries for DM, group mention,
131+
forum topic/thread, inline button action, media metadata, and reconnect assertions.
132+
It is not Canonical Multipass VM orchestration and does not route through OpenClaw's
133+
`qa-channel` normalized bus.
134+
135+
Capability metadata is available for automation:
136+
137+
```bash
138+
pnpm dev channel-matrix --json
139+
```
140+
113141
Native Discord provider options:
114142

115143
```yaml
@@ -287,6 +315,7 @@ pnpm dev providers --config fixtures/examples/openclaw-supported.yaml
287315
```bash
288316
crabline providers
289317
crabline fixtures
318+
crabline channel-matrix
290319
crabline probe <fixture|provider>
291320
crabline send <fixture>
292321
crabline roundtrip <fixture>
@@ -363,6 +392,7 @@ or:
363392

364393
## Current scope
365394

366-
- Real built-in providers: `loopback`, native `slack`
395+
- Real built-in providers: `loopback`, native `slack`, native `discord`, native-community `matrix`, native-community `imessage`
396+
- Deterministic local channel SDK drivers: `telegram-local-v1`
367397
- Real external bridge: `script` for the full OpenClaw channel matrix
368-
- Not implemented yet: native adapters beyond Slack, richer inbound event storage, rich media/cards, recorder compaction/query tooling
398+
- Not implemented yet: local channel drivers beyond Telegram, richer recorder compaction/query tooling, live-model response generation

‎fixtures/examples/crabline.example.yaml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ providers:
88
loopback:
99
delayMs: 0
1010

11+
telegram-local:
12+
adapter: channel
13+
platform: telegram
14+
channel:
15+
driver: telegram-local-v1
16+
botUserName: multipass_telegram_bot
17+
qaResponse:
18+
mode: ack
19+
1120
slack-native:
1221
adapter: slack
1322
platform: slack
@@ -87,6 +96,39 @@ fixtures:
8796
id: agent-bot
8897
behavior: agent
8998

99+
- id: telegram-local-dm
100+
provider: telegram-local
101+
mode: roundtrip
102+
target:
103+
id: "100000001"
104+
metadata:
105+
chatType: dm
106+
userName: qa-user
107+
inboundMatch:
108+
author: assistant
109+
strategy: contains
110+
nonce: contains
111+
112+
- id: telegram-local-group-topic-action
113+
provider: telegram-local
114+
mode: roundtrip
115+
target:
116+
id: "-100000001"
117+
channelId: telegram:group:-100000001
118+
threadId: "42"
119+
metadata:
120+
actionId: approve-tool-1
121+
actionPayload: approve:tool
122+
actionType: button
123+
chatType: group
124+
mediaKind: image
125+
mention: "true"
126+
topicId: "42"
127+
inboundMatch:
128+
author: assistant
129+
strategy: contains
130+
nonce: contains
131+
90132
- id: slack-openclaw-demo
91133
provider: slack-openclaw
92134
mode: roundtrip

‎src/channels/index.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export { LOCAL_CHANNEL_DRIVER_MATRIX } from "./matrix.js";
2+
export {
3+
TELEGRAM_LOCAL_DRIVER_ID,
4+
TELEGRAM_LOCAL_DRIVER_METADATA,
5+
TelegramLocalChannelDriver,
6+
} from "./telegram.js";
7+
export { LocalChannelUpstream } from "./local-upstream.js";
8+
export type {
9+
ChannelActor,
10+
ChannelAttachment,
11+
ChannelCapability,
12+
ChannelCapabilityMatrixRow,
13+
ChannelConversation,
14+
ChannelDirection,
15+
ChannelDriverMetadata,
16+
ChannelLiveMode,
17+
ChannelNativeAction,
18+
ChannelTranscriptEntry,
19+
ChannelTranscriptKind,
20+
LocalChannelDriverId,
21+
} from "./types.js";

‎src/channels/local-upstream.ts‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import type {
2+
ChannelActor,
3+
ChannelAttachment,
4+
ChannelConversation,
5+
ChannelDriverMetadata,
6+
ChannelNativeAction,
7+
ChannelTranscriptEntry,
8+
ChannelTranscriptKind,
9+
} from "./types.js";
10+
11+
export type IngestChannelEventInput = {
12+
action?: ChannelNativeAction | undefined;
13+
actor: ChannelActor;
14+
attachments?: ChannelAttachment[] | undefined;
15+
conversation: ChannelConversation;
16+
kind?: ChannelTranscriptKind | undefined;
17+
raw?: Record<string, unknown> | undefined;
18+
replyToId?: string | undefined;
19+
sentAt?: string | undefined;
20+
text?: string | undefined;
21+
};
22+
23+
export type RecordChannelActionInput = {
24+
action?: ChannelNativeAction | undefined;
25+
actor: ChannelActor;
26+
attachments?: ChannelAttachment[] | undefined;
27+
conversation: ChannelConversation;
28+
kind?: ChannelTranscriptKind | undefined;
29+
raw?: Record<string, unknown> | undefined;
30+
replyToId?: string | undefined;
31+
sentAt?: string | undefined;
32+
text?: string | undefined;
33+
};
34+
35+
export class LocalChannelUpstream {
36+
readonly metadata: ChannelDriverMetadata;
37+
38+
readonly #transcript: ChannelTranscriptEntry[] = [];
39+
#sequence = 0;
40+
41+
constructor(metadata: ChannelDriverMetadata) {
42+
this.metadata = metadata;
43+
}
44+
45+
ingestEvent(input: IngestChannelEventInput): ChannelTranscriptEntry {
46+
return this.#append("inbound", input);
47+
}
48+
49+
recordAction(input: RecordChannelActionInput): ChannelTranscriptEntry {
50+
return this.#append("outbound", input);
51+
}
52+
53+
listTranscript(conversation?: ChannelConversation): ChannelTranscriptEntry[] {
54+
if (!conversation) {
55+
return [...this.#transcript];
56+
}
57+
58+
return this.#transcript.filter(
59+
(entry) =>
60+
entry.conversation.id === conversation.id &&
61+
entry.conversation.topicId === conversation.topicId,
62+
);
63+
}
64+
65+
listSince(params: {
66+
conversation: ChannelConversation;
67+
direction?: "inbound" | "outbound" | undefined;
68+
since?: string | undefined;
69+
}): ChannelTranscriptEntry[] {
70+
const sinceTime = params.since ? new Date(params.since).getTime() : Number.NEGATIVE_INFINITY;
71+
return this.listTranscript(params.conversation).filter((entry) => {
72+
if (params.direction && entry.direction !== params.direction) {
73+
return false;
74+
}
75+
return new Date(entry.sentAt).getTime() >= sinceTime;
76+
});
77+
}
78+
79+
#append(
80+
direction: "inbound" | "outbound",
81+
input: IngestChannelEventInput | RecordChannelActionInput,
82+
): ChannelTranscriptEntry {
83+
this.#sequence += 1;
84+
const id = `${this.metadata.driverId}:event:${this.#sequence}`;
85+
const entry: ChannelTranscriptEntry = {
86+
actor: input.actor,
87+
attachments: input.attachments ?? [],
88+
channel: this.metadata.channel,
89+
conversation: input.conversation,
90+
direction,
91+
driverId: this.metadata.driverId,
92+
id,
93+
kind: input.kind ?? "message",
94+
raw: input.raw ?? {},
95+
sentAt: input.sentAt ?? new Date(1_767_225_600_000 + this.#sequence).toISOString(),
96+
text: input.text ?? "",
97+
};
98+
99+
if (input.action) {
100+
entry.action = input.action;
101+
}
102+
if (input.replyToId) {
103+
entry.replyToId = input.replyToId;
104+
}
105+
106+
this.#transcript.push(entry);
107+
return entry;
108+
}
109+
}

‎src/channels/matrix.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { ChannelCapabilityMatrixRow } from "./types.js";
2+
import { TELEGRAM_LOCAL_DRIVER_ID, TELEGRAM_LOCAL_DRIVER_METADATA } from "./telegram.js";
3+
4+
export const LOCAL_CHANNEL_DRIVER_MATRIX = [
5+
...TELEGRAM_LOCAL_DRIVER_METADATA.capabilities.map(
6+
(capability): ChannelCapabilityMatrixRow => ({
7+
capabilityId: capability.id,
8+
channel: "telegram",
9+
driverId: TELEGRAM_LOCAL_DRIVER_ID,
10+
notes: capability.notes,
11+
status: capability.status,
12+
}),
13+
),
14+
{
15+
capabilityId: "discord.dm.text",
16+
channel: "discord",
17+
notes: "Planned local Discord upstream driver.",
18+
status: "planned",
19+
},
20+
{
21+
capabilityId: "slack.dm.text",
22+
channel: "slack",
23+
notes: "Planned local Slack upstream driver.",
24+
status: "planned",
25+
},
26+
{
27+
capabilityId: "whatsapp.dm.text",
28+
channel: "whatsapp",
29+
notes: "Planned local WhatsApp upstream driver.",
30+
status: "planned",
31+
},
32+
] as const satisfies readonly ChannelCapabilityMatrixRow[];

0 commit comments

Comments
 (0)