@framers/agentos-ext-telegram-bot 1.1.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/dist/config.d.ts +56 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +170 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +115 -0
- package/dist/index.js.map +1 -0
- package/dist/services/telegramBot.d.ts +129 -0
- package/dist/services/telegramBot.d.ts.map +1 -0
- package/dist/services/telegramBot.js +276 -0
- package/dist/services/telegramBot.js.map +1 -0
- package/dist/tools/sendMessage.d.ts +116 -0
- package/dist/tools/sendMessage.d.ts.map +1 -0
- package/dist/tools/sendMessage.js +155 -0
- package/dist/tools/sendMessage.js.map +1 -0
- package/manifest.json +94 -0
- package/package.json +76 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for Telegram Bot extension
|
|
3
|
+
* Supports loading from options, environment variables, and .env files
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Telegram bot configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface TelegramConfig {
|
|
9
|
+
botToken: string;
|
|
10
|
+
defaultParseMode: 'Markdown' | 'HTML' | 'MarkdownV2';
|
|
11
|
+
pollingInterval: number;
|
|
12
|
+
maxRetries: number;
|
|
13
|
+
priority?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Loads configuration from multiple sources with priority:
|
|
17
|
+
* 1. Direct options (highest priority)
|
|
18
|
+
* 2. Environment variables
|
|
19
|
+
* 3. .env file (lowest priority)
|
|
20
|
+
*
|
|
21
|
+
* @param {Partial<TelegramConfig>} options - Direct configuration options
|
|
22
|
+
* @returns {TelegramConfig} Complete configuration
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Priority order: options > env vars > .env file
|
|
27
|
+
* const config = loadConfig({
|
|
28
|
+
* botToken: undefined, // Will check env vars
|
|
29
|
+
* defaultParseMode: 'HTML' // Direct override
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadConfig(options?: Partial<TelegramConfig>): TelegramConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Gets API key from multiple sources
|
|
36
|
+
* Useful for tools that need to check for API keys dynamically
|
|
37
|
+
*
|
|
38
|
+
* @param {string} keyName - Name of the key to look for
|
|
39
|
+
* @param {Record<string, any>} [options] - Optional direct configuration
|
|
40
|
+
* @returns {string | undefined} The API key if found
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const token = getApiKey('botToken', options);
|
|
45
|
+
* const apiKey = getApiKey('TELEGRAM_API_KEY');
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function getApiKey(keyName: string, options?: Record<string, any>): string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Validates that all required configuration is present
|
|
51
|
+
*
|
|
52
|
+
* @param {Partial<TelegramConfig>} config - Configuration to validate
|
|
53
|
+
* @throws {Error} If required configuration is missing
|
|
54
|
+
*/
|
|
55
|
+
export declare function validateConfig(config: Partial<TelegramConfig>): asserts config is TelegramConfig;
|
|
56
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,UAAU,GAAG,MAAM,GAAG,YAAY,CAAC;IACrD,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA6BD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,OAAO,CAAC,cAAc,CAAM,GAAG,cAAc,CAkChF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,MAAM,GAAG,SAAS,CAqBpB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAsBhG"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration management for Telegram Bot extension
|
|
4
|
+
* Supports loading from options, environment variables, and .env files
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.loadConfig = loadConfig;
|
|
41
|
+
exports.getApiKey = getApiKey;
|
|
42
|
+
exports.validateConfig = validateConfig;
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const dotenv_1 = require("dotenv");
|
|
46
|
+
/**
|
|
47
|
+
* Attempts to find and load .env file from various locations
|
|
48
|
+
*
|
|
49
|
+
* @private
|
|
50
|
+
* @returns {void}
|
|
51
|
+
*/
|
|
52
|
+
function loadDotEnv() {
|
|
53
|
+
const possiblePaths = [
|
|
54
|
+
'.env',
|
|
55
|
+
'../.env',
|
|
56
|
+
'../../.env',
|
|
57
|
+
'../../../.env',
|
|
58
|
+
'../../../../.env',
|
|
59
|
+
'../../../../../.env', // Root of monorepo
|
|
60
|
+
path.join(process.cwd(), '.env'),
|
|
61
|
+
path.join(process.cwd(), '..', '.env'),
|
|
62
|
+
path.join(process.cwd(), '..', '..', '.env'),
|
|
63
|
+
];
|
|
64
|
+
for (const envPath of possiblePaths) {
|
|
65
|
+
if (fs.existsSync(envPath)) {
|
|
66
|
+
(0, dotenv_1.config)({ path: envPath });
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Loads configuration from multiple sources with priority:
|
|
73
|
+
* 1. Direct options (highest priority)
|
|
74
|
+
* 2. Environment variables
|
|
75
|
+
* 3. .env file (lowest priority)
|
|
76
|
+
*
|
|
77
|
+
* @param {Partial<TelegramConfig>} options - Direct configuration options
|
|
78
|
+
* @returns {TelegramConfig} Complete configuration
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // Priority order: options > env vars > .env file
|
|
83
|
+
* const config = loadConfig({
|
|
84
|
+
* botToken: undefined, // Will check env vars
|
|
85
|
+
* defaultParseMode: 'HTML' // Direct override
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
function loadConfig(options = {}) {
|
|
90
|
+
// Try to load .env file if it exists
|
|
91
|
+
loadDotEnv();
|
|
92
|
+
// Build config with priority: options > env > defaults
|
|
93
|
+
const config = {
|
|
94
|
+
botToken: options.botToken ||
|
|
95
|
+
process.env.TELEGRAM_BOT_TOKEN ||
|
|
96
|
+
process.env.TG_BOT_TOKEN ||
|
|
97
|
+
'',
|
|
98
|
+
defaultParseMode: options.defaultParseMode ||
|
|
99
|
+
process.env.TELEGRAM_PARSE_MODE ||
|
|
100
|
+
'Markdown',
|
|
101
|
+
pollingInterval: options.pollingInterval ||
|
|
102
|
+
parseInt(process.env.TELEGRAM_POLLING_INTERVAL || '1000'),
|
|
103
|
+
maxRetries: options.maxRetries ||
|
|
104
|
+
parseInt(process.env.TELEGRAM_MAX_RETRIES || '3'),
|
|
105
|
+
priority: options.priority
|
|
106
|
+
};
|
|
107
|
+
// Validate parse mode
|
|
108
|
+
if (!['Markdown', 'HTML', 'MarkdownV2'].includes(config.defaultParseMode)) {
|
|
109
|
+
config.defaultParseMode = 'Markdown';
|
|
110
|
+
}
|
|
111
|
+
return config;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Gets API key from multiple sources
|
|
115
|
+
* Useful for tools that need to check for API keys dynamically
|
|
116
|
+
*
|
|
117
|
+
* @param {string} keyName - Name of the key to look for
|
|
118
|
+
* @param {Record<string, any>} [options] - Optional direct configuration
|
|
119
|
+
* @returns {string | undefined} The API key if found
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const token = getApiKey('botToken', options);
|
|
124
|
+
* const apiKey = getApiKey('TELEGRAM_API_KEY');
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
function getApiKey(keyName, options) {
|
|
128
|
+
// Check options first
|
|
129
|
+
if (options && options[keyName]) {
|
|
130
|
+
return options[keyName];
|
|
131
|
+
}
|
|
132
|
+
// Check environment variables
|
|
133
|
+
const envKeys = [
|
|
134
|
+
keyName,
|
|
135
|
+
keyName.toUpperCase(),
|
|
136
|
+
`TELEGRAM_${keyName.toUpperCase()}`,
|
|
137
|
+
`TG_${keyName.toUpperCase()}`
|
|
138
|
+
];
|
|
139
|
+
for (const envKey of envKeys) {
|
|
140
|
+
if (process.env[envKey]) {
|
|
141
|
+
return process.env[envKey];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Validates that all required configuration is present
|
|
148
|
+
*
|
|
149
|
+
* @param {Partial<TelegramConfig>} config - Configuration to validate
|
|
150
|
+
* @throws {Error} If required configuration is missing
|
|
151
|
+
*/
|
|
152
|
+
function validateConfig(config) {
|
|
153
|
+
if (!config.botToken) {
|
|
154
|
+
throw new Error('Telegram bot token is required. Set it via:\n' +
|
|
155
|
+
' 1. options.botToken in extension configuration\n' +
|
|
156
|
+
' 2. TELEGRAM_BOT_TOKEN environment variable\n' +
|
|
157
|
+
' 3. .env file with TELEGRAM_BOT_TOKEN=your_token\n' +
|
|
158
|
+
'\nGet a bot token from @BotFather on Telegram');
|
|
159
|
+
}
|
|
160
|
+
if (!config.defaultParseMode) {
|
|
161
|
+
throw new Error('Default parse mode is required');
|
|
162
|
+
}
|
|
163
|
+
if (typeof config.pollingInterval !== 'number' || config.pollingInterval < 100) {
|
|
164
|
+
throw new Error('Polling interval must be at least 100ms');
|
|
165
|
+
}
|
|
166
|
+
if (typeof config.maxRetries !== 'number' || config.maxRetries < 0) {
|
|
167
|
+
throw new Error('Max retries must be non-negative');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DH,gCAkCC;AAgBD,8BAwBC;AAQD,wCAsBC;AApKD,uCAAyB;AACzB,2CAA6B;AAC7B,mCAAgD;AAahD;;;;;GAKG;AACH,SAAS,UAAU;IACjB,MAAM,aAAa,GAAG;QACpB,MAAM;QACN,SAAS;QACT,YAAY;QACZ,eAAe;QACf,kBAAkB;QAClB,qBAAqB,EAAE,mBAAmB;QAC1C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;KAC7C,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACpC,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,IAAA,eAAY,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YAChC,MAAM;QACR,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,UAAU,CAAC,UAAmC,EAAE;IAC9D,qCAAqC;IACrC,UAAU,EAAE,CAAC;IAEb,uDAAuD;IACvD,MAAM,MAAM,GAAm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AM,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,MAA+B;IAC5D,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,+CAA+C;YAC/C,oDAAoD;YACpD,gDAAgD;YAChD,qDAAqD;YACrD,+CAA+C,CAChD,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,QAAQ,IAAI,MAAM,CAAC,eAAe,GAAG,GAAG,EAAE,CAAC;QAC/E,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Bot Extension for AgentOS
|
|
3
|
+
*
|
|
4
|
+
* Provides comprehensive Telegram Bot API integration for AgentOS agents.
|
|
5
|
+
*
|
|
6
|
+
* @module @framers/agentos-communications-telegram
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @license MIT
|
|
9
|
+
*/
|
|
10
|
+
import { ExtensionContext, ExtensionPack } from '@framers/agentos';
|
|
11
|
+
import { SendMessageTool } from './tools/sendMessage';
|
|
12
|
+
import { SendPhotoTool } from './tools/sendPhoto';
|
|
13
|
+
import { SendDocumentTool } from './tools/sendDocument';
|
|
14
|
+
import { ManageChatTool } from './tools/manageChat';
|
|
15
|
+
import { PollMessagesTool } from './tools/pollMessages';
|
|
16
|
+
/**
|
|
17
|
+
* Extension configuration options
|
|
18
|
+
*/
|
|
19
|
+
export interface TelegramExtensionOptions {
|
|
20
|
+
/** Telegram Bot token - can be provided directly or via env var */
|
|
21
|
+
botToken?: string;
|
|
22
|
+
/** Default parse mode for messages */
|
|
23
|
+
defaultParseMode?: 'Markdown' | 'HTML' | 'MarkdownV2';
|
|
24
|
+
/** Polling interval in ms */
|
|
25
|
+
pollingInterval?: number;
|
|
26
|
+
/** Max retry attempts */
|
|
27
|
+
maxRetries?: number;
|
|
28
|
+
/** Extension priority */
|
|
29
|
+
priority?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates the Telegram Bot extension pack
|
|
33
|
+
*
|
|
34
|
+
* @param {ExtensionContext} context - The extension context
|
|
35
|
+
* @returns {ExtensionPack} The configured extension pack
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { createExtensionPack } from '@framers/agentos-communications-telegram';
|
|
40
|
+
*
|
|
41
|
+
* const pack = createExtensionPack({
|
|
42
|
+
* options: {
|
|
43
|
+
* botToken: process.env.TELEGRAM_BOT_TOKEN,
|
|
44
|
+
* defaultParseMode: 'Markdown'
|
|
45
|
+
* },
|
|
46
|
+
* logger: console
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function createExtensionPack(context: ExtensionContext): ExtensionPack;
|
|
51
|
+
export { SendMessageTool, SendPhotoTool, SendDocumentTool, ManageChatTool, PollMessagesTool };
|
|
52
|
+
export { TelegramBotService } from './services/telegramBot';
|
|
53
|
+
export type { TelegramConfig } from './config';
|
|
54
|
+
export default createExtensionPack;
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAIxD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,gBAAgB,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,YAAY,CAAC;IACtD,6BAA6B;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAsE5E;AAGD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,eAAe,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Telegram Bot Extension for AgentOS
|
|
4
|
+
*
|
|
5
|
+
* Provides comprehensive Telegram Bot API integration for AgentOS agents.
|
|
6
|
+
*
|
|
7
|
+
* @module @framers/agentos-communications-telegram
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TelegramBotService = exports.PollMessagesTool = exports.ManageChatTool = exports.SendDocumentTool = exports.SendPhotoTool = exports.SendMessageTool = void 0;
|
|
13
|
+
exports.createExtensionPack = createExtensionPack;
|
|
14
|
+
const sendMessage_1 = require("./tools/sendMessage");
|
|
15
|
+
Object.defineProperty(exports, "SendMessageTool", { enumerable: true, get: function () { return sendMessage_1.SendMessageTool; } });
|
|
16
|
+
const sendPhoto_1 = require("./tools/sendPhoto");
|
|
17
|
+
Object.defineProperty(exports, "SendPhotoTool", { enumerable: true, get: function () { return sendPhoto_1.SendPhotoTool; } });
|
|
18
|
+
const sendDocument_1 = require("./tools/sendDocument");
|
|
19
|
+
Object.defineProperty(exports, "SendDocumentTool", { enumerable: true, get: function () { return sendDocument_1.SendDocumentTool; } });
|
|
20
|
+
const manageChat_1 = require("./tools/manageChat");
|
|
21
|
+
Object.defineProperty(exports, "ManageChatTool", { enumerable: true, get: function () { return manageChat_1.ManageChatTool; } });
|
|
22
|
+
const pollMessages_1 = require("./tools/pollMessages");
|
|
23
|
+
Object.defineProperty(exports, "PollMessagesTool", { enumerable: true, get: function () { return pollMessages_1.PollMessagesTool; } });
|
|
24
|
+
const telegramBot_1 = require("./services/telegramBot");
|
|
25
|
+
const config_1 = require("./config");
|
|
26
|
+
/**
|
|
27
|
+
* Creates the Telegram Bot extension pack
|
|
28
|
+
*
|
|
29
|
+
* @param {ExtensionContext} context - The extension context
|
|
30
|
+
* @returns {ExtensionPack} The configured extension pack
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createExtensionPack } from '@framers/agentos-communications-telegram';
|
|
35
|
+
*
|
|
36
|
+
* const pack = createExtensionPack({
|
|
37
|
+
* options: {
|
|
38
|
+
* botToken: process.env.TELEGRAM_BOT_TOKEN,
|
|
39
|
+
* defaultParseMode: 'Markdown'
|
|
40
|
+
* },
|
|
41
|
+
* logger: console
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function createExtensionPack(context) {
|
|
46
|
+
// Load configuration from options, env vars, or .env file
|
|
47
|
+
const config = (0, config_1.loadConfig)(context.options || {});
|
|
48
|
+
if (!config.botToken) {
|
|
49
|
+
throw new Error('Telegram bot token is required. Set via options, TELEGRAM_BOT_TOKEN env var, or .env file');
|
|
50
|
+
}
|
|
51
|
+
// Initialize bot service
|
|
52
|
+
const botService = new telegramBot_1.TelegramBotService(config);
|
|
53
|
+
// Create tool instances
|
|
54
|
+
const sendMessageTool = new sendMessage_1.SendMessageTool(botService);
|
|
55
|
+
const sendPhotoTool = new sendPhoto_1.SendPhotoTool(botService);
|
|
56
|
+
const sendDocumentTool = new sendDocument_1.SendDocumentTool(botService);
|
|
57
|
+
const manageChatTool = new manageChat_1.ManageChatTool(botService);
|
|
58
|
+
const pollMessagesTool = new pollMessages_1.PollMessagesTool(botService);
|
|
59
|
+
const priority = config.priority || 50;
|
|
60
|
+
return {
|
|
61
|
+
name: '@framers/agentos-communications-telegram',
|
|
62
|
+
version: '1.0.0',
|
|
63
|
+
descriptors: [
|
|
64
|
+
{
|
|
65
|
+
id: 'telegramSendMessage',
|
|
66
|
+
kind: 'tool',
|
|
67
|
+
priority,
|
|
68
|
+
payload: sendMessageTool
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'telegramSendPhoto',
|
|
72
|
+
kind: 'tool',
|
|
73
|
+
priority,
|
|
74
|
+
payload: sendPhotoTool
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'telegramSendDocument',
|
|
78
|
+
kind: 'tool',
|
|
79
|
+
priority,
|
|
80
|
+
payload: sendDocumentTool
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'telegramManageChat',
|
|
84
|
+
kind: 'tool',
|
|
85
|
+
priority,
|
|
86
|
+
payload: manageChatTool
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'telegramPollMessages',
|
|
90
|
+
kind: 'tool',
|
|
91
|
+
priority,
|
|
92
|
+
payload: pollMessagesTool
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
/**
|
|
96
|
+
* Called when extension is activated
|
|
97
|
+
*/
|
|
98
|
+
onActivate: async () => {
|
|
99
|
+
await botService.initialize();
|
|
100
|
+
context.logger?.info('Telegram Bot Extension activated');
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* Called when extension is deactivated
|
|
104
|
+
*/
|
|
105
|
+
onDeactivate: async () => {
|
|
106
|
+
await botService.shutdown();
|
|
107
|
+
context.logger?.info('Telegram Bot Extension deactivated');
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
var telegramBot_2 = require("./services/telegramBot");
|
|
112
|
+
Object.defineProperty(exports, "TelegramBotService", { enumerable: true, get: function () { return telegramBot_2.TelegramBotService; } });
|
|
113
|
+
// Default export
|
|
114
|
+
exports.default = createExtensionPack;
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AA8CH,kDAsEC;AAjHD,qDAAsD;AAoH7C,gGApHA,6BAAe,OAoHA;AAnHxB,iDAAkD;AAmHxB,8FAnHjB,yBAAa,OAmHiB;AAlHvC,uDAAwD;AAkHf,iGAlHhC,+BAAgB,OAkHgC;AAjHzD,mDAAoD;AAiHO,+FAjHlD,2BAAc,OAiHkD;AAhHzE,uDAAwD;AAgHmB,iGAhHlE,+BAAgB,OAgHkE;AA/G3F,wDAA4D;AAC5D,qCAAsC;AAkBtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,mBAAmB,CAAC,OAAyB;IAC3D,0DAA0D;IAC1D,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,OAAO,CAAC,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UAAU,EAAE,KAAK,IAAI,EAAE;YACrB,MAAM,UAAU,CAAC,UAAU,EAAE,CAAC;YAC9B,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,kCAAkC,CAAC,CAAC;QAC3D,CAAC;QACD;;WAEG;QACH,YAAY,EAAE,KAAK,IAAI,EAAE;YACvB,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,oCAAoC,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC;AAID,sDAA4D;AAAnD,iHAAA,kBAAkB,OAAA;AAG3B,iBAAiB;AACjB,kBAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Bot service for managing bot instance and API calls
|
|
3
|
+
*/
|
|
4
|
+
import TelegramBot from 'node-telegram-bot-api';
|
|
5
|
+
import { TelegramConfig } from '../config';
|
|
6
|
+
/**
|
|
7
|
+
* Message send options
|
|
8
|
+
*/
|
|
9
|
+
export interface SendMessageOptions {
|
|
10
|
+
chatId: string | number;
|
|
11
|
+
text: string;
|
|
12
|
+
parseMode?: 'Markdown' | 'HTML' | 'MarkdownV2';
|
|
13
|
+
disableNotification?: boolean;
|
|
14
|
+
replyToMessageId?: number;
|
|
15
|
+
replyMarkup?: any;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Photo send options
|
|
19
|
+
*/
|
|
20
|
+
export interface SendPhotoOptions {
|
|
21
|
+
chatId: string | number;
|
|
22
|
+
photo: string | Buffer;
|
|
23
|
+
caption?: string;
|
|
24
|
+
parseMode?: 'Markdown' | 'HTML' | 'MarkdownV2';
|
|
25
|
+
disableNotification?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Service for interacting with Telegram Bot API
|
|
29
|
+
*
|
|
30
|
+
* @class TelegramBotService
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const service = new TelegramBotService(config);
|
|
35
|
+
* await service.initialize();
|
|
36
|
+
* await service.sendMessage({
|
|
37
|
+
* chatId: '@mychannel',
|
|
38
|
+
* text: 'Hello from AgentOS!'
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class TelegramBotService {
|
|
43
|
+
private bot;
|
|
44
|
+
private config;
|
|
45
|
+
private retryAttempts;
|
|
46
|
+
/**
|
|
47
|
+
* Creates an instance of TelegramBotService
|
|
48
|
+
*
|
|
49
|
+
* @param {TelegramConfig} config - Bot configuration
|
|
50
|
+
*/
|
|
51
|
+
constructor(config: TelegramConfig);
|
|
52
|
+
/**
|
|
53
|
+
* Initializes the bot instance
|
|
54
|
+
*
|
|
55
|
+
* @returns {Promise<void>}
|
|
56
|
+
*/
|
|
57
|
+
initialize(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Sends a text message
|
|
60
|
+
*
|
|
61
|
+
* @param {SendMessageOptions} options - Message options
|
|
62
|
+
* @returns {Promise<any>} Sent message object
|
|
63
|
+
*/
|
|
64
|
+
sendMessage(options: SendMessageOptions): Promise<any>;
|
|
65
|
+
/**
|
|
66
|
+
* Sends a photo
|
|
67
|
+
*
|
|
68
|
+
* @param {SendPhotoOptions} options - Photo options
|
|
69
|
+
* @returns {Promise<any>} Sent message object
|
|
70
|
+
*/
|
|
71
|
+
sendPhoto(options: SendPhotoOptions): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Sends a document
|
|
74
|
+
*
|
|
75
|
+
* @param {Object} options - Document options
|
|
76
|
+
* @returns {Promise<any>} Sent message object
|
|
77
|
+
*/
|
|
78
|
+
sendDocument(options: {
|
|
79
|
+
chatId: string | number;
|
|
80
|
+
document: string | Buffer;
|
|
81
|
+
caption?: string;
|
|
82
|
+
parseMode?: string;
|
|
83
|
+
}): Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* Gets information about a chat
|
|
86
|
+
*
|
|
87
|
+
* @param {string | number} chatId - Chat identifier
|
|
88
|
+
* @returns {Promise<any>} Chat information
|
|
89
|
+
*/
|
|
90
|
+
getChatInfo(chatId: string | number): Promise<any>;
|
|
91
|
+
/**
|
|
92
|
+
* Pins a message in a chat
|
|
93
|
+
*
|
|
94
|
+
* @param {string | number} chatId - Chat identifier
|
|
95
|
+
* @param {number} messageId - Message to pin
|
|
96
|
+
* @param {boolean} disableNotification - Silent pin
|
|
97
|
+
* @returns {Promise<any>} Operation result
|
|
98
|
+
*/
|
|
99
|
+
pinMessage(chatId: string | number, messageId: number, disableNotification?: boolean): Promise<any>;
|
|
100
|
+
/**
|
|
101
|
+
* Gets recent messages from a chat (if using polling)
|
|
102
|
+
*
|
|
103
|
+
* @param {string | number} chatId - Chat identifier
|
|
104
|
+
* @param {number} limit - Number of messages to retrieve
|
|
105
|
+
* @returns {Promise<any[]>} Recent messages
|
|
106
|
+
*/
|
|
107
|
+
getRecentMessages(chatId: string | number, limit?: number): Promise<any[]>;
|
|
108
|
+
/**
|
|
109
|
+
* Retries an operation with exponential backoff
|
|
110
|
+
*
|
|
111
|
+
* @private
|
|
112
|
+
* @param {Function} operation - Operation to retry
|
|
113
|
+
* @returns {Promise<any>} Operation result
|
|
114
|
+
*/
|
|
115
|
+
private retryOperation;
|
|
116
|
+
/**
|
|
117
|
+
* Shuts down the bot service
|
|
118
|
+
*
|
|
119
|
+
* @returns {Promise<void>}
|
|
120
|
+
*/
|
|
121
|
+
shutdown(): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Gets the bot instance (for advanced operations)
|
|
124
|
+
*
|
|
125
|
+
* @returns {TelegramBot | null} Bot instance
|
|
126
|
+
*/
|
|
127
|
+
getBotInstance(): TelegramBot | null;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=telegramBot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegramBot.d.ts","sourceRoot":"","sources":["../../src/services/telegramBot.ts"],"names":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CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,CAAC;IA4BhB;;;;;OAKG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAwBxD;;;;;;;OAOG;IACG,UAAU,CACd,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,mBAAmB,UAAQ,GAC1B,OAAO,CAAC,GAAG,CAAC;IAmBf;;;;;;OAMG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,SAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAY5E;;;;;;OAMG;YACW,cAAc;IAoB5B;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAS/B;;;;OAIG;IACH,cAAc,IAAI,WAAW,GAAG,IAAI;CAGrC"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Telegram Bot service for managing bot instance and API calls
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TelegramBotService = void 0;
|
|
10
|
+
const node_telegram_bot_api_1 = __importDefault(require("node-telegram-bot-api"));
|
|
11
|
+
/**
|
|
12
|
+
* Service for interacting with Telegram Bot API
|
|
13
|
+
*
|
|
14
|
+
* @class TelegramBotService
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const service = new TelegramBotService(config);
|
|
19
|
+
* await service.initialize();
|
|
20
|
+
* await service.sendMessage({
|
|
21
|
+
* chatId: '@mychannel',
|
|
22
|
+
* text: 'Hello from AgentOS!'
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
class TelegramBotService {
|
|
27
|
+
bot = null;
|
|
28
|
+
config;
|
|
29
|
+
retryAttempts = new Map();
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of TelegramBotService
|
|
32
|
+
*
|
|
33
|
+
* @param {TelegramConfig} config - Bot configuration
|
|
34
|
+
*/
|
|
35
|
+
constructor(config) {
|
|
36
|
+
this.config = config;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Initializes the bot instance
|
|
40
|
+
*
|
|
41
|
+
* @returns {Promise<void>}
|
|
42
|
+
*/
|
|
43
|
+
async initialize() {
|
|
44
|
+
if (this.bot)
|
|
45
|
+
return;
|
|
46
|
+
this.bot = new node_telegram_bot_api_1.default(this.config.botToken, {
|
|
47
|
+
polling: false // We'll use webhook or manual polling
|
|
48
|
+
});
|
|
49
|
+
// Verify bot token is valid
|
|
50
|
+
try {
|
|
51
|
+
const me = await this.bot.getMe();
|
|
52
|
+
console.info(`Telegram bot initialized: @${me.username}`);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw new Error(`Failed to initialize Telegram bot: ${error}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Sends a text message
|
|
60
|
+
*
|
|
61
|
+
* @param {SendMessageOptions} options - Message options
|
|
62
|
+
* @returns {Promise<any>} Sent message object
|
|
63
|
+
*/
|
|
64
|
+
async sendMessage(options) {
|
|
65
|
+
if (!this.bot) {
|
|
66
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
67
|
+
}
|
|
68
|
+
const parseMode = options.parseMode || this.config.defaultParseMode;
|
|
69
|
+
try {
|
|
70
|
+
const result = await this.retryOperation(async () => {
|
|
71
|
+
return this.bot.sendMessage(options.chatId, options.text, {
|
|
72
|
+
parse_mode: parseMode,
|
|
73
|
+
disable_notification: options.disableNotification,
|
|
74
|
+
reply_to_message_id: options.replyToMessageId,
|
|
75
|
+
reply_markup: options.replyMarkup
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
success: true,
|
|
80
|
+
messageId: result.message_id,
|
|
81
|
+
chatId: result.chat.id,
|
|
82
|
+
date: result.date,
|
|
83
|
+
text: result.text
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: error.message
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sends a photo
|
|
95
|
+
*
|
|
96
|
+
* @param {SendPhotoOptions} options - Photo options
|
|
97
|
+
* @returns {Promise<any>} Sent message object
|
|
98
|
+
*/
|
|
99
|
+
async sendPhoto(options) {
|
|
100
|
+
if (!this.bot) {
|
|
101
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
102
|
+
}
|
|
103
|
+
const parseMode = options.parseMode || this.config.defaultParseMode;
|
|
104
|
+
try {
|
|
105
|
+
const result = await this.retryOperation(async () => {
|
|
106
|
+
return this.bot.sendPhoto(options.chatId, options.photo, {
|
|
107
|
+
caption: options.caption,
|
|
108
|
+
parse_mode: parseMode,
|
|
109
|
+
disable_notification: options.disableNotification
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
messageId: result.message_id,
|
|
115
|
+
chatId: result.chat.id,
|
|
116
|
+
date: result.date,
|
|
117
|
+
photo: result.photo
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
return {
|
|
122
|
+
success: false,
|
|
123
|
+
error: error.message
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Sends a document
|
|
129
|
+
*
|
|
130
|
+
* @param {Object} options - Document options
|
|
131
|
+
* @returns {Promise<any>} Sent message object
|
|
132
|
+
*/
|
|
133
|
+
async sendDocument(options) {
|
|
134
|
+
if (!this.bot) {
|
|
135
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const result = await this.retryOperation(async () => {
|
|
139
|
+
return this.bot.sendDocument(options.chatId, options.document, {
|
|
140
|
+
caption: options.caption,
|
|
141
|
+
parse_mode: options.parseMode || this.config.defaultParseMode
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
success: true,
|
|
146
|
+
messageId: result.message_id,
|
|
147
|
+
chatId: result.chat.id,
|
|
148
|
+
date: result.date,
|
|
149
|
+
document: result.document
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
error: error.message
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Gets information about a chat
|
|
161
|
+
*
|
|
162
|
+
* @param {string | number} chatId - Chat identifier
|
|
163
|
+
* @returns {Promise<any>} Chat information
|
|
164
|
+
*/
|
|
165
|
+
async getChatInfo(chatId) {
|
|
166
|
+
if (!this.bot) {
|
|
167
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const chat = await this.bot.getChat(chatId);
|
|
171
|
+
return {
|
|
172
|
+
success: true,
|
|
173
|
+
id: chat.id,
|
|
174
|
+
type: chat.type,
|
|
175
|
+
title: chat.title,
|
|
176
|
+
username: chat.username,
|
|
177
|
+
description: chat.description,
|
|
178
|
+
inviteLink: chat.invite_link
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
error: error.message
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Pins a message in a chat
|
|
190
|
+
*
|
|
191
|
+
* @param {string | number} chatId - Chat identifier
|
|
192
|
+
* @param {number} messageId - Message to pin
|
|
193
|
+
* @param {boolean} disableNotification - Silent pin
|
|
194
|
+
* @returns {Promise<any>} Operation result
|
|
195
|
+
*/
|
|
196
|
+
async pinMessage(chatId, messageId, disableNotification = false) {
|
|
197
|
+
if (!this.bot) {
|
|
198
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
await this.bot.pinChatMessage(chatId, messageId, {
|
|
202
|
+
disable_notification: disableNotification
|
|
203
|
+
});
|
|
204
|
+
return { success: true };
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
error: error.message
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Gets recent messages from a chat (if using polling)
|
|
215
|
+
*
|
|
216
|
+
* @param {string | number} chatId - Chat identifier
|
|
217
|
+
* @param {number} limit - Number of messages to retrieve
|
|
218
|
+
* @returns {Promise<any[]>} Recent messages
|
|
219
|
+
*/
|
|
220
|
+
async getRecentMessages(chatId, limit = 10) {
|
|
221
|
+
// Note: Telegram Bot API doesn't directly support getting message history
|
|
222
|
+
// This would need to be implemented using message polling/webhooks
|
|
223
|
+
// and maintaining a message cache
|
|
224
|
+
return {
|
|
225
|
+
success: false,
|
|
226
|
+
error: 'Message history requires webhook setup or message caching',
|
|
227
|
+
hint: 'Use webhooks or long polling to receive and cache messages'
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Retries an operation with exponential backoff
|
|
232
|
+
*
|
|
233
|
+
* @private
|
|
234
|
+
* @param {Function} operation - Operation to retry
|
|
235
|
+
* @returns {Promise<any>} Operation result
|
|
236
|
+
*/
|
|
237
|
+
async retryOperation(operation) {
|
|
238
|
+
let lastError;
|
|
239
|
+
for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
|
|
240
|
+
try {
|
|
241
|
+
return await operation();
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
lastError = error;
|
|
245
|
+
if (attempt < this.config.maxRetries) {
|
|
246
|
+
// Exponential backoff
|
|
247
|
+
const delay = Math.min(1000 * Math.pow(2, attempt), 10000);
|
|
248
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
throw lastError;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Shuts down the bot service
|
|
256
|
+
*
|
|
257
|
+
* @returns {Promise<void>}
|
|
258
|
+
*/
|
|
259
|
+
async shutdown() {
|
|
260
|
+
if (this.bot) {
|
|
261
|
+
await this.bot.stopPolling();
|
|
262
|
+
this.bot = null;
|
|
263
|
+
}
|
|
264
|
+
this.retryAttempts.clear();
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Gets the bot instance (for advanced operations)
|
|
268
|
+
*
|
|
269
|
+
* @returns {TelegramBot | null} Bot instance
|
|
270
|
+
*/
|
|
271
|
+
getBotInstance() {
|
|
272
|
+
return this.bot;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.TelegramBotService = TelegramBotService;
|
|
276
|
+
//# sourceMappingURL=telegramBot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegramBot.js","sourceRoot":"","sources":["../../src/services/telegramBot.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,kFAAgD;AA0BhD;;;;;;;;;;;;;;GAcG;AACH,MAAa,kBAAkB;IACrB,GAAG,GAAuB,IAAI,CAAC;IAC/B,MAAM,CAAiB;IACvB,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEvD;;;;OAIG;IACH,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UA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AAE,CAAC;YACnE,IAAI,CAAC;gBACH,OAAO,MAAM,SAAS,EAAE,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,SAAS,GAAG,KAAK,CAAC;gBAElB,IAAI,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;oBACrC,sBAAsB;oBACtB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;oBAC3D,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;gBAC3D,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,SAAS,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF;AAtRD,gDAsRC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send message tool for Telegram Bot extension
|
|
3
|
+
*/
|
|
4
|
+
import { ITool, ToolExecutionContext, ToolExecutionResult } from '@framers/agentos';
|
|
5
|
+
import { TelegramBotService } from '../services/telegramBot';
|
|
6
|
+
/**
|
|
7
|
+
* Tool for sending text messages via Telegram
|
|
8
|
+
*
|
|
9
|
+
* @class SendMessageTool
|
|
10
|
+
* @implements {ITool}
|
|
11
|
+
*/
|
|
12
|
+
export declare class SendMessageTool implements ITool {
|
|
13
|
+
private botService;
|
|
14
|
+
readonly id = "telegramSendMessage";
|
|
15
|
+
readonly name = "telegramSendMessage";
|
|
16
|
+
readonly displayName = "Send Telegram Message";
|
|
17
|
+
readonly description = "Send a text message to a Telegram chat, channel, or user. Supports Markdown and HTML formatting.";
|
|
18
|
+
readonly inputSchema: {
|
|
19
|
+
type: string;
|
|
20
|
+
required: string[];
|
|
21
|
+
properties: {
|
|
22
|
+
chatId: {
|
|
23
|
+
type: string[];
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
text: {
|
|
27
|
+
type: string;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
30
|
+
parseMode: {
|
|
31
|
+
type: string;
|
|
32
|
+
enum: string[];
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
disableNotification: {
|
|
36
|
+
type: string;
|
|
37
|
+
description: string;
|
|
38
|
+
default: boolean;
|
|
39
|
+
};
|
|
40
|
+
replyToMessageId: {
|
|
41
|
+
type: string;
|
|
42
|
+
description: string;
|
|
43
|
+
};
|
|
44
|
+
buttons: {
|
|
45
|
+
type: string;
|
|
46
|
+
description: string;
|
|
47
|
+
items: {
|
|
48
|
+
type: string;
|
|
49
|
+
items: {
|
|
50
|
+
type: string;
|
|
51
|
+
properties: {
|
|
52
|
+
text: {
|
|
53
|
+
type: string;
|
|
54
|
+
};
|
|
55
|
+
url: {
|
|
56
|
+
type: string;
|
|
57
|
+
};
|
|
58
|
+
callbackData: {
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
readonly outputSchema: {
|
|
68
|
+
type: string;
|
|
69
|
+
properties: {
|
|
70
|
+
success: {
|
|
71
|
+
type: string;
|
|
72
|
+
};
|
|
73
|
+
messageId: {
|
|
74
|
+
type: string;
|
|
75
|
+
};
|
|
76
|
+
chatId: {
|
|
77
|
+
type: string[];
|
|
78
|
+
};
|
|
79
|
+
date: {
|
|
80
|
+
type: string;
|
|
81
|
+
};
|
|
82
|
+
error: {
|
|
83
|
+
type: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
readonly requiredCapabilities: string[];
|
|
88
|
+
readonly category = "communications";
|
|
89
|
+
readonly version = "1.0.0";
|
|
90
|
+
readonly hasSideEffects = true;
|
|
91
|
+
/**
|
|
92
|
+
* Creates an instance of SendMessageTool
|
|
93
|
+
*
|
|
94
|
+
* @param {TelegramBotService} botService - Telegram bot service
|
|
95
|
+
*/
|
|
96
|
+
constructor(botService: TelegramBotService);
|
|
97
|
+
/**
|
|
98
|
+
* Executes the send message operation
|
|
99
|
+
*
|
|
100
|
+
* @param {any} args - Input arguments
|
|
101
|
+
* @param {ToolExecutionContext} context - Execution context
|
|
102
|
+
* @returns {Promise<ToolExecutionResult>} Execution result
|
|
103
|
+
*/
|
|
104
|
+
execute(args: any, context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Validates input arguments
|
|
107
|
+
*
|
|
108
|
+
* @param {any} args - Arguments to validate
|
|
109
|
+
* @returns {{isValid: boolean, errors?: string[]}} Validation result
|
|
110
|
+
*/
|
|
111
|
+
validateArgs(args: any): {
|
|
112
|
+
isValid: boolean;
|
|
113
|
+
errors?: string[];
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=sendMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendMessage.d.ts","sourceRoot":"","sources":["../../src/tools/sendMessage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,KAAK;IAuE/B,OAAO,CAAC,UAAU;IAtE9B,SAAgB,EAAE,yBAAyB;IAC3C,SAAgB,IAAI,yBAAyB;IAC7C,SAAgB,WAAW,2BAA2B;IACtD,SAAgB,WAAW,sGAAsG;IAEjI,SAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA0CzB;IAEF,SAAgB,YAAY;;;;;;;;;;;;;;;;;;;MAS1B;IAEF,SAAgB,oBAAoB,WAAmC;IACvE,SAAgB,QAAQ,oBAAoB;IAC5C,SAAgB,OAAO,WAAW;IAClC,SAAgB,cAAc,QAAQ;IAEtC;;;;OAIG;gBACiB,UAAU,EAAE,kBAAkB;IAElD;;;;;;OAMG;IACG,OAAO,CACX,IAAI,EAAE,GAAG,EACT,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC;IAsC/B;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;CAwBjE"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Send message tool for Telegram Bot extension
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SendMessageTool = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Tool for sending text messages via Telegram
|
|
9
|
+
*
|
|
10
|
+
* @class SendMessageTool
|
|
11
|
+
* @implements {ITool}
|
|
12
|
+
*/
|
|
13
|
+
class SendMessageTool {
|
|
14
|
+
botService;
|
|
15
|
+
id = 'telegramSendMessage';
|
|
16
|
+
name = 'telegramSendMessage';
|
|
17
|
+
displayName = 'Send Telegram Message';
|
|
18
|
+
description = 'Send a text message to a Telegram chat, channel, or user. Supports Markdown and HTML formatting.';
|
|
19
|
+
inputSchema = {
|
|
20
|
+
type: 'object',
|
|
21
|
+
required: ['chatId', 'text'],
|
|
22
|
+
properties: {
|
|
23
|
+
chatId: {
|
|
24
|
+
type: ['string', 'number'],
|
|
25
|
+
description: 'Chat ID, username (@username), or channel (@channelname)'
|
|
26
|
+
},
|
|
27
|
+
text: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'Message text to send (supports Markdown/HTML based on parseMode)'
|
|
30
|
+
},
|
|
31
|
+
parseMode: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
enum: ['Markdown', 'HTML', 'MarkdownV2'],
|
|
34
|
+
description: 'Text formatting mode'
|
|
35
|
+
},
|
|
36
|
+
disableNotification: {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
description: 'Send message silently',
|
|
39
|
+
default: false
|
|
40
|
+
},
|
|
41
|
+
replyToMessageId: {
|
|
42
|
+
type: 'number',
|
|
43
|
+
description: 'ID of message to reply to'
|
|
44
|
+
},
|
|
45
|
+
buttons: {
|
|
46
|
+
type: 'array',
|
|
47
|
+
description: 'Inline keyboard buttons',
|
|
48
|
+
items: {
|
|
49
|
+
type: 'array',
|
|
50
|
+
items: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
text: { type: 'string' },
|
|
54
|
+
url: { type: 'string' },
|
|
55
|
+
callbackData: { type: 'string' }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
outputSchema = {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
success: { type: 'boolean' },
|
|
66
|
+
messageId: { type: 'number' },
|
|
67
|
+
chatId: { type: ['string', 'number'] },
|
|
68
|
+
date: { type: 'number' },
|
|
69
|
+
error: { type: 'string' }
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
requiredCapabilities = ['capability:network:telegram'];
|
|
73
|
+
category = 'communications';
|
|
74
|
+
version = '1.0.0';
|
|
75
|
+
hasSideEffects = true;
|
|
76
|
+
/**
|
|
77
|
+
* Creates an instance of SendMessageTool
|
|
78
|
+
*
|
|
79
|
+
* @param {TelegramBotService} botService - Telegram bot service
|
|
80
|
+
*/
|
|
81
|
+
constructor(botService) {
|
|
82
|
+
this.botService = botService;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Executes the send message operation
|
|
86
|
+
*
|
|
87
|
+
* @param {any} args - Input arguments
|
|
88
|
+
* @param {ToolExecutionContext} context - Execution context
|
|
89
|
+
* @returns {Promise<ToolExecutionResult>} Execution result
|
|
90
|
+
*/
|
|
91
|
+
async execute(args, context) {
|
|
92
|
+
try {
|
|
93
|
+
// Prepare reply markup if buttons provided
|
|
94
|
+
let replyMarkup;
|
|
95
|
+
if (args.buttons && Array.isArray(args.buttons)) {
|
|
96
|
+
replyMarkup = {
|
|
97
|
+
inline_keyboard: args.buttons.map((row) => row.map(btn => ({
|
|
98
|
+
text: btn.text,
|
|
99
|
+
url: btn.url,
|
|
100
|
+
callback_data: btn.callbackData
|
|
101
|
+
})))
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const result = await this.botService.sendMessage({
|
|
105
|
+
chatId: args.chatId,
|
|
106
|
+
text: args.text,
|
|
107
|
+
parseMode: args.parseMode,
|
|
108
|
+
disableNotification: args.disableNotification,
|
|
109
|
+
replyToMessageId: args.replyToMessageId,
|
|
110
|
+
replyMarkup
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
success: result.success,
|
|
114
|
+
output: result,
|
|
115
|
+
error: result.error
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
error: `Failed to send message: ${error.message}`
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Validates input arguments
|
|
127
|
+
*
|
|
128
|
+
* @param {any} args - Arguments to validate
|
|
129
|
+
* @returns {{isValid: boolean, errors?: string[]}} Validation result
|
|
130
|
+
*/
|
|
131
|
+
validateArgs(args) {
|
|
132
|
+
const errors = [];
|
|
133
|
+
if (!args.chatId) {
|
|
134
|
+
errors.push('chatId is required');
|
|
135
|
+
}
|
|
136
|
+
if (!args.text) {
|
|
137
|
+
errors.push('text is required');
|
|
138
|
+
}
|
|
139
|
+
else if (typeof args.text !== 'string') {
|
|
140
|
+
errors.push('text must be a string');
|
|
141
|
+
}
|
|
142
|
+
else if (args.text.length > 4096) {
|
|
143
|
+
errors.push('text must be 4096 characters or less');
|
|
144
|
+
}
|
|
145
|
+
if (args.parseMode && !['Markdown', 'HTML', 'MarkdownV2'].includes(args.parseMode)) {
|
|
146
|
+
errors.push('parseMode must be Markdown, HTML, or MarkdownV2');
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
isValid: errors.length === 0,
|
|
150
|
+
errors: errors.length > 0 ? errors : undefined
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.SendMessageTool = SendMessageTool;
|
|
155
|
+
//# sourceMappingURL=sendMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendMessage.js","sourceRoot":"","sources":["../../src/tools/sendMessage.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAKH;;;;;GAKG;AACH,MAAa,eAAe;IAuEN;IAtEJ,EAAE,GAAG,qBAAqB,CAAC;IAC3B,IAAI,GAAG,qBAAqB,CAAC;IAC7B,WAAW,GAAG,uBAAuB,CAAC;IACtC,WAAW,GAAG,kGAAkG,CAAC;IAEjH,WAAW,GAAG;QAC5B,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC5B,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;gBAC1B,WAAW,EAAE,0DAA0D;aACxE;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd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CAAC;QAE5B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACpC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAClC,CAAC;aAAM,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACvC,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACnF,MAAM,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;QACjE,CAAC;QAED,OAAO;YACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC/C,CAAC;IACJ,CAAC;CACF;AAvJD,0CAuJC"}
|
package/manifest.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://agentos.sh/schemas/extension-manifest-v1.json",
|
|
3
|
+
"id": "com.framers.communications.telegram",
|
|
4
|
+
"name": "Telegram Bot Extension",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "Professional Telegram Bot API integration for AgentOS agents",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Frame.dev",
|
|
9
|
+
"email": "support@frame.dev",
|
|
10
|
+
"url": "https://github.com/framersai"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"keywords": ["telegram", "bot", "messaging", "communications", "chat", "channels"],
|
|
14
|
+
"agentosVersion": "^2.0.0",
|
|
15
|
+
"categories": ["communications", "integrations"],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/framersai/agentos-extensions"
|
|
19
|
+
},
|
|
20
|
+
"extensions": [
|
|
21
|
+
{
|
|
22
|
+
"kind": "tool",
|
|
23
|
+
"id": "telegramSendMessage",
|
|
24
|
+
"displayName": "Send Telegram Message",
|
|
25
|
+
"description": "Send a message to a Telegram chat or channel",
|
|
26
|
+
"entry": "./dist/tools/sendMessage.js"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"kind": "tool",
|
|
30
|
+
"id": "telegramSendPhoto",
|
|
31
|
+
"displayName": "Send Telegram Photo",
|
|
32
|
+
"description": "Send a photo with optional caption to a Telegram chat",
|
|
33
|
+
"entry": "./dist/tools/sendPhoto.js"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"kind": "tool",
|
|
37
|
+
"id": "telegramSendDocument",
|
|
38
|
+
"displayName": "Send Telegram Document",
|
|
39
|
+
"description": "Send a document file to a Telegram chat",
|
|
40
|
+
"entry": "./dist/tools/sendDocument.js"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"kind": "tool",
|
|
44
|
+
"id": "telegramManageChat",
|
|
45
|
+
"displayName": "Manage Telegram Chat",
|
|
46
|
+
"description": "Get chat info, pin messages, or manage chat settings",
|
|
47
|
+
"entry": "./dist/tools/manageChat.js"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"kind": "tool",
|
|
51
|
+
"id": "telegramPollMessages",
|
|
52
|
+
"displayName": "Poll Telegram Messages",
|
|
53
|
+
"description": "Retrieve recent messages from a chat for context",
|
|
54
|
+
"entry": "./dist/tools/pollMessages.js"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"configuration": {
|
|
58
|
+
"properties": {
|
|
59
|
+
"telegram.botToken": {
|
|
60
|
+
"type": "string",
|
|
61
|
+
"description": "Telegram Bot API token from @BotFather",
|
|
62
|
+
"secret": true
|
|
63
|
+
},
|
|
64
|
+
"telegram.defaultParseMode": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"enum": ["Markdown", "HTML", "MarkdownV2"],
|
|
67
|
+
"default": "Markdown",
|
|
68
|
+
"description": "Default message parsing mode"
|
|
69
|
+
},
|
|
70
|
+
"telegram.pollingInterval": {
|
|
71
|
+
"type": "number",
|
|
72
|
+
"default": 1000,
|
|
73
|
+
"minimum": 100,
|
|
74
|
+
"maximum": 10000,
|
|
75
|
+
"description": "Polling interval in milliseconds"
|
|
76
|
+
},
|
|
77
|
+
"telegram.maxRetries": {
|
|
78
|
+
"type": "number",
|
|
79
|
+
"default": 3,
|
|
80
|
+
"minimum": 0,
|
|
81
|
+
"maximum": 10,
|
|
82
|
+
"description": "Maximum retry attempts for failed requests"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"features": [
|
|
87
|
+
"Send text messages with formatting (Markdown/HTML)",
|
|
88
|
+
"Send photos, documents, and media",
|
|
89
|
+
"Manage chat settings and pins",
|
|
90
|
+
"Poll messages for context awareness",
|
|
91
|
+
"Rate limiting and retry logic",
|
|
92
|
+
"Environment variable support for credentials"
|
|
93
|
+
]
|
|
94
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@framers/agentos-ext-telegram-bot",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Telegram Bot API extension for AgentOS - manage channels, send messages, and interact as a bot",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"dev": "tsc --watch",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest watch",
|
|
12
|
+
"test:coverage": "vitest run --coverage",
|
|
13
|
+
"lint": "eslint src test --ext .ts",
|
|
14
|
+
"lint:fix": "eslint src test --ext .ts --fix",
|
|
15
|
+
"clean": "rm -rf dist coverage",
|
|
16
|
+
"docs": "typedoc --out docs src/index.ts"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"agentos",
|
|
20
|
+
"extension",
|
|
21
|
+
"telegram",
|
|
22
|
+
"bot",
|
|
23
|
+
"messaging",
|
|
24
|
+
"communications",
|
|
25
|
+
"chat"
|
|
26
|
+
],
|
|
27
|
+
"author": {
|
|
28
|
+
"name": "Framers AI",
|
|
29
|
+
"email": "team@frame.dev",
|
|
30
|
+
"url": "https://frame.dev"
|
|
31
|
+
},
|
|
32
|
+
"contributors": [
|
|
33
|
+
{
|
|
34
|
+
"name": "Johnny Dunn",
|
|
35
|
+
"email": "johnnyfived@protonmail.com",
|
|
36
|
+
"url": "https://github.com/jddunn"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/framersai/agentos-extensions",
|
|
43
|
+
"directory": "registry/curated/communications/telegram-bot"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"manifest.json",
|
|
48
|
+
"README.md"
|
|
49
|
+
],
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@framers/agentos": "^0.1.0"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"node-telegram-bot-api": "^0.64.0",
|
|
55
|
+
"dotenv": "^16.0.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@framers/agentos": "^0.1.0",
|
|
59
|
+
"@types/node": "^20.0.0",
|
|
60
|
+
"@types/node-telegram-bot-api": "^0.64.0",
|
|
61
|
+
"typescript": "^5.0.0",
|
|
62
|
+
"vitest": "^1.0.0",
|
|
63
|
+
"@vitest/coverage-v8": "^1.0.0",
|
|
64
|
+
"eslint": "^8.0.0",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
66
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
67
|
+
"typedoc": "^0.25.0"
|
|
68
|
+
},
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=18.0.0"
|
|
71
|
+
},
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"access": "public",
|
|
74
|
+
"registry": "https://registry.npmjs.org/"
|
|
75
|
+
}
|
|
76
|
+
}
|