@framers/agentos-ext-telegram 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/LICENSE +21 -0
- package/README.md +317 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +227 -0
- package/dist/index.js.map +1 -0
- package/dist/services/telegramBot.d.ts +167 -0
- package/dist/services/telegramBot.d.ts.map +1 -0
- package/dist/services/telegramBot.js +302 -0
- package/dist/services/telegramBot.js.map +1 -0
- package/dist/tools/getChatInfo.d.ts +77 -0
- package/dist/tools/getChatInfo.d.ts.map +1 -0
- package/dist/tools/getChatInfo.js +119 -0
- package/dist/tools/getChatInfo.js.map +1 -0
- package/dist/tools/handleCallback.d.ts +55 -0
- package/dist/tools/handleCallback.d.ts.map +1 -0
- package/dist/tools/handleCallback.js +78 -0
- package/dist/tools/handleCallback.js.map +1 -0
- package/dist/tools/manageGroup.d.ts +54 -0
- package/dist/tools/manageGroup.d.ts.map +1 -0
- package/dist/tools/manageGroup.js +105 -0
- package/dist/tools/manageGroup.js.map +1 -0
- package/dist/tools/sendDocument.d.ts +59 -0
- package/dist/tools/sendDocument.d.ts.map +1 -0
- package/dist/tools/sendDocument.js +86 -0
- package/dist/tools/sendDocument.js.map +1 -0
- package/dist/tools/sendMessage.d.ts +94 -0
- package/dist/tools/sendMessage.d.ts.map +1 -0
- package/dist/tools/sendMessage.js +142 -0
- package/dist/tools/sendMessage.js.map +1 -0
- package/dist/tools/sendPhoto.d.ts +54 -0
- package/dist/tools/sendPhoto.d.ts.map +1 -0
- package/dist/tools/sendPhoto.js +80 -0
- package/dist/tools/sendPhoto.js.map +1 -0
- package/manifest.json +176 -0
- package/package.json +77 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Bot Service
|
|
3
|
+
* Manages the Telegram bot connection and provides API methods
|
|
4
|
+
*/
|
|
5
|
+
import TelegramBot from 'node-telegram-bot-api';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for the Telegram bot service
|
|
8
|
+
*/
|
|
9
|
+
export interface TelegramConfig {
|
|
10
|
+
botToken: string;
|
|
11
|
+
webhookUrl?: string;
|
|
12
|
+
pollingInterval?: number;
|
|
13
|
+
defaultParseMode: 'Markdown' | 'HTML';
|
|
14
|
+
enableTypingAction: boolean;
|
|
15
|
+
rateLimit: {
|
|
16
|
+
maxRequests: number;
|
|
17
|
+
windowMs: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Message sending options
|
|
22
|
+
*/
|
|
23
|
+
export interface SendMessageOptions {
|
|
24
|
+
chatId: string | number;
|
|
25
|
+
text: string;
|
|
26
|
+
parseMode?: 'Markdown' | 'HTML';
|
|
27
|
+
replyToMessageId?: number;
|
|
28
|
+
disableNotification?: boolean;
|
|
29
|
+
replyMarkup?: any;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Service for interacting with Telegram Bot API
|
|
33
|
+
*
|
|
34
|
+
* @class TelegramBotService
|
|
35
|
+
*/
|
|
36
|
+
export declare class TelegramBotService {
|
|
37
|
+
private bot;
|
|
38
|
+
private config;
|
|
39
|
+
private rateLimitState;
|
|
40
|
+
private messageQueue;
|
|
41
|
+
private isProcessingQueue;
|
|
42
|
+
/**
|
|
43
|
+
* Creates an instance of TelegramBotService
|
|
44
|
+
* @param {TelegramConfig} config - Service configuration
|
|
45
|
+
*/
|
|
46
|
+
constructor(config: TelegramConfig);
|
|
47
|
+
/**
|
|
48
|
+
* Initializes the bot connection
|
|
49
|
+
*/
|
|
50
|
+
initialize(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Checks and enforces rate limiting
|
|
53
|
+
*
|
|
54
|
+
* @private
|
|
55
|
+
* @param {string} key - Rate limit key (usually chatId)
|
|
56
|
+
* @returns {Promise<boolean>} True if within limits
|
|
57
|
+
*/
|
|
58
|
+
private checkRateLimit;
|
|
59
|
+
/**
|
|
60
|
+
* Queues an API call with rate limiting
|
|
61
|
+
*
|
|
62
|
+
* @private
|
|
63
|
+
* @param {Function} fn - Function to execute
|
|
64
|
+
* @returns {Promise<T>} Result of the function
|
|
65
|
+
*/
|
|
66
|
+
private queueApiCall;
|
|
67
|
+
/**
|
|
68
|
+
* Processes the message queue
|
|
69
|
+
*
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
private processQueue;
|
|
73
|
+
/**
|
|
74
|
+
* Sends a text message
|
|
75
|
+
*
|
|
76
|
+
* @param {SendMessageOptions} options - Message options
|
|
77
|
+
* @returns {Promise<TelegramBot.Message>} Sent message
|
|
78
|
+
*/
|
|
79
|
+
sendMessage(options: SendMessageOptions): Promise<TelegramBot.Message>;
|
|
80
|
+
/**
|
|
81
|
+
* Sends a photo
|
|
82
|
+
*
|
|
83
|
+
* @param {string | number} chatId - Chat ID
|
|
84
|
+
* @param {string | Buffer} photo - Photo URL or buffer
|
|
85
|
+
* @param {Object} options - Additional options
|
|
86
|
+
* @returns {Promise<TelegramBot.Message>} Sent message
|
|
87
|
+
*/
|
|
88
|
+
sendPhoto(chatId: string | number, photo: string | Buffer, options?: {
|
|
89
|
+
caption?: string;
|
|
90
|
+
parseMode?: 'Markdown' | 'HTML';
|
|
91
|
+
replyToMessageId?: number;
|
|
92
|
+
}): Promise<TelegramBot.Message>;
|
|
93
|
+
/**
|
|
94
|
+
* Sends a document
|
|
95
|
+
*
|
|
96
|
+
* @param {string | number} chatId - Chat ID
|
|
97
|
+
* @param {string | Buffer} document - Document URL or buffer
|
|
98
|
+
* @param {Object} options - Additional options
|
|
99
|
+
* @returns {Promise<TelegramBot.Message>} Sent message
|
|
100
|
+
*/
|
|
101
|
+
sendDocument(chatId: string | number, document: string | Buffer, options?: {
|
|
102
|
+
caption?: string;
|
|
103
|
+
parseMode?: 'Markdown' | 'HTML';
|
|
104
|
+
replyToMessageId?: number;
|
|
105
|
+
filename?: string;
|
|
106
|
+
}): Promise<TelegramBot.Message>;
|
|
107
|
+
/**
|
|
108
|
+
* Gets chat information
|
|
109
|
+
*
|
|
110
|
+
* @param {string | number} chatId - Chat ID
|
|
111
|
+
* @returns {Promise<TelegramBot.Chat>} Chat information
|
|
112
|
+
*/
|
|
113
|
+
getChatInfo(chatId: string | number): Promise<TelegramBot.Chat>;
|
|
114
|
+
/**
|
|
115
|
+
* Gets chat member count
|
|
116
|
+
*
|
|
117
|
+
* @param {string | number} chatId - Chat ID
|
|
118
|
+
* @returns {Promise<number>} Member count
|
|
119
|
+
*/
|
|
120
|
+
getChatMemberCount(chatId: string | number): Promise<number>;
|
|
121
|
+
/**
|
|
122
|
+
* Pins a message in a chat
|
|
123
|
+
*
|
|
124
|
+
* @param {string | number} chatId - Chat ID
|
|
125
|
+
* @param {number} messageId - Message ID to pin
|
|
126
|
+
* @param {boolean} disableNotification - Disable notification
|
|
127
|
+
* @returns {Promise<boolean>} Success status
|
|
128
|
+
*/
|
|
129
|
+
pinMessage(chatId: string | number, messageId: number, disableNotification?: boolean): Promise<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* Answers a callback query
|
|
132
|
+
*
|
|
133
|
+
* @param {string} callbackQueryId - Callback query ID
|
|
134
|
+
* @param {Object} options - Answer options
|
|
135
|
+
* @returns {Promise<boolean>} Success status
|
|
136
|
+
*/
|
|
137
|
+
answerCallbackQuery(callbackQueryId: string, options?: {
|
|
138
|
+
text?: string;
|
|
139
|
+
showAlert?: boolean;
|
|
140
|
+
url?: string;
|
|
141
|
+
cacheTime?: number;
|
|
142
|
+
}): Promise<boolean>;
|
|
143
|
+
/**
|
|
144
|
+
* Registers a message handler
|
|
145
|
+
*
|
|
146
|
+
* @param {RegExp | string} pattern - Message pattern to match
|
|
147
|
+
* @param {Function} handler - Handler function
|
|
148
|
+
*/
|
|
149
|
+
onMessage(pattern: RegExp | string, handler: (msg: TelegramBot.Message) => void): void;
|
|
150
|
+
/**
|
|
151
|
+
* Registers a callback query handler
|
|
152
|
+
*
|
|
153
|
+
* @param {Function} handler - Handler function
|
|
154
|
+
*/
|
|
155
|
+
onCallbackQuery(handler: (query: TelegramBot.CallbackQuery) => void): void;
|
|
156
|
+
/**
|
|
157
|
+
* Gets the bot instance for advanced operations
|
|
158
|
+
*
|
|
159
|
+
* @returns {TelegramBot | null} The bot instance
|
|
160
|
+
*/
|
|
161
|
+
getBotInstance(): TelegramBot | null;
|
|
162
|
+
/**
|
|
163
|
+
* Shuts down the bot connection
|
|
164
|
+
*/
|
|
165
|
+
shutdown(): Promise<void>;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=telegramBot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegramBot.d.ts","sourceRoot":"","sources":["../../src/services/telegramBot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,UAAU,GAAG,MAAM,CAAC;IACtC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,SAAS,EAAE;QACT,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,WAAW,CAAC,EAAE,GAAG,CAAC;CACnB;AAED;;;;GAIG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAA4B;IACvC,OAAO,CAAC,MAAM,C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IACG,UAAU,CACd,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,mBAAmB,UAAQ,GAC1B,OAAO,CAAC,OAAO,CAAC;IAQnB;;;;;;OAMG;IACG,mBAAmB,CACvB,eAAe,EAAE,MAAM,EACvB,OAAO,GAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;KACf,GACL,OAAO,CAAC,OAAO,CAAC;IAQnB;;;;;OAKG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,OAAO,KAAK,IAAI,GAAG,IAAI;IAQtF;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,aAAa,KAAK,IAAI,GAAG,IAAI;IAQ1E;;;;OAIG;IACH,cAAc,IAAI,WAAW,GAAG,IAAI;IAIpC;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAUhC"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Telegram Bot Service
|
|
4
|
+
* Manages the Telegram bot connection and provides API methods
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.TelegramBotService = void 0;
|
|
11
|
+
const node_telegram_bot_api_1 = __importDefault(require("node-telegram-bot-api"));
|
|
12
|
+
/**
|
|
13
|
+
* Service for interacting with Telegram Bot API
|
|
14
|
+
*
|
|
15
|
+
* @class TelegramBotService
|
|
16
|
+
*/
|
|
17
|
+
class TelegramBotService {
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of TelegramBotService
|
|
20
|
+
* @param {TelegramConfig} config - Service configuration
|
|
21
|
+
*/
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.bot = null;
|
|
24
|
+
this.messageQueue = [];
|
|
25
|
+
this.isProcessingQueue = false;
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.rateLimitState = new Map();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initializes the bot connection
|
|
31
|
+
*/
|
|
32
|
+
async initialize() {
|
|
33
|
+
if (this.bot) {
|
|
34
|
+
return; // Already initialized
|
|
35
|
+
}
|
|
36
|
+
const options = {
|
|
37
|
+
polling: !this.config.webhookUrl,
|
|
38
|
+
webHook: this.config.webhookUrl ? true : false
|
|
39
|
+
};
|
|
40
|
+
if (options.polling) {
|
|
41
|
+
options.polling = {
|
|
42
|
+
interval: this.config.pollingInterval || 300,
|
|
43
|
+
autoStart: true,
|
|
44
|
+
params: {
|
|
45
|
+
timeout: 10
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
this.bot = new node_telegram_bot_api_1.default(this.config.botToken, options);
|
|
50
|
+
if (this.config.webhookUrl) {
|
|
51
|
+
await this.bot.setWebHook(this.config.webhookUrl);
|
|
52
|
+
}
|
|
53
|
+
// Set up error handling
|
|
54
|
+
this.bot.on('error', (error) => {
|
|
55
|
+
console.error('Telegram Bot Error:', error);
|
|
56
|
+
});
|
|
57
|
+
this.bot.on('polling_error', (error) => {
|
|
58
|
+
console.error('Telegram Polling Error:', error);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks and enforces rate limiting
|
|
63
|
+
*
|
|
64
|
+
* @private
|
|
65
|
+
* @param {string} key - Rate limit key (usually chatId)
|
|
66
|
+
* @returns {Promise<boolean>} True if within limits
|
|
67
|
+
*/
|
|
68
|
+
async checkRateLimit(key = 'global') {
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
const state = this.rateLimitState.get(key);
|
|
71
|
+
if (!state || now > state.resetTime) {
|
|
72
|
+
this.rateLimitState.set(key, {
|
|
73
|
+
count: 1,
|
|
74
|
+
resetTime: now + this.config.rateLimit.windowMs
|
|
75
|
+
});
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (state.count >= this.config.rateLimit.maxRequests) {
|
|
79
|
+
// Wait until reset time
|
|
80
|
+
const waitTime = state.resetTime - now;
|
|
81
|
+
if (waitTime > 0) {
|
|
82
|
+
await new Promise(resolve => setTimeout(resolve, waitTime));
|
|
83
|
+
return this.checkRateLimit(key);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
state.count++;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Queues an API call with rate limiting
|
|
91
|
+
*
|
|
92
|
+
* @private
|
|
93
|
+
* @param {Function} fn - Function to execute
|
|
94
|
+
* @returns {Promise<T>} Result of the function
|
|
95
|
+
*/
|
|
96
|
+
async queueApiCall(fn) {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
this.messageQueue.push(async () => {
|
|
99
|
+
try {
|
|
100
|
+
const result = await fn();
|
|
101
|
+
resolve(result);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
reject(error);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
this.processQueue();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Processes the message queue
|
|
112
|
+
*
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
async processQueue() {
|
|
116
|
+
if (this.isProcessingQueue || this.messageQueue.length === 0) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.isProcessingQueue = true;
|
|
120
|
+
while (this.messageQueue.length > 0) {
|
|
121
|
+
await this.checkRateLimit();
|
|
122
|
+
const task = this.messageQueue.shift();
|
|
123
|
+
if (task) {
|
|
124
|
+
await task();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
this.isProcessingQueue = false;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Sends a text message
|
|
131
|
+
*
|
|
132
|
+
* @param {SendMessageOptions} options - Message options
|
|
133
|
+
* @returns {Promise<TelegramBot.Message>} Sent message
|
|
134
|
+
*/
|
|
135
|
+
async sendMessage(options) {
|
|
136
|
+
if (!this.bot) {
|
|
137
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
138
|
+
}
|
|
139
|
+
return this.queueApiCall(async () => {
|
|
140
|
+
if (this.config.enableTypingAction) {
|
|
141
|
+
await this.bot.sendChatAction(options.chatId, 'typing');
|
|
142
|
+
}
|
|
143
|
+
return this.bot.sendMessage(options.chatId, options.text, {
|
|
144
|
+
parse_mode: options.parseMode || this.config.defaultParseMode,
|
|
145
|
+
reply_to_message_id: options.replyToMessageId,
|
|
146
|
+
disable_notification: options.disableNotification,
|
|
147
|
+
reply_markup: options.replyMarkup
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Sends a photo
|
|
153
|
+
*
|
|
154
|
+
* @param {string | number} chatId - Chat ID
|
|
155
|
+
* @param {string | Buffer} photo - Photo URL or buffer
|
|
156
|
+
* @param {Object} options - Additional options
|
|
157
|
+
* @returns {Promise<TelegramBot.Message>} Sent message
|
|
158
|
+
*/
|
|
159
|
+
async sendPhoto(chatId, photo, options = {}) {
|
|
160
|
+
if (!this.bot) {
|
|
161
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
162
|
+
}
|
|
163
|
+
return this.queueApiCall(async () => {
|
|
164
|
+
if (this.config.enableTypingAction) {
|
|
165
|
+
await this.bot.sendChatAction(chatId, 'upload_photo');
|
|
166
|
+
}
|
|
167
|
+
return this.bot.sendPhoto(chatId, photo, {
|
|
168
|
+
caption: options.caption,
|
|
169
|
+
parse_mode: options.parseMode || this.config.defaultParseMode,
|
|
170
|
+
reply_to_message_id: options.replyToMessageId
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Sends a document
|
|
176
|
+
*
|
|
177
|
+
* @param {string | number} chatId - Chat ID
|
|
178
|
+
* @param {string | Buffer} document - Document URL or buffer
|
|
179
|
+
* @param {Object} options - Additional options
|
|
180
|
+
* @returns {Promise<TelegramBot.Message>} Sent message
|
|
181
|
+
*/
|
|
182
|
+
async sendDocument(chatId, document, options = {}) {
|
|
183
|
+
if (!this.bot) {
|
|
184
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
185
|
+
}
|
|
186
|
+
return this.queueApiCall(async () => {
|
|
187
|
+
if (this.config.enableTypingAction) {
|
|
188
|
+
await this.bot.sendChatAction(chatId, 'upload_document');
|
|
189
|
+
}
|
|
190
|
+
const sendOptions = {
|
|
191
|
+
caption: options.caption,
|
|
192
|
+
parse_mode: options.parseMode || this.config.defaultParseMode,
|
|
193
|
+
reply_to_message_id: options.replyToMessageId
|
|
194
|
+
};
|
|
195
|
+
if (options.filename && Buffer.isBuffer(document)) {
|
|
196
|
+
return this.bot.sendDocument(chatId, document, sendOptions, {
|
|
197
|
+
filename: options.filename,
|
|
198
|
+
contentType: 'application/octet-stream'
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return this.bot.sendDocument(chatId, document, sendOptions);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Gets chat information
|
|
206
|
+
*
|
|
207
|
+
* @param {string | number} chatId - Chat ID
|
|
208
|
+
* @returns {Promise<TelegramBot.Chat>} Chat information
|
|
209
|
+
*/
|
|
210
|
+
async getChatInfo(chatId) {
|
|
211
|
+
if (!this.bot) {
|
|
212
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
213
|
+
}
|
|
214
|
+
return this.bot.getChat(chatId);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets chat member count
|
|
218
|
+
*
|
|
219
|
+
* @param {string | number} chatId - Chat ID
|
|
220
|
+
* @returns {Promise<number>} Member count
|
|
221
|
+
*/
|
|
222
|
+
async getChatMemberCount(chatId) {
|
|
223
|
+
if (!this.bot) {
|
|
224
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
225
|
+
}
|
|
226
|
+
return this.bot.getChatMemberCount(chatId);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Pins a message in a chat
|
|
230
|
+
*
|
|
231
|
+
* @param {string | number} chatId - Chat ID
|
|
232
|
+
* @param {number} messageId - Message ID to pin
|
|
233
|
+
* @param {boolean} disableNotification - Disable notification
|
|
234
|
+
* @returns {Promise<boolean>} Success status
|
|
235
|
+
*/
|
|
236
|
+
async pinMessage(chatId, messageId, disableNotification = false) {
|
|
237
|
+
if (!this.bot) {
|
|
238
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
239
|
+
}
|
|
240
|
+
return this.bot.pinChatMessage(chatId, messageId, { disable_notification: disableNotification });
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Answers a callback query
|
|
244
|
+
*
|
|
245
|
+
* @param {string} callbackQueryId - Callback query ID
|
|
246
|
+
* @param {Object} options - Answer options
|
|
247
|
+
* @returns {Promise<boolean>} Success status
|
|
248
|
+
*/
|
|
249
|
+
async answerCallbackQuery(callbackQueryId, options = {}) {
|
|
250
|
+
if (!this.bot) {
|
|
251
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
252
|
+
}
|
|
253
|
+
return this.bot.answerCallbackQuery(callbackQueryId, options);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Registers a message handler
|
|
257
|
+
*
|
|
258
|
+
* @param {RegExp | string} pattern - Message pattern to match
|
|
259
|
+
* @param {Function} handler - Handler function
|
|
260
|
+
*/
|
|
261
|
+
onMessage(pattern, handler) {
|
|
262
|
+
if (!this.bot) {
|
|
263
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
264
|
+
}
|
|
265
|
+
this.bot.onText(pattern instanceof RegExp ? pattern : new RegExp(pattern), handler);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Registers a callback query handler
|
|
269
|
+
*
|
|
270
|
+
* @param {Function} handler - Handler function
|
|
271
|
+
*/
|
|
272
|
+
onCallbackQuery(handler) {
|
|
273
|
+
if (!this.bot) {
|
|
274
|
+
throw new Error('Bot not initialized. Call initialize() first.');
|
|
275
|
+
}
|
|
276
|
+
this.bot.on('callback_query', handler);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Gets the bot instance for advanced operations
|
|
280
|
+
*
|
|
281
|
+
* @returns {TelegramBot | null} The bot instance
|
|
282
|
+
*/
|
|
283
|
+
getBotInstance() {
|
|
284
|
+
return this.bot;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Shuts down the bot connection
|
|
288
|
+
*/
|
|
289
|
+
async shutdown() {
|
|
290
|
+
if (this.bot) {
|
|
291
|
+
if (this.config.webhookUrl) {
|
|
292
|
+
await this.bot.deleteWebHook();
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
this.bot.stopPolling();
|
|
296
|
+
}
|
|
297
|
+
this.bot = null;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.TelegramBotService = TelegramBotService;
|
|
302
|
+
//# sourceMappingURL=telegramBot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegramBot.js","sourceRoot":"","sources":["../../src/services/telegramBot.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,kFAAgD;AA6BhD;;;;GAIG;AACH,MAAa,kBAAkB;IAO7B;;;OAGG;IACH,YAAY,MAAsB;QAV1B,QAAG,GAAuB,IAAI,CAAC;QAG/B,iBAAY,GAA8B,EAAE,CAAC;QAC7C,sBAAiB,GAAG,KAAK,CAAC;QAOhC,IAAI,CAAC,MAAM,GAAG,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,CAAC;gBAC3B,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YACzB,CAAC;YACD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAClB,CAAC;IACH,CAAC;CACF;AAnWD,gDAmWC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ITool, ToolExecutionContext, ToolExecutionResult } from '@framers/agentos';
|
|
2
|
+
import { TelegramBotService } from '../services/telegramBot';
|
|
3
|
+
/**
|
|
4
|
+
* Tool for getting Telegram chat information
|
|
5
|
+
*
|
|
6
|
+
* @class GetChatInfoTool
|
|
7
|
+
* @implements {ITool}
|
|
8
|
+
*/
|
|
9
|
+
export declare class GetChatInfoTool implements ITool {
|
|
10
|
+
private telegramService;
|
|
11
|
+
readonly id = "telegramGetChatInfo";
|
|
12
|
+
readonly name = "telegramGetChatInfo";
|
|
13
|
+
readonly displayName = "Get Telegram Chat Info";
|
|
14
|
+
readonly description = "Retrieve information about a Telegram chat including type, title, member count, and settings.";
|
|
15
|
+
readonly category = "communication";
|
|
16
|
+
readonly version = "1.0.0";
|
|
17
|
+
readonly hasSideEffects = false;
|
|
18
|
+
readonly inputSchema: {
|
|
19
|
+
type: string;
|
|
20
|
+
required: string[];
|
|
21
|
+
properties: {
|
|
22
|
+
chatId: {
|
|
23
|
+
type: string[];
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
includeMemberCount: {
|
|
27
|
+
type: string;
|
|
28
|
+
description: string;
|
|
29
|
+
default: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
readonly outputSchema: {
|
|
34
|
+
type: string;
|
|
35
|
+
properties: {
|
|
36
|
+
id: {
|
|
37
|
+
type: string[];
|
|
38
|
+
description: string;
|
|
39
|
+
};
|
|
40
|
+
type: {
|
|
41
|
+
type: string;
|
|
42
|
+
enum: string[];
|
|
43
|
+
description: string;
|
|
44
|
+
};
|
|
45
|
+
title: {
|
|
46
|
+
type: string;
|
|
47
|
+
description: string;
|
|
48
|
+
};
|
|
49
|
+
username: {
|
|
50
|
+
type: string;
|
|
51
|
+
description: string;
|
|
52
|
+
};
|
|
53
|
+
firstName: {
|
|
54
|
+
type: string;
|
|
55
|
+
description: string;
|
|
56
|
+
};
|
|
57
|
+
lastName: {
|
|
58
|
+
type: string;
|
|
59
|
+
description: string;
|
|
60
|
+
};
|
|
61
|
+
memberCount: {
|
|
62
|
+
type: string;
|
|
63
|
+
description: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
constructor(telegramService: TelegramBotService);
|
|
68
|
+
execute(args: {
|
|
69
|
+
chatId: string | number;
|
|
70
|
+
includeMemberCount?: boolean;
|
|
71
|
+
}, context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
72
|
+
validateArgs(args: Record<string, any>): {
|
|
73
|
+
isValid: boolean;
|
|
74
|
+
errors?: string[];
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=getChatInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getChatInfo.d.ts","sourceRoot":"","sources":["../../src/tools/getChatInfo.ts"],"names":[],"mappings":"AAAA,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;IA4D/B,OAAO,CAAC,eAAe;IA3DnC,SAAgB,EAAE,yBAAyB;IAC3C,SAAgB,IAAI,yBAAyB;IAC7C,SAAgB,WAAW,4BAA4B;IACvD,SAAgB,WAAW,mGAAmG;IAC9H,SAAgB,QAAQ,mBAAmB;IAC3C,SAAgB,OAAO,WAAW;IAClC,SAAgB,cAAc,SAAS;IAEvC,SAAgB,WAAW;;;;;;;;;;;;;;MAczB;IAEF,SAAgB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiC1B;gBAEkB,eAAe,EAAE,kBAAkB;IAEjD,OAAO,CACX,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;QACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,EACD,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC;IAuC/B,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;CAYjF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetChatInfoTool = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Tool for getting Telegram chat information
|
|
6
|
+
*
|
|
7
|
+
* @class GetChatInfoTool
|
|
8
|
+
* @implements {ITool}
|
|
9
|
+
*/
|
|
10
|
+
class GetChatInfoTool {
|
|
11
|
+
constructor(telegramService) {
|
|
12
|
+
this.telegramService = telegramService;
|
|
13
|
+
this.id = 'telegramGetChatInfo';
|
|
14
|
+
this.name = 'telegramGetChatInfo';
|
|
15
|
+
this.displayName = 'Get Telegram Chat Info';
|
|
16
|
+
this.description = 'Retrieve information about a Telegram chat including type, title, member count, and settings.';
|
|
17
|
+
this.category = 'communication';
|
|
18
|
+
this.version = '1.0.0';
|
|
19
|
+
this.hasSideEffects = false;
|
|
20
|
+
this.inputSchema = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
required: ['chatId'],
|
|
23
|
+
properties: {
|
|
24
|
+
chatId: {
|
|
25
|
+
type: ['string', 'number'],
|
|
26
|
+
description: 'Unique identifier for the target chat or username of the target channel'
|
|
27
|
+
},
|
|
28
|
+
includeMemberCount: {
|
|
29
|
+
type: 'boolean',
|
|
30
|
+
description: 'Whether to include member count (requires additional API call)',
|
|
31
|
+
default: false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this.outputSchema = {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
id: {
|
|
39
|
+
type: ['string', 'number'],
|
|
40
|
+
description: 'Unique chat identifier'
|
|
41
|
+
},
|
|
42
|
+
type: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
enum: ['private', 'group', 'supergroup', 'channel'],
|
|
45
|
+
description: 'Type of chat'
|
|
46
|
+
},
|
|
47
|
+
title: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
description: 'Title for groups/channels'
|
|
50
|
+
},
|
|
51
|
+
username: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
description: 'Username for private chats and channels'
|
|
54
|
+
},
|
|
55
|
+
firstName: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'First name for private chats'
|
|
58
|
+
},
|
|
59
|
+
lastName: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
description: 'Last name for private chats'
|
|
62
|
+
},
|
|
63
|
+
memberCount: {
|
|
64
|
+
type: 'number',
|
|
65
|
+
description: 'Number of members (if requested)'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async execute(args, context) {
|
|
71
|
+
try {
|
|
72
|
+
const chatInfo = await this.telegramService.getChatInfo(args.chatId);
|
|
73
|
+
const output = {
|
|
74
|
+
id: chatInfo.id,
|
|
75
|
+
type: chatInfo.type,
|
|
76
|
+
title: chatInfo.title,
|
|
77
|
+
username: chatInfo.username,
|
|
78
|
+
firstName: chatInfo.first_name,
|
|
79
|
+
lastName: chatInfo.last_name
|
|
80
|
+
};
|
|
81
|
+
if (args.includeMemberCount && ['group', 'supergroup', 'channel'].includes(chatInfo.type)) {
|
|
82
|
+
try {
|
|
83
|
+
const memberCount = await this.telegramService.getChatMemberCount(args.chatId);
|
|
84
|
+
output.memberCount = memberCount;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
// Member count might not be available for all chats
|
|
88
|
+
console.warn('Could not get member count:', err);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
success: true,
|
|
93
|
+
output
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
error: error.message,
|
|
100
|
+
details: {
|
|
101
|
+
code: error.code,
|
|
102
|
+
description: error.description
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
validateArgs(args) {
|
|
108
|
+
const errors = [];
|
|
109
|
+
if (!args.chatId) {
|
|
110
|
+
errors.push('chatId is required');
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
isValid: errors.length === 0,
|
|
114
|
+
errors
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.GetChatInfoTool = GetChatInfoTool;
|
|
119
|
+
//# sourceMappingURL=getChatInfo.js.map
|