@kieksme/csp-plugin-telegram 0.11.0 → 0.12.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/README.md +2 -0
- package/dist/browser.js +1 -1
- package/dist/{chunk-PGRFWYJH.js → chunk-CN5ESZIH.js} +1 -1
- package/dist/server.js +40 -6
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -11,3 +11,5 @@ pnpm dlx @kieksme/csp-cli plugin add @kieksme/csp-plugin-telegram
|
|
|
11
11
|
Offene Webseiten verwenden `chatSupport: { "mode": "telegram", "auth": "anonymous" }`; alternativ Entra-Login. Bot-Token und Webhook-Secret gehören ausschließlich auf den API-Host. Genau ein Supporttransport je Instanz.
|
|
12
12
|
|
|
13
13
|
[Einrichtung, Rechte, Architektur und Grenzen](https://github.com/kieksme/csp/wiki/telegram-support). Reale Telegram-Verbindung **noch ungetestet**; automatisierte Prüfungen verwenden synthetische Antworten.
|
|
14
|
+
|
|
15
|
+
Explicit human requests use the shared persistent waiting state and directed notifications, with current support membership checks. See [shared chat behaviour](../../docs/chat.md).
|
package/dist/browser.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
cspPlugin
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CN5ESZIH.js";
|
|
4
4
|
|
|
5
5
|
// src/server.ts
|
|
6
6
|
import {
|
|
@@ -225,7 +225,7 @@ function chunks(text, limit) {
|
|
|
225
225
|
return result;
|
|
226
226
|
}
|
|
227
227
|
function card(c) {
|
|
228
|
-
const status = c.status === "bot" ? "Digitaler Assistent" : c.status === "closed" ? c.resolution ? "Problem gel\xF6st" : "Abgeschlossen" : `Support: ${c.support?.name}`;
|
|
228
|
+
const status = c.status === "bot" || c.status === "waiting" ? c.status === "waiting" ? "Pers\xF6nlicher Support angefragt \xB7 KI pausiert" : "Digitaler Assistent" : c.status === "closed" ? c.resolution ? "Problem gel\xF6st" : "Abgeschlossen" : `Support: ${c.support?.name}`;
|
|
229
229
|
return {
|
|
230
230
|
text: `Portal-Support
|
|
231
231
|
Portal-Nutzer: ${c.owner.name}
|
|
@@ -233,7 +233,7 @@ Gespr\xE4ch: ${c.id}
|
|
|
233
233
|
Status: ${status}`,
|
|
234
234
|
reply_markup: {
|
|
235
235
|
inline_keyboard: c.status === "closed" ? [] : [
|
|
236
|
-
(c.status === "bot" ? [
|
|
236
|
+
(c.status === "bot" || c.status === "waiting" ? [
|
|
237
237
|
["take", "\xDCbernehmen"],
|
|
238
238
|
["resolve", "Problem gel\xF6st"]
|
|
239
239
|
] : [
|
|
@@ -328,7 +328,7 @@ async function createTelegramBridge(app, store, config, fetcher = fetch, onTake
|
|
|
328
328
|
409,
|
|
329
329
|
"Gespr\xE4chslimit erreicht. Bitte abschlie\xDFen."
|
|
330
330
|
);
|
|
331
|
-
const transition = job.action === "take" && c.status === "bot" || job.action === "resolve" && c.status !== "closed";
|
|
331
|
+
const transition = job.action === "take" && (c.status === "bot" || c.status === "waiting") || job.action === "resolve" && c.status !== "closed";
|
|
332
332
|
action(c, job.action, person, queue);
|
|
333
333
|
c.supportActionAt = job.timestamp;
|
|
334
334
|
if (job.action === "take" && transition)
|
|
@@ -393,7 +393,7 @@ async function createTelegramBridge(app, store, config, fetcher = fetch, onTake
|
|
|
393
393
|
const match = /^(take|release|close|resolve):([a-f0-9-]{36})$/.exec(
|
|
394
394
|
callback.data ?? ""
|
|
395
395
|
);
|
|
396
|
-
if (!match || match[2] !== c.id || String(m.message_id) !== c.thread?.serviceUrl || m.from?.id !== bot.id)
|
|
396
|
+
if (!match || match[2] !== c.id || String(m.message_id) !== c.thread?.serviceUrl && String(m.message_id) !== c.supportRequest?.messageId || m.from?.id !== bot.id)
|
|
397
397
|
return { ok: true };
|
|
398
398
|
command = match[1];
|
|
399
399
|
} else if (!m.text?.trim()) return { ok: true };
|
|
@@ -439,7 +439,41 @@ async function createTelegramBridge(app, store, config, fetcher = fetch, onTake
|
|
|
439
439
|
chat_id: config.CSP_TELEGRAM_CHAT_ID,
|
|
440
440
|
message_thread_id: Number(c.thread.rootId)
|
|
441
441
|
};
|
|
442
|
-
if (job.kind === "
|
|
442
|
+
if (job.kind === "request") {
|
|
443
|
+
if (c.status !== "waiting" || c.supportRequest?.id !== job.id || c.supportRequest.messageId)
|
|
444
|
+
return;
|
|
445
|
+
const targets = [];
|
|
446
|
+
for (const id of job.targets ?? []) {
|
|
447
|
+
const person = await authorize(id);
|
|
448
|
+
if (person) targets.push({ id, name: person.name });
|
|
449
|
+
}
|
|
450
|
+
const names = targets.map((p) => p.name).join(", ");
|
|
451
|
+
const text = names + (names ? ": " : "") + "Pers\xF6nlicher Support angefragt. Bitte \xFCbernehmen.";
|
|
452
|
+
let offset = 0;
|
|
453
|
+
const entities = targets.map((p) => {
|
|
454
|
+
const entity = {
|
|
455
|
+
type: "text_mention",
|
|
456
|
+
offset,
|
|
457
|
+
length: p.name.length,
|
|
458
|
+
user: { id: Number(p.id) }
|
|
459
|
+
};
|
|
460
|
+
offset += p.name.length + 2;
|
|
461
|
+
return entity;
|
|
462
|
+
});
|
|
463
|
+
const result = z2.object({ message_id: integer.positive() }).parse(
|
|
464
|
+
await api("sendMessage", {
|
|
465
|
+
...base,
|
|
466
|
+
text,
|
|
467
|
+
entities,
|
|
468
|
+
reply_markup: card(c).reply_markup,
|
|
469
|
+
link_preview_options: { is_disabled: true }
|
|
470
|
+
})
|
|
471
|
+
);
|
|
472
|
+
await store.change(c.id, (current) => {
|
|
473
|
+
if (current.supportRequest?.id === job.id)
|
|
474
|
+
current.supportRequest.messageId = String(result.message_id);
|
|
475
|
+
});
|
|
476
|
+
} else if (job.kind === "create" || job.kind === "card") {
|
|
443
477
|
if (c.thread.serviceUrl) {
|
|
444
478
|
await api("editMessageText", {
|
|
445
479
|
chat_id: base.chat_id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kieksme/csp-plugin-telegram",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"registry": "https://registry.npmjs.org"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@kieksme/csp-sdk": "^0.
|
|
26
|
-
"@kieksme/csp-core": "^0.
|
|
25
|
+
"@kieksme/csp-sdk": "^0.12.0",
|
|
26
|
+
"@kieksme/csp-core": "^0.12.0",
|
|
27
27
|
"zod": "^3.25.76",
|
|
28
28
|
"fastify": "^5.6.1"
|
|
29
29
|
},
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"cspPlugin": {
|
|
34
34
|
"id": "telegram",
|
|
35
|
-
"sdkVersion": "^0.
|
|
35
|
+
"sdkVersion": "^0.12.0",
|
|
36
36
|
"browser": "./browser",
|
|
37
37
|
"server": "./server",
|
|
38
38
|
"requires": [
|