@diegoaltoworks/chatter 0.54.2 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Telegram update -> {@link ChannelMessage}: the transport's own half of the
3
+ * channel contract (see docs/build-a-channel.md), kept pure so mention and
4
+ * reply-to detection are testable without a network or a running channel.
5
+ *
6
+ * Addressing parity with WhatsApp is the point of this module. WhatsApp
7
+ * resolves "was the bot addressed?" from `contextInfo.mentionedJid` and the
8
+ * quoted participant; Telegram resolves it from message entities and
9
+ * `reply_to_message.from`. The gate policy that consumes those booleans
10
+ * (`decideChannelAction`) is identical for both.
11
+ */
12
+ import type { ChannelMessage } from "../gates";
13
+ import type { TelegramMessage, TelegramMessageEntity, TelegramUpdate } from "./api";
14
+ /** The bot's own identity, as `getMe` reports it. */
15
+ export interface TelegramBotIdentity {
16
+ id: number;
17
+ username?: string;
18
+ }
19
+ /** The message's text: plain text, or a photo/video/document caption. */
20
+ export declare function messageText(message: TelegramMessage): string;
21
+ /** Entities belong to whichever field carried the text — captions carry theirs on `caption_entities`. */
22
+ export declare function messageEntities(message: TelegramMessage): TelegramMessageEntity[];
23
+ /**
24
+ * Did this message address the bot? Three ways it can, all of which a human
25
+ * reader would call "addressed":
26
+ *
27
+ * - a `mention` entity whose text is the bot's `@username`;
28
+ * - a `text_mention` entity pointing at the bot's user id (how a mention
29
+ * arrives when the mentioned account has no username);
30
+ * - a `bot_command` entity suffixed with the bot's username (`/ask@mybot`),
31
+ * which is how Telegram disambiguates commands between several bots in one
32
+ * group.
33
+ *
34
+ * Username comparison is case-insensitive: Telegram treats `@MyBot` and
35
+ * `@mybot` as the same handle, and clients preserve whatever the sender typed.
36
+ */
37
+ export declare function mentionsBot(message: TelegramMessage, me: TelegramBotIdentity): boolean;
38
+ /**
39
+ * The {@link ChannelMessage} for an update, or `undefined` when there is
40
+ * nothing for a chat pipeline to look at: a non-message update, a channel post
41
+ * (which has no `from`, only a `sender_chat`), or a service message.
42
+ *
43
+ * A message with no text at all (a sticker, an uncaptioned photo) still maps —
44
+ * its blank text is dropped by `decideChannelAction` like any other, and
45
+ * mapping it keeps this function's rule simple: interpret the wire, let the
46
+ * gates decide policy.
47
+ */
48
+ export declare function toChannelMessage(update: TelegramUpdate, me: TelegramBotIdentity): ChannelMessage | undefined;
49
+ /**
50
+ * The `offset` to request next so `update` is never redelivered:
51
+ * `update_id + 1`, which is also how the Bot API acknowledges it (there is no
52
+ * separate ack call — see docs/telegram.md on offset persistence).
53
+ */
54
+ export declare function nextOffset(update: TelegramUpdate): number;
55
+ /**
56
+ * A stable identity key for `bucketsFor`/`personaResolver`/`answerFn`. Namespaced
57
+ * because a bare Telegram user id is a numeral with no channel in it — a host
58
+ * keying persona or spend state across several channels must not have one
59
+ * collide with a phone number or another transport's numeric id (the same
60
+ * reasoning as WhatsApp's explicit `lid:` marker).
61
+ */
62
+ export declare function telegramSenderKey(senderId: string): string;
63
+ //# sourceMappingURL=updates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updates.d.ts","sourceRoot":"","sources":["../../../src/channels/telegram/updates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEpF,qDAAqD;AACrD,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,yEAAyE;AACzE,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAE5D;AAED,yGAAyG;AACzG,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,qBAAqB,EAAE,CAEjF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,mBAAmB,GAAG,OAAO,CAYtF;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,cAAc,EACtB,EAAE,EAAE,mBAAmB,GACtB,cAAc,GAAG,SAAS,CAiB5B;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegoaltoworks/chatter",
3
- "version": "0.54.2",
3
+ "version": "0.55.0",
4
4
  "description": "Embeddable AI chatbot framework with RAG, authentication, and customizable widgets",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -63,6 +63,11 @@
63
63
  "import": "./dist/channels/whatsapp/index.mjs",
64
64
  "require": "./dist/channels/whatsapp/index.js"
65
65
  },
66
+ "./telegram": {
67
+ "types": "./dist/channels/telegram/index.d.ts",
68
+ "import": "./dist/channels/telegram/index.mjs",
69
+ "require": "./dist/channels/telegram/index.js"
70
+ },
66
71
  "./images": {
67
72
  "types": "./dist/images/index.d.ts",
68
73
  "import": "./dist/images/index.mjs",
@@ -83,7 +88,7 @@
83
88
  ],
84
89
  "scripts": {
85
90
  "dev": "bun --watch src/index.ts",
86
- "build": "bun run build:clean && bun run build:types && bun run build:esm && bun run build:cjs && bun run build:server && bun run build:mcp && bun run build:usage && bun run build:history && bun run build:personas && bun run build:channels && bun run build:whatsapp && bun run build:flows && bun run build:images && bun run build:scheduler && bun run build:bin && bun run build:client && bun run build:copy-client",
91
+ "build": "bun run build:clean && bun run build:types && bun run build:esm && bun run build:cjs && bun run build:server && bun run build:mcp && bun run build:usage && bun run build:history && bun run build:personas && bun run build:channels && bun run build:whatsapp && bun run build:telegram && bun run build:flows && bun run build:images && bun run build:scheduler && bun run build:bin && bun run build:client && bun run build:copy-client",
87
92
  "build:clean": "rm -rf dist",
88
93
  "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly --outDir dist",
89
94
  "build:esm": "esbuild src/index.ts --bundle --format=esm --outfile=dist/index.mjs --external:@hono/node-server --external:hono --external:openai --external:@libsql/client --external:jose --external:@modelcontextprotocol/sdk --external:zod --platform=node --target=node24",
@@ -95,6 +100,7 @@
95
100
  "build:personas": "esbuild src/personas/index.ts --bundle --format=esm --outfile=dist/personas/index.mjs --platform=node --target=node24 && esbuild src/personas/index.ts --bundle --format=cjs --outfile=dist/personas/index.js --platform=node --target=node24",
96
101
  "build:channels": "esbuild src/channels/index.ts --bundle --format=esm --outfile=dist/channels/index.mjs --external:hono --external:openai --external:@libsql/client --platform=node --target=node24 && esbuild src/channels/index.ts --bundle --format=cjs --outfile=dist/channels/index.js --external:hono --external:openai --external:@libsql/client --platform=node --target=node24",
97
102
  "build:whatsapp": "esbuild src/channels/whatsapp/index.ts --bundle --format=esm --outfile=dist/channels/whatsapp/index.mjs --external:@libsql/client --external:@whiskeysockets/baileys --platform=node --target=node24 && esbuild src/channels/whatsapp/index.ts --bundle --format=cjs --outfile=dist/channels/whatsapp/index.js --external:@libsql/client --external:@whiskeysockets/baileys --platform=node --target=node24",
103
+ "build:telegram": "esbuild src/channels/telegram/index.ts --bundle --format=esm --outfile=dist/channels/telegram/index.mjs --external:@libsql/client --external:openai --platform=node --target=node24 && esbuild src/channels/telegram/index.ts --bundle --format=cjs --outfile=dist/channels/telegram/index.js --external:@libsql/client --external:openai --platform=node --target=node24",
98
104
  "build:flows": "esbuild src/flows/index.ts --bundle --format=esm --outfile=dist/flows/index.mjs --external:@libsql/client --external:openai --platform=node --target=node24 && esbuild src/flows/index.ts --bundle --format=cjs --outfile=dist/flows/index.js --external:@libsql/client --external:openai --platform=node --target=node24",
99
105
  "build:images": "esbuild src/images/index.ts --bundle --format=esm --outfile=dist/images/index.mjs --external:@libsql/client --external:openai --platform=node --target=node24 && esbuild src/images/index.ts --bundle --format=cjs --outfile=dist/images/index.js --external:@libsql/client --external:openai --platform=node --target=node24",
100
106
  "build:scheduler": "esbuild src/scheduler/index.ts --bundle --format=esm --outfile=dist/scheduler/index.mjs --external:@libsql/client --external:openai --platform=node --target=node24 && esbuild src/scheduler/index.ts --bundle --format=cjs --outfile=dist/scheduler/index.js --external:@libsql/client --external:openai --platform=node --target=node24",