@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.
- package/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -0
- package/package.json +1 -1
- package/src/adapters/telegram/index.ts +15 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @poncho-ai/messaging@0.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
[34mCLI[39m tsup v8.5.1
|
|
8
8
|
[34mCLI[39m Target: es2022
|
|
9
9
|
[34mESM[39m Build start
|
|
10
|
-
[32mESM[39m [1mdist/index.js [22m[32m44.
|
|
11
|
-
[32mESM[39m ⚡️ Build success in
|
|
10
|
+
[32mESM[39m [1mdist/index.js [22m[32m44.99 KB[39m
|
|
11
|
+
[32mESM[39m ⚡️ Build success in 69ms
|
|
12
12
|
[34mDTS[39m Build start
|
|
13
|
-
[32mDTS[39m ⚡️ Build success in
|
|
14
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
13
|
+
[32mDTS[39m ⚡️ Build success in 1830ms
|
|
14
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m10.05 KB[39m
|
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
|
@@ -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";
|