@mastra/telegram 0.2.0 → 0.2.1-alpha.1
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/dist/index.cjs +12 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -24200,7 +24200,7 @@ async function setMyCommands(botToken, options, apiBaseUrl = TELEGRAM_API_BASE_U
|
|
|
24200
24200
|
* @see https://core.telegram.org/bots/api#setwebhook
|
|
24201
24201
|
*/
|
|
24202
24202
|
function generateSecretToken() {
|
|
24203
|
-
return (
|
|
24203
|
+
return Buffer.from(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32))).toString("base64url");
|
|
24204
24204
|
}
|
|
24205
24205
|
//#endregion
|
|
24206
24206
|
//#region src/commands.ts
|
|
@@ -24269,8 +24269,8 @@ function isEncrypted(value) {
|
|
|
24269
24269
|
}
|
|
24270
24270
|
/** Encrypt a UTF-8 string with a per-value random salt + IV. */
|
|
24271
24271
|
function encrypt(plaintext, passphrase) {
|
|
24272
|
-
const salt = (
|
|
24273
|
-
const iv = (
|
|
24272
|
+
const salt = Buffer.from(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)));
|
|
24273
|
+
const iv = Buffer.from(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(12)));
|
|
24274
24274
|
const cipher = (0, crypto$1.createCipheriv)("aes-256-gcm", deriveKey(passphrase, salt), iv);
|
|
24275
24275
|
const enc = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
24276
24276
|
const tag = cipher.getAuthTag();
|
|
@@ -24631,11 +24631,11 @@ var TelegramProvider = class {
|
|
|
24631
24631
|
botToken = resolved;
|
|
24632
24632
|
} else botToken = options.botToken ?? this.#config.botToken;
|
|
24633
24633
|
if (!botToken) {
|
|
24634
|
-
const installationId = existing?.id ??
|
|
24634
|
+
const installationId = existing?.id ?? globalThis.crypto.randomUUID();
|
|
24635
24635
|
await store.save({
|
|
24636
24636
|
id: installationId,
|
|
24637
24637
|
agentId,
|
|
24638
|
-
webhookId: existing?.webhookId ??
|
|
24638
|
+
webhookId: existing?.webhookId ?? globalThis.crypto.randomUUID(),
|
|
24639
24639
|
status: "pending",
|
|
24640
24640
|
installedAt: existing?.installedAt ?? /* @__PURE__ */ new Date()
|
|
24641
24641
|
});
|
|
@@ -24648,18 +24648,14 @@ var TelegramProvider = class {
|
|
|
24648
24648
|
const baseUrl = this.#getBaseUrl();
|
|
24649
24649
|
const mode = this.#resolveMode(baseUrl);
|
|
24650
24650
|
if (mode === "webhook" && !baseUrl) throw new Error("TelegramProvider needs a baseUrl to register a webhook. Set `baseUrl`, configure the Mastra server, or use `mode: \"polling\"`.");
|
|
24651
|
-
if (
|
|
24652
|
-
|
|
24653
|
-
this.#connectingBotTokens.add(botToken);
|
|
24654
|
-
}
|
|
24651
|
+
if (this.#connectingBotTokens.has(botToken)) throw new Error("This Telegram bot is already being connected. Wait for that connection to finish.");
|
|
24652
|
+
this.#connectingBotTokens.add(botToken);
|
|
24655
24653
|
try {
|
|
24656
24654
|
const me = await getMe(botToken, this.#apiBaseUrl());
|
|
24657
|
-
|
|
24658
|
-
|
|
24659
|
-
|
|
24660
|
-
|
|
24661
|
-
const installationId = existing?.id ?? (0, crypto$1.randomUUID)();
|
|
24662
|
-
const webhookId = existing?.webhookId ?? (0, crypto$1.randomUUID)();
|
|
24655
|
+
const duplicate = (await store.list()).find((i) => i.status === "active" && i.agentId !== agentId && (i.botUserId !== void 0 ? i.botUserId === me.id : i.botToken === botToken));
|
|
24656
|
+
if (duplicate) throw new Error(`This Telegram bot is already connected to agent "${duplicate.agentId}". Disconnect it before connecting another agent.`);
|
|
24657
|
+
const installationId = existing?.id ?? globalThis.crypto.randomUUID();
|
|
24658
|
+
const webhookId = existing?.webhookId ?? globalThis.crypto.randomUUID();
|
|
24663
24659
|
const webhookUrl = mode === "webhook" ? `${baseUrl}/${PLATFORM}/events/${webhookId}` : void 0;
|
|
24664
24660
|
const commands = normalizeCommands(options.commands ?? this.#config.commands ?? DEFAULT_COMMANDS);
|
|
24665
24661
|
const installation = {
|
|
@@ -24686,7 +24682,7 @@ var TelegramProvider = class {
|
|
|
24686
24682
|
installationId
|
|
24687
24683
|
};
|
|
24688
24684
|
} finally {
|
|
24689
|
-
|
|
24685
|
+
this.#connectingBotTokens.delete(botToken);
|
|
24690
24686
|
}
|
|
24691
24687
|
}
|
|
24692
24688
|
/** Disconnect an agent from Telegram, removing its webhook and installation. */
|