fix: reply with connect instructions on plain telegram start
This commit is contained in:
@@ -35,12 +35,32 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
const startText = pickStartText(update);
|
const startText = pickStartText(update);
|
||||||
const linkToken = startText ? extractLinkTokenFromStartText(startText) : null;
|
const linkToken = startText ? extractLinkTokenFromStartText(startText) : null;
|
||||||
|
const startChatId = getTelegramChatIdFromUpdate(update);
|
||||||
|
|
||||||
|
if (startText && !linkToken) {
|
||||||
|
if (startChatId) {
|
||||||
|
void telegramBotApi("sendMessage", {
|
||||||
|
chat_id: startChatId,
|
||||||
|
text: "Чтобы привязать Telegram Business к CRM, открой CRM → Settings → Telegram Business → Connect. Кнопка сгенерирует персональную ссылку привязки.",
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
return { ok: true, accepted: true, type: "start_without_link_token" };
|
||||||
|
}
|
||||||
|
|
||||||
if (linkToken) {
|
if (linkToken) {
|
||||||
const payload = verifyLinkToken(linkToken);
|
const payload = verifyLinkToken(linkToken);
|
||||||
if (!payload) return { ok: true, accepted: false, reason: "invalid_or_expired_link_token" };
|
if (!payload) {
|
||||||
|
if (startChatId) {
|
||||||
|
void telegramBotApi("sendMessage", {
|
||||||
|
chat_id: startChatId,
|
||||||
|
text: "Ссылка привязки недействительна или истекла. Вернись в CRM и нажми Connect заново.",
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
return { ok: true, accepted: false, reason: "invalid_or_expired_link_token" };
|
||||||
|
}
|
||||||
|
|
||||||
const pendingId = `pending:${payload.nonce}`;
|
const pendingId = `pending:${payload.nonce}`;
|
||||||
const chatId = getTelegramChatIdFromUpdate(update);
|
const chatId = startChatId;
|
||||||
|
|
||||||
await prisma.telegramBusinessConnection.updateMany({
|
await prisma.telegramBusinessConnection.updateMany({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in New Issue
Block a user