@poncho-ai/messaging 0.3.0 → 0.4.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @poncho-ai/messaging@0.3.0 build /Users/cesar/Dev/latitude/poncho-ai/packages/messaging
2
+ > @poncho-ai/messaging@0.4.0 build /Users/cesar/Dev/latitude/poncho-ai/packages/messaging
3
3
  > tsup src/index.ts --format esm --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -7,8 +7,8 @@
7
7
  CLI tsup v8.5.1
8
8
  CLI Target: es2022
9
9
  ESM Build start
10
- ESM dist/index.js 44.67 KB
11
- ESM ⚡️ Build success in 55ms
10
+ ESM dist/index.js 44.99 KB
11
+ ESM ⚡️ Build success in 69ms
12
12
  DTS Build start
13
- DTS ⚡️ Build success in 3450ms
14
- DTS dist/index.d.ts 9.98 KB
13
+ DTS ⚡️ Build success in 1830ms
14
+ DTS dist/index.d.ts 10.05 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @poncho-ai/messaging
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`3216e80`](https://github.com/cesr/poncho-ai/commit/3216e8072027896dd1cc5f29b1a7b0eea9ee1ff5) Thanks [@cesr](https://github.com/cesr)! - Add `allowedUserIds` option to Telegram adapter for restricting bot access to specific users.
8
+
3
9
  ## 0.3.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -192,6 +192,7 @@ declare class ResendAdapter implements MessagingAdapter {
192
192
  interface TelegramAdapterOptions {
193
193
  botTokenEnv?: string;
194
194
  webhookSecretEnv?: string;
195
+ allowedUserIds?: number[];
195
196
  }
196
197
  declare class TelegramAdapter implements MessagingAdapter {
197
198
  readonly platform: "telegram";
@@ -203,6 +204,7 @@ declare class TelegramAdapter implements MessagingAdapter {
203
204
  private botId;
204
205
  private readonly botTokenEnv;
205
206
  private readonly webhookSecretEnv;
207
+ private readonly allowedUserIds;
206
208
  private handler;
207
209
  private readonly sessionCounters;
208
210
  private lastUpdateId;
package/dist/index.js CHANGED
@@ -1136,12 +1136,14 @@ var TelegramAdapter = class {
1136
1136
  botId = 0;
1137
1137
  botTokenEnv;
1138
1138
  webhookSecretEnv;
1139
+ allowedUserIds;
1139
1140
  handler;
1140
1141
  sessionCounters = /* @__PURE__ */ new Map();
1141
1142
  lastUpdateId = 0;
1142
1143
  constructor(options = {}) {
1143
1144
  this.botTokenEnv = options.botTokenEnv ?? "TELEGRAM_BOT_TOKEN";
1144
1145
  this.webhookSecretEnv = options.webhookSecretEnv ?? "TELEGRAM_WEBHOOK_SECRET";
1146
+ this.allowedUserIds = options.allowedUserIds && options.allowedUserIds.length > 0 ? options.allowedUserIds : void 0;
1145
1147
  }
1146
1148
  // -----------------------------------------------------------------------
1147
1149
  // MessagingAdapter implementation
@@ -1247,6 +1249,13 @@ var TelegramAdapter = class {
1247
1249
  res.end();
1248
1250
  return;
1249
1251
  }
1252
+ if (this.allowedUserIds && message.from) {
1253
+ if (!this.allowedUserIds.includes(message.from.id)) {
1254
+ res.writeHead(200);
1255
+ res.end();
1256
+ return;
1257
+ }
1258
+ }
1250
1259
  const chatId = String(message.chat.id);
1251
1260
  const chatType = message.chat.type;
1252
1261
  const isGroup = chatType === "group" || chatType === "supergroup";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poncho-ai/messaging",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Messaging platform adapters for Poncho agents (Slack, Telegram, etc.)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,6 +29,7 @@ const NEW_COMMAND_RE = /^\/new(?:@(\S+))?$/i;
29
29
  export interface TelegramAdapterOptions {
30
30
  botTokenEnv?: string;
31
31
  webhookSecretEnv?: string;
32
+ allowedUserIds?: number[];
32
33
  }
33
34
 
34
35
  const collectBody = (req: http.IncomingMessage): Promise<string> =>
@@ -50,6 +51,7 @@ export class TelegramAdapter implements MessagingAdapter {
50
51
  private botId = 0;
51
52
  private readonly botTokenEnv: string;
52
53
  private readonly webhookSecretEnv: string;
54
+ private readonly allowedUserIds: number[] | undefined;
53
55
  private handler: IncomingMessageHandler | undefined;
54
56
  private readonly sessionCounters = new Map<string, number>();
55
57
  private lastUpdateId = 0;
@@ -58,6 +60,10 @@ export class TelegramAdapter implements MessagingAdapter {
58
60
  this.botTokenEnv = options.botTokenEnv ?? "TELEGRAM_BOT_TOKEN";
59
61
  this.webhookSecretEnv =
60
62
  options.webhookSecretEnv ?? "TELEGRAM_WEBHOOK_SECRET";
63
+ this.allowedUserIds =
64
+ options.allowedUserIds && options.allowedUserIds.length > 0
65
+ ? options.allowedUserIds
66
+ : undefined;
61
67
  }
62
68
 
63
69
  // -----------------------------------------------------------------------
@@ -197,6 +203,15 @@ export class TelegramAdapter implements MessagingAdapter {
197
203
  return;
198
204
  }
199
205
 
206
+ // -- User allowlist -----------------------------------------------------
207
+ if (this.allowedUserIds && message.from) {
208
+ if (!this.allowedUserIds.includes(message.from.id)) {
209
+ res.writeHead(200);
210
+ res.end();
211
+ return;
212
+ }
213
+ }
214
+
200
215
  const chatId = String(message.chat.id);
201
216
  const chatType = message.chat.type;
202
217
  const isGroup = chatType === "group" || chatType === "supergroup";