@@ -2,6 +2,8 @@ import { MyContext } from "../../types/myContext";
|
||||
import { qrDb, messagesDb } from "../../dbs";
|
||||
import type { MessageDocument } from "@hereconnect/types";
|
||||
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.
|
||||
@@ -54,24 +56,29 @@ export const replayToQrCodeMessageMiddleware = async (
|
||||
if (!qrCodeDoc) {
|
||||
await ctx.reply(
|
||||
`Я не смогу обработать это сообщение. QR-код с ID ${qr_code_uri} не найден.`,
|
||||
{ reply_to_message_id: ctx.msg.message_id },
|
||||
);
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!ctx.userDoc) {
|
||||
await ctx.reply(`Я не смогу обработать это сообщение. Вы не авторизованы`);
|
||||
await ctx.reply(`Я не смогу обработать это сообщение. Вы не авторизованы`, {
|
||||
reply_to_message_id: ctx.msg.message_id,
|
||||
});
|
||||
return next();
|
||||
}
|
||||
|
||||
console.log(ctx.userDoc?.telegram_id, "!==", qrCodeDoc.telegram_id);
|
||||
|
||||
if (ctx.userDoc?.telegram_id !== qrCodeDoc.telegram_id) {
|
||||
await ctx.reply(`Я не смогу обработать это сообщение. Это не ваш QR-код`);
|
||||
if (ctx.userDoc?.user_uuid !== qrCodeDoc.user_uuid) {
|
||||
await ctx.reply(`Я не смогу обработать это сообщение. Это не ваш QR-код`, {
|
||||
reply_to_message_id: ctx.msg.message_id,
|
||||
});
|
||||
return next();
|
||||
}
|
||||
|
||||
const created_at = secondsToISOString(ctx.msg.date);
|
||||
const user_uuid = ctx.userDoc!.user_uuid;
|
||||
const user_uuid = ctx.userDoc.user_uuid;
|
||||
const message: MessageDocument = {
|
||||
_id: `message:${qr_code_uri}:${chat}:${created_at}`,
|
||||
type: "message",
|
||||
@@ -85,8 +92,14 @@ export const replayToQrCodeMessageMiddleware = async (
|
||||
|
||||
await messagesDb.put(message);
|
||||
|
||||
// Вы можете выполнить любую логику с этими данными
|
||||
await ctx.reply(
|
||||
`Вы ответили на сообщение: "${originalMessage}" с текстом: "${ctx.msg.text}"`,
|
||||
);
|
||||
const hashTag = `#qr${qr_code_uri}_c${chat}`;
|
||||
const manageMessageUrl = `${env.APP_BASE_URL}/manage/qr/${qr_code_uri}/chat/${chat}#message-${encodeURIComponent(created_at)}`;
|
||||
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 { Bot, Context, Keyboard } from "grammy";
|
||||
import { Bot } from "grammy";
|
||||
import type { ServiceSeqTracker } from "@hereconnect/lib-service-seq-tracker";
|
||||
import type { CouchDBChangesStream } from "@hereconnect/couchdb-changes-stream";
|
||||
import type { MessageDocument, UserDocument } from "@hereconnect/types";
|
||||
import { qrDb, userChatSettingsDb, usersDb } from "../dbs";
|
||||
// import { blockquote, fmt, italic, link } from "@grammyjs/parse-mode";
|
||||
import { env } from "../config/env";
|
||||
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 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 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,
|
||||
};
|
||||
|
||||
const text = `${escapeHtml(msgDoc.body.trim())} — <i><a href="${escapeHtml(manageMessageUrl)}">сообщение</a> ${escapeHtml(hashTag)} QR-кода <b>«${escapeHtml(qrDoc.name)}»</b></i>`;
|
||||
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: "MarkdownV2",
|
||||
link_preview_options: { is_disabled: true },
|
||||
entities: body.entities,
|
||||
reply_markup: { force_reply: true },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ export const createServiceChangesMessagesDb = async ({
|
||||
filter: "_selector",
|
||||
selector: {
|
||||
type: "message",
|
||||
},
|
||||
from: "guest",
|
||||
} satisfies Partial<MessageDocument>,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user