@coffer-org/plugin-telegram 2.2.0 → 2.2.2
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/runtime/bot.js +5 -6
- package/dist/runtime/index.js +5 -0
- package/package.json +3 -3
package/dist/runtime/bot.js
CHANGED
|
@@ -7,7 +7,6 @@ import { NewMessage } from 'teleproto/events/index.js';
|
|
|
7
7
|
import { handleIncoming, loadGatePolicy, makeLiveChannel, chunk } from '@coffer-org/plugin-orchestrator/runtime';
|
|
8
8
|
import { recordUser, recordAssistant, buildChain } from "./chain-store.js";
|
|
9
9
|
import { loadBotConfig, hasCredentials, loadReasoningDisplay } from "./config.js";
|
|
10
|
-
import { saveUploadBytes } from '@coffer-org/server/uploads';
|
|
11
10
|
import { getLogger } from '@coffer-org/sdk/logger';
|
|
12
11
|
const log = getLogger('telegram');
|
|
13
12
|
const FALLBACK_REPLY_WINDOW_MS = 1_800_000;
|
|
@@ -89,13 +88,13 @@ function mediaInfo(message) {
|
|
|
89
88
|
return { mime: 'image/jpeg', label: 'photo.jpg' };
|
|
90
89
|
return null;
|
|
91
90
|
}
|
|
92
|
-
async function downloadAttachment(tg, message, info) {
|
|
91
|
+
async function downloadAttachment(tg, message, info, materializer) {
|
|
93
92
|
const downloaded = await tg.downloadMedia(message, {});
|
|
94
93
|
if (!downloaded || typeof downloaded === 'string')
|
|
95
94
|
throw new Error('Telegram returned no in-memory media bytes');
|
|
96
95
|
const bytes = Buffer.isBuffer(downloaded) ? downloaded : Buffer.from(downloaded);
|
|
97
|
-
const stored = await
|
|
98
|
-
return {
|
|
96
|
+
const stored = await materializer.store(bytes, { originalName: info.label, mime: info.mime });
|
|
97
|
+
return { ...stored, label: info.label };
|
|
99
98
|
}
|
|
100
99
|
function loadSessionString(file) {
|
|
101
100
|
try {
|
|
@@ -258,10 +257,10 @@ export async function startBot(opts = {}) {
|
|
|
258
257
|
const messages = await buildChain(incomingMsgId, { chatId, fetch, botId: meId ?? '' });
|
|
259
258
|
let preparedMessages;
|
|
260
259
|
const prepareAttachments = attachmentInfo
|
|
261
|
-
? async () => {
|
|
260
|
+
? async (materializer) => {
|
|
262
261
|
if (preparedMessages)
|
|
263
262
|
return preparedMessages;
|
|
264
|
-
const attachment = await downloadAttachment(tg, message, attachmentInfo);
|
|
263
|
+
const attachment = await downloadAttachment(tg, message, attachmentInfo, materializer);
|
|
265
264
|
await recordUser({
|
|
266
265
|
chatId,
|
|
267
266
|
msgId: incomingMsgId,
|
package/dist/runtime/index.js
CHANGED
|
@@ -2,16 +2,21 @@ import { getPluginSettings } from '@coffer-org/server/plugin-runtime';
|
|
|
2
2
|
import { pruneThreadMessages } from '@coffer-org/server/thread-store';
|
|
3
3
|
import { startBot, stopBot } from "./bot.js";
|
|
4
4
|
import { getLogger } from '@coffer-org/sdk/logger';
|
|
5
|
+
import { registerConnector } from '@coffer-org/plugin-orchestrator/runtime';
|
|
5
6
|
const log = getLogger('telegram');
|
|
6
7
|
const THREAD_TTL_MS = Number(process.env['TELEGRAM_THREAD_TTL_MS'] ?? 7 * 86_400_000);
|
|
8
|
+
let unregisterConnector;
|
|
7
9
|
export { startBot, stopBot };
|
|
8
10
|
export { loadBotConfig, hasCredentials } from "./config.js";
|
|
9
11
|
export const serverHooks = {
|
|
10
12
|
init: async () => {
|
|
13
|
+
unregisterConnector = registerConnector({ id: 'telegram' });
|
|
11
14
|
const dbSettings = await getPluginSettings('telegram');
|
|
12
15
|
void startBot({ dbSettings }).catch((e) => log.warn(`failed to start: ${e.message}`));
|
|
13
16
|
},
|
|
14
17
|
teardown: async () => {
|
|
18
|
+
unregisterConnector?.();
|
|
19
|
+
unregisterConnector = undefined;
|
|
15
20
|
await stopBot();
|
|
16
21
|
},
|
|
17
22
|
backgroundTasks: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffer-org/plugin-telegram",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"test": "node --import tsx --test \"src/runtime/*.test.ts\""
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@coffer-org/plugin-orchestrator": "^2.
|
|
29
|
-
"@coffer-org/sdk": "^2.1.
|
|
28
|
+
"@coffer-org/plugin-orchestrator": "^2.3.0",
|
|
29
|
+
"@coffer-org/sdk": "^2.1.2",
|
|
30
30
|
"@coffer-org/server": "^2.3.0",
|
|
31
31
|
"input": "^1.0.1",
|
|
32
32
|
"teleproto": "^1.228.1"
|