@@ -3,6 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "dist/serviceSeqTracker.js",
|
"main": "dist/serviceSeqTracker.js",
|
||||||
"types": "dist/serviceSeqTracker.d.ts",
|
"types": "dist/serviceSeqTracker.d.ts",
|
||||||
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./dist/serviceSeqTracker.js",
|
"import": "./dist/serviceSeqTracker.js",
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { MyContext } from "../../types/myContext";
|
|||||||
import { qrDb, messagesDb } from "../../dbs";
|
import { qrDb, messagesDb } from "../../dbs";
|
||||||
import type { MessageDocument } from "@hereconnect/types";
|
import type { MessageDocument } from "@hereconnect/types";
|
||||||
import { secondsToISOString } from "../../utils/date";
|
import { secondsToISOString } from "../../utils/date";
|
||||||
|
import { env } from "../../config/env";
|
||||||
|
import { escapeHtml } from "../../utils/escapeHtml";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Middleware for handling replies to messages containing QR code identifiers.
|
* Middleware for handling replies to messages containing QR code identifiers.
|
||||||
@@ -54,24 +56,29 @@ export const replayToQrCodeMessageMiddleware = async (
|
|||||||
if (!qrCodeDoc) {
|
if (!qrCodeDoc) {
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
`Я не смогу обработать это сообщение. QR-код с ID ${qr_code_uri} не найден.`,
|
`Я не смогу обработать это сообщение. QR-код с ID ${qr_code_uri} не найден.`,
|
||||||
|
{ reply_to_message_id: ctx.msg.message_id },
|
||||||
);
|
);
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.userDoc) {
|
if (!ctx.userDoc) {
|
||||||
await ctx.reply(`Я не смогу обработать это сообщение. Вы не авторизованы`);
|
await ctx.reply(`Я не смогу обработать это сообщение. Вы не авторизованы`, {
|
||||||
|
reply_to_message_id: ctx.msg.message_id,
|
||||||
|
});
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(ctx.userDoc?.telegram_id, "!==", qrCodeDoc.telegram_id);
|
console.log(ctx.userDoc?.telegram_id, "!==", qrCodeDoc.telegram_id);
|
||||||
|
|
||||||
if (ctx.userDoc?.telegram_id !== qrCodeDoc.telegram_id) {
|
if (ctx.userDoc?.user_uuid !== qrCodeDoc.user_uuid) {
|
||||||
await ctx.reply(`Я не смогу обработать это сообщение. Это не ваш QR-код`);
|
await ctx.reply(`Я не смогу обработать это сообщение. Это не ваш QR-код`, {
|
||||||
|
reply_to_message_id: ctx.msg.message_id,
|
||||||
|
});
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const created_at = secondsToISOString(ctx.msg.date);
|
const created_at = secondsToISOString(ctx.msg.date);
|
||||||
const user_uuid = ctx.userDoc!.user_uuid;
|
const user_uuid = ctx.userDoc.user_uuid;
|
||||||
const message: MessageDocument = {
|
const message: MessageDocument = {
|
||||||
_id: `message:${qr_code_uri}:${chat}:${created_at}`,
|
_id: `message:${qr_code_uri}:${chat}:${created_at}`,
|
||||||
type: "message",
|
type: "message",
|
||||||
@@ -85,8 +92,14 @@ export const replayToQrCodeMessageMiddleware = async (
|
|||||||
|
|
||||||
await messagesDb.put(message);
|
await messagesDb.put(message);
|
||||||
|
|
||||||
// Вы можете выполнить любую логику с этими данными
|
const hashTag = `#qr${qr_code_uri}_c${chat}`;
|
||||||
await ctx.reply(
|
const manageMessageUrl = `${env.APP_BASE_URL}/manage/qr/${qr_code_uri}/chat/${chat}#message-${encodeURIComponent(created_at)}`;
|
||||||
`Вы ответили на сообщение: "${originalMessage}" с текстом: "${ctx.msg.text}"`,
|
const text = `<i>переслал <a href="${escapeHtml(manageMessageUrl)}">сообщение</a> ${escapeHtml(hashTag)} QR-кода <b>«${escapeHtml(qrCodeDoc.name)}»</b></i>`;
|
||||||
);
|
|
||||||
|
await ctx.reply(text, {
|
||||||
|
parse_mode: "HTML",
|
||||||
|
link_preview_options: { is_disabled: true },
|
||||||
|
reply_markup: { force_reply: true },
|
||||||
|
reply_to_message_id: ctx.msg.message_id,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import type { MyContext } from "../types/myContext";
|
import type { MyContext } from "../types/myContext";
|
||||||
import { Bot, Context, Keyboard } from "grammy";
|
import { Bot } from "grammy";
|
||||||
import type { ServiceSeqTracker } from "@hereconnect/lib-service-seq-tracker";
|
import type { ServiceSeqTracker } from "@hereconnect/lib-service-seq-tracker";
|
||||||
import type { CouchDBChangesStream } from "@hereconnect/couchdb-changes-stream";
|
import type { CouchDBChangesStream } from "@hereconnect/couchdb-changes-stream";
|
||||||
import type { MessageDocument, UserDocument } from "@hereconnect/types";
|
import type { MessageDocument, UserDocument } from "@hereconnect/types";
|
||||||
import { qrDb, userChatSettingsDb, usersDb } from "../dbs";
|
import { qrDb, userChatSettingsDb, usersDb } from "../dbs";
|
||||||
// import { blockquote, fmt, italic, link } from "@grammyjs/parse-mode";
|
|
||||||
import { env } from "../config/env";
|
import { env } from "../config/env";
|
||||||
import { escapeHtml } from "../utils/escapeHtml";
|
import { escapeHtml } from "../utils/escapeHtml";
|
||||||
|
|
||||||
@@ -55,23 +54,11 @@ async function handleChange(msgDoc: MessageDocument, bot: Bot<MyContext>) {
|
|||||||
|
|
||||||
const hashTag = `#qr${qrDoc.uri}_c${msgDoc.chat}`;
|
const hashTag = `#qr${qrDoc.uri}_c${msgDoc.chat}`;
|
||||||
const manageMessageUrl = `${env.APP_BASE_URL}/manage/qr/${qrDoc.uri}/chat/${msgDoc.chat}#message-${encodeURIComponent(msgDoc.created_at)}`;
|
const manageMessageUrl = `${env.APP_BASE_URL}/manage/qr/${qrDoc.uri}/chat/${msgDoc.chat}#message-${encodeURIComponent(msgDoc.created_at)}`;
|
||||||
// const manageMessageUrl = `tg://resolve?domain=${bot.botInfo.username}&start=message:${qrDoc.uri}:${msgDoc.created_at}`;
|
const text = `${escapeHtml(msgDoc.body.trim())} — <i><a href="${escapeHtml(manageMessageUrl)}">сообщение</a> ${escapeHtml(hashTag)} QR-кода <b>«${escapeHtml(qrDoc.name)}»</b></i>`;
|
||||||
// const msgCaption = ` — ${link("сообщение", manageMessageUrl)} QR-кода «${qrDoc.name}»`;
|
|
||||||
|
|
||||||
// const caption = fmt`${link("сообщение", manageMessageUrl)} QR-кода «${qrDoc.name}»`;
|
|
||||||
// const body = fmt`${msgDoc.body.trim()} — ${italic(caption)}`;
|
|
||||||
|
|
||||||
const body = {
|
|
||||||
text: `${escapeHtml(msgDoc.body.trim())} — <i><a href="${escapeHtml(manageMessageUrl)}">сообщение</a> ${escapeHtml(hashTag)} QR-кода <b>«${escapeHtml(qrDoc.name)}»</b></i>`,
|
|
||||||
entities: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const telegramUserDoc of telegramUsersDocs) {
|
for (const telegramUserDoc of telegramUsersDocs) {
|
||||||
await bot.api.sendMessage(telegramUserDoc.telegram_id, body.text, {
|
await bot.api.sendMessage(telegramUserDoc.telegram_id, text, {
|
||||||
parse_mode: "HTML",
|
parse_mode: "HTML",
|
||||||
// parse_mode: "MarkdownV2",
|
|
||||||
link_preview_options: { is_disabled: true },
|
link_preview_options: { is_disabled: true },
|
||||||
entities: body.entities,
|
|
||||||
reply_markup: { force_reply: true },
|
reply_markup: { force_reply: true },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ export const createServiceChangesMessagesDb = async ({
|
|||||||
filter: "_selector",
|
filter: "_selector",
|
||||||
selector: {
|
selector: {
|
||||||
type: "message",
|
type: "message",
|
||||||
},
|
from: "guest",
|
||||||
|
} satisfies Partial<MessageDocument>,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user