feat: add crm return button in telegram connect messages
This commit is contained in:
@@ -25,6 +25,23 @@ function pickStartText(update: any): string | null {
|
||||
return text;
|
||||
}
|
||||
|
||||
function crmConnectUrl() {
|
||||
return String(process.env.CRM_APP_URL || "https://clientsflow.dsrptlab.com").trim();
|
||||
}
|
||||
|
||||
function crmConnectButton() {
|
||||
return {
|
||||
inline_keyboard: [
|
||||
[
|
||||
{
|
||||
text: "Открыть CRM и подтвердить",
|
||||
url: crmConnectUrl(),
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
if (!hasValidSecret(event)) {
|
||||
throw createError({ statusCode: 401, statusMessage: "invalid webhook secret" });
|
||||
@@ -42,6 +59,7 @@ export default defineEventHandler(async (event) => {
|
||||
void telegramBotApi("sendMessage", {
|
||||
chat_id: startChatId,
|
||||
text: "Чтобы привязать Telegram Business к CRM, открой CRM → Settings → Telegram Business → Connect. Кнопка сгенерирует персональную ссылку привязки.",
|
||||
reply_markup: crmConnectButton(),
|
||||
}).catch(() => {});
|
||||
}
|
||||
return { ok: true, accepted: true, type: "start_without_link_token" };
|
||||
@@ -54,6 +72,7 @@ export default defineEventHandler(async (event) => {
|
||||
void telegramBotApi("sendMessage", {
|
||||
chat_id: startChatId,
|
||||
text: "Ссылка привязки недействительна или истекла. Вернись в CRM и нажми Connect заново.",
|
||||
reply_markup: crmConnectButton(),
|
||||
}).catch(() => {});
|
||||
}
|
||||
return { ok: true, accepted: false, reason: "invalid_or_expired_link_token" };
|
||||
@@ -85,7 +104,8 @@ export default defineEventHandler(async (event) => {
|
||||
if (chatId) {
|
||||
void telegramBotApi("sendMessage", {
|
||||
chat_id: chatId,
|
||||
text: "CRM: связка аккаунта получена. Теперь подключите Telegram Business в настройках Telegram, затем вернитесь в CRM и обновите статус.",
|
||||
text: "CRM: связка аккаунта получена. Нажми кнопку ниже и вернись в CRM для подтверждения.",
|
||||
reply_markup: crmConnectButton(),
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user