@mastra/telegram 0.1.2 → 0.1.3
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 +65 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +20 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -37
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -19375,7 +19375,7 @@ function isUint8Array(value) {
|
|
|
19375
19375
|
return Boolean(value && typeof value === "object" && "byteLength" in value && "byteOffset" in value);
|
|
19376
19376
|
}
|
|
19377
19377
|
//#endregion
|
|
19378
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/chat/4.40.0/
|
|
19378
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/chat/4.40.0/bf8128214e5ca45222a909d8e82dc4a6bbc779eb9b510d06add2841f98f9c957/node_modules/chat/dist/chunk-VB76CUI4.js
|
|
19379
19379
|
function isListNode(node) {
|
|
19380
19380
|
return node.type === "list";
|
|
19381
19381
|
}
|
|
@@ -20276,7 +20276,7 @@ var vn = (n, r) => {
|
|
|
20276
20276
|
};
|
|
20277
20277
|
var $e = vn;
|
|
20278
20278
|
//#endregion
|
|
20279
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/chat/4.40.0/
|
|
20279
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/chat/4.40.0/bf8128214e5ca45222a909d8e82dc4a6bbc779eb9b510d06add2841f98f9c957/node_modules/chat/dist/chunk-BKACWYIW.js
|
|
20280
20280
|
var adapterMap = /* @__PURE__ */ new WeakMap();
|
|
20281
20281
|
var Message = class _Message {
|
|
20282
20282
|
/** Unique message ID */
|
|
@@ -20687,7 +20687,7 @@ function wrapTablesForAppend(text2, closeFences = false) {
|
|
|
20687
20687
|
new AbortController().signal;
|
|
20688
20688
|
new async_hooks.AsyncLocalStorage();
|
|
20689
20689
|
//#endregion
|
|
20690
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/chat/4.40.0/
|
|
20690
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/chat/4.40.0/bf8128214e5ca45222a909d8e82dc4a6bbc779eb9b510d06add2841f98f9c957/node_modules/chat/dist/index.js
|
|
20691
20691
|
var emojiRegistry = /* @__PURE__ */ new Map();
|
|
20692
20692
|
function getEmoji(name) {
|
|
20693
20693
|
let emojiValue = emojiRegistry.get(name);
|
|
@@ -21353,7 +21353,7 @@ createEmoji();
|
|
|
21353
21353
|
var cardChildToFallbackText2 = cardChildToFallbackText;
|
|
21354
21354
|
var isCardElement2 = isCardElement;
|
|
21355
21355
|
//#endregion
|
|
21356
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@chat-adapter/shared/4.40.0/
|
|
21356
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@chat-adapter/shared/4.40.0/b8d1ffb3606d5fbc146955d209d67d901e1ac7e62c614258eabf21f6794389e3/node_modules/@chat-adapter/shared/dist/index.js
|
|
21357
21357
|
function extractCard(message) {
|
|
21358
21358
|
if (isCardElement2(message)) return message;
|
|
21359
21359
|
if (typeof message === "object" && message !== null && "card" in message) return message.card;
|
|
@@ -21493,7 +21493,7 @@ function blocklist(ranges, family) {
|
|
|
21493
21493
|
blocklist(IPV4, "ipv4");
|
|
21494
21494
|
blocklist(IPV6, "ipv6");
|
|
21495
21495
|
//#endregion
|
|
21496
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@chat-adapter/telegram/4.40.0/
|
|
21496
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@chat-adapter/telegram/4.40.0/117ee55721c79f2050c97f5568d59cc1a8a9476541dcbc8fcd32561f0bae25c7/node_modules/@chat-adapter/telegram/dist/index.js
|
|
21497
21497
|
var CALLBACK_DATA_PREFIX = "chat:";
|
|
21498
21498
|
var TELEGRAM_CALLBACK_DATA_LIMIT_BYTES = 64;
|
|
21499
21499
|
function convertLabel(label) {
|
|
@@ -24432,6 +24432,7 @@ var TelegramProvider = class {
|
|
|
24432
24432
|
/** Cached sync view of whether any active bot is registered (for {@link getInfo}). */
|
|
24433
24433
|
#configured = false;
|
|
24434
24434
|
#initPromise = null;
|
|
24435
|
+
#connectingBotTokens = /* @__PURE__ */ new Set();
|
|
24435
24436
|
constructor(config = {}) {
|
|
24436
24437
|
this.#config = config;
|
|
24437
24438
|
}
|
|
@@ -24480,7 +24481,7 @@ var TelegramProvider = class {
|
|
|
24480
24481
|
properties: {
|
|
24481
24482
|
botToken: {
|
|
24482
24483
|
type: "string",
|
|
24483
|
-
description: "BotFather bot token. Omit to
|
|
24484
|
+
description: "BotFather bot token. Omit to use the provider default token. If neither is set, returns a BotFather deep link."
|
|
24484
24485
|
},
|
|
24485
24486
|
name: {
|
|
24486
24487
|
type: "string",
|
|
@@ -24516,12 +24517,21 @@ var TelegramProvider = class {
|
|
|
24516
24517
|
}
|
|
24517
24518
|
}
|
|
24518
24519
|
/**
|
|
24519
|
-
* Update runtime provider settings.
|
|
24520
|
-
*
|
|
24521
|
-
*
|
|
24520
|
+
* Update runtime provider settings. Pass `botToken` to change the default
|
|
24521
|
+
* bot token new {@link connect} calls fall back to when none is supplied
|
|
24522
|
+
* per-agent (matching {@link SlackProvider.configure}'s rotation pattern);
|
|
24523
|
+
* pass `apiBaseUrl`/`baseUrl` to point the adapter at a different host.
|
|
24524
|
+
* `null` clears the default `botToken` only — per-bot installs are managed
|
|
24525
|
+
* via {@link connect}/{@link disconnect}.
|
|
24522
24526
|
*/
|
|
24523
24527
|
async configure(credentials) {
|
|
24524
|
-
if (credentials === null)
|
|
24528
|
+
if (credentials === null) {
|
|
24529
|
+
this.#config = {
|
|
24530
|
+
...this.#config,
|
|
24531
|
+
botToken: void 0
|
|
24532
|
+
};
|
|
24533
|
+
return;
|
|
24534
|
+
}
|
|
24525
24535
|
const apiBaseUrlChanged = credentials.apiBaseUrl !== void 0 && credentials.apiBaseUrl !== this.#config.apiBaseUrl;
|
|
24526
24536
|
this.#config = {
|
|
24527
24537
|
...this.#config,
|
|
@@ -24541,17 +24551,18 @@ var TelegramProvider = class {
|
|
|
24541
24551
|
/**
|
|
24542
24552
|
* Connect an agent to a Telegram bot.
|
|
24543
24553
|
*
|
|
24544
|
-
* - With `options.botToken
|
|
24545
|
-
* secret, persist the installation, register the
|
|
24546
|
-
* polling), and return `{ type: 'immediate' }`.
|
|
24547
|
-
* - Without
|
|
24554
|
+
* - With `options.botToken` or a provider default token: validate via `getMe`,
|
|
24555
|
+
* mint a per-bot webhook secret, persist the installation, register the
|
|
24556
|
+
* transport (webhook or polling), and return `{ type: 'immediate' }`.
|
|
24557
|
+
* - Without either token: persist a pending installation and return
|
|
24548
24558
|
* `{ type: 'deep_link' }` pointing at BotFather.
|
|
24549
24559
|
*/
|
|
24550
24560
|
async connect(agentId, options = {}) {
|
|
24551
24561
|
const store = await this.#getStore();
|
|
24552
24562
|
const existing = await store.getByAgent(agentId);
|
|
24553
24563
|
if (existing?.status === "active") throw new Error(`Agent "${agentId}" is already connected to Telegram. Disconnect first to reconnect.`);
|
|
24554
|
-
|
|
24564
|
+
const botToken = options.botToken ?? this.#config.botToken;
|
|
24565
|
+
if (!botToken) {
|
|
24555
24566
|
const installationId = existing?.id ?? (0, crypto$1.randomUUID)();
|
|
24556
24567
|
await store.save({
|
|
24557
24568
|
id: installationId,
|
|
@@ -24566,36 +24577,48 @@ var TelegramProvider = class {
|
|
|
24566
24577
|
installationId
|
|
24567
24578
|
};
|
|
24568
24579
|
}
|
|
24569
|
-
const me = await getMe(options.botToken, this.#apiBaseUrl());
|
|
24570
|
-
const installationId = existing?.id ?? (0, crypto$1.randomUUID)();
|
|
24571
|
-
const webhookId = existing?.webhookId ?? (0, crypto$1.randomUUID)();
|
|
24572
24580
|
const baseUrl = this.#getBaseUrl();
|
|
24573
24581
|
const mode = this.#resolveMode(baseUrl);
|
|
24574
24582
|
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\"`.");
|
|
24575
|
-
|
|
24576
|
-
|
|
24577
|
-
|
|
24578
|
-
|
|
24579
|
-
|
|
24580
|
-
|
|
24581
|
-
|
|
24582
|
-
|
|
24583
|
-
|
|
24584
|
-
|
|
24585
|
-
|
|
24586
|
-
|
|
24587
|
-
|
|
24588
|
-
|
|
24589
|
-
|
|
24590
|
-
|
|
24591
|
-
|
|
24592
|
-
|
|
24593
|
-
|
|
24594
|
-
|
|
24595
|
-
|
|
24596
|
-
|
|
24597
|
-
|
|
24598
|
-
|
|
24583
|
+
if (mode === "webhook") {
|
|
24584
|
+
if (this.#connectingBotTokens.has(botToken)) throw new Error("This Telegram bot is already being connected. Wait for that connection to finish.");
|
|
24585
|
+
this.#connectingBotTokens.add(botToken);
|
|
24586
|
+
}
|
|
24587
|
+
try {
|
|
24588
|
+
if (mode === "webhook") {
|
|
24589
|
+
const duplicate = (await store.list()).find((i) => i.status === "active" && i.botToken === botToken);
|
|
24590
|
+
if (duplicate) throw new Error(`This Telegram bot is already connected to agent "${duplicate.agentId}". Disconnect it before connecting another agent.`);
|
|
24591
|
+
}
|
|
24592
|
+
const me = await getMe(botToken, this.#apiBaseUrl());
|
|
24593
|
+
const installationId = existing?.id ?? (0, crypto$1.randomUUID)();
|
|
24594
|
+
const webhookId = existing?.webhookId ?? (0, crypto$1.randomUUID)();
|
|
24595
|
+
const webhookUrl = mode === "webhook" ? `${baseUrl}/${PLATFORM}/events/${webhookId}` : void 0;
|
|
24596
|
+
const commands = normalizeCommands(options.commands ?? this.#config.commands ?? DEFAULT_COMMANDS);
|
|
24597
|
+
const installation = {
|
|
24598
|
+
id: installationId,
|
|
24599
|
+
agentId,
|
|
24600
|
+
webhookId,
|
|
24601
|
+
status: "active",
|
|
24602
|
+
botToken,
|
|
24603
|
+
secretToken: generateSecretToken(),
|
|
24604
|
+
username: options.name ?? me.username ?? me.first_name,
|
|
24605
|
+
webhookUrl,
|
|
24606
|
+
commands: commands.length ? commands : void 0,
|
|
24607
|
+
installedAt: existing?.installedAt ?? /* @__PURE__ */ new Date()
|
|
24608
|
+
};
|
|
24609
|
+
await this.#registerTransport(installation, mode);
|
|
24610
|
+
await this.#registerCommands(installation);
|
|
24611
|
+
await store.save(installation);
|
|
24612
|
+
await this.#activateInstallation(installation);
|
|
24613
|
+
this.#configured = true;
|
|
24614
|
+
await this.#config.onInstall?.(installation);
|
|
24615
|
+
return {
|
|
24616
|
+
type: "immediate",
|
|
24617
|
+
installationId
|
|
24618
|
+
};
|
|
24619
|
+
} finally {
|
|
24620
|
+
if (mode === "webhook") this.#connectingBotTokens.delete(botToken);
|
|
24621
|
+
}
|
|
24599
24622
|
}
|
|
24600
24623
|
/** Disconnect an agent from Telegram, removing its webhook and installation. */
|
|
24601
24624
|
async disconnect(agentId) {
|