@codebam/cf-workers-telegram-bot 12.6.5 → 12.6.6
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/ai.js +26 -12
- package/dist/telegram_execution_context.js +2 -2
- package/package.json +2 -2
package/dist/ai.js
CHANGED
|
@@ -213,8 +213,8 @@ tools = []) {
|
|
|
213
213
|
const botApi = new TelegramApi();
|
|
214
214
|
// Use updateId as a stable draftId if available, otherwise generate one
|
|
215
215
|
const draftId = task.updateId || Date.now();
|
|
216
|
-
// Skip Thinking message for guest messages as they only support one response
|
|
217
|
-
if (task.updateType !== 'guest_message') {
|
|
216
|
+
// Skip Thinking message for guest messages and business messages as they only support one response or don't support drafts
|
|
217
|
+
if (task.updateType !== 'guest_message' && task.updateType !== 'business_message') {
|
|
218
218
|
await botApi.sendMessageDraft(`https://api.telegram.org/bot${task.telegramToken || task.token}`, {
|
|
219
219
|
chat_id: task.chatId,
|
|
220
220
|
text: 'Thinking...',
|
|
@@ -259,7 +259,10 @@ tools = []) {
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
// Update Telegram every 2 seconds to avoid rate limits
|
|
262
|
-
if (task.updateType !== 'guest_message' &&
|
|
262
|
+
if (task.updateType !== 'guest_message' &&
|
|
263
|
+
task.updateType !== 'business_message' &&
|
|
264
|
+
Date.now() - lastUpdate > 2000 &&
|
|
265
|
+
streamContent.trim()) {
|
|
263
266
|
const currentContent = streamContent;
|
|
264
267
|
bot
|
|
265
268
|
.streamReply(await markdownToHtml(currentContent + '...'), draftId, 'HTML')
|
|
@@ -315,16 +318,27 @@ export function createMockTelegramExecutionContext(task) {
|
|
|
315
318
|
},
|
|
316
319
|
streamReply: async (text, draft_id, parse_mode = '', options = {}, finish = false) => {
|
|
317
320
|
const api = new TelegramApi();
|
|
318
|
-
if (task.updateType === 'guest_message'
|
|
321
|
+
if (task.updateType === 'guest_message' || task.updateType === 'business_message') {
|
|
319
322
|
if (finish) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
323
|
+
if (task.updateType === 'guest_message' && task.guestQueryId) {
|
|
324
|
+
return await api.answerGuestQuery(`https://api.telegram.org/bot${task.telegramToken || task.token}`, {
|
|
325
|
+
guest_query_id: task.guestQueryId,
|
|
326
|
+
result: {
|
|
327
|
+
type: 'article',
|
|
328
|
+
id: crypto.randomUUID(),
|
|
329
|
+
title: 'Response',
|
|
330
|
+
input_message_content: { message_text: text, parse_mode: (parse_mode || 'HTML') },
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return await api.sendMessage(`https://api.telegram.org/bot${task.telegramToken || task.token}`, {
|
|
335
|
+
chat_id: task.chatId,
|
|
336
|
+
text,
|
|
337
|
+
parse_mode: (parse_mode || 'HTML'),
|
|
338
|
+
reply_markup: options.reply_markup,
|
|
339
|
+
message_thread_id: task.threadId,
|
|
340
|
+
business_connection_id: task.businessConnectionId,
|
|
341
|
+
reply_to_message_id: task.messageId,
|
|
328
342
|
});
|
|
329
343
|
}
|
|
330
344
|
return null;
|
|
@@ -477,9 +477,9 @@ export default class TelegramExecutionContext {
|
|
|
477
477
|
* @returns Promise with the API response
|
|
478
478
|
*/
|
|
479
479
|
async streamReply(message, draft_id, parse_mode = '', options = {}, finish = false) {
|
|
480
|
-
if (this.update_type === 'guest_message') {
|
|
480
|
+
if (this.update_type === 'guest_message' || this.update_type === 'business_message') {
|
|
481
481
|
if (finish) {
|
|
482
|
-
return await this.
|
|
482
|
+
return await this.reply(message, parse_mode, true, options);
|
|
483
483
|
}
|
|
484
484
|
return null;
|
|
485
485
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebam/cf-workers-telegram-bot",
|
|
3
|
-
"version": "12.6.
|
|
3
|
+
"version": "12.6.6",
|
|
4
4
|
"description": "serverless telegram bot on cf workers",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"module": "./dist/main.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test:all": "npm test && npm test --prefix ai-workflow && npm test --prefix consumer && npm test --prefix webapp",
|
|
30
30
|
"format": "prettier --write src test *.json *.js *.mjs",
|
|
31
31
|
"format:check": "prettier --check src test *.json *.js *.mjs",
|
|
32
|
-
"docs": "typedoc --options typedoc.json",
|
|
32
|
+
"docs": "typedoc --options typedoc.json && node fix-docs.js",
|
|
33
33
|
"deploy:docs": "npm run docs && wrangler pages deploy docs",
|
|
34
34
|
"ncu": "npx npm-check-updates -u --root",
|
|
35
35
|
"ncu:interactive": "npx npm-check-updates -i --root",
|