feat: implement token-complete telegram connect flow via bot button
This commit is contained in:
@@ -598,6 +598,7 @@ const telegramConnectBusy = ref(false);
|
||||
const telegramRefreshBusy = ref(false);
|
||||
const telegramConnectUrl = ref("");
|
||||
const telegramConnections = ref<TelegramConnectionSummary[]>([]);
|
||||
const telegramConnectNotice = ref("");
|
||||
|
||||
const telegramStatusLabel = computed(() => {
|
||||
if (telegramConnectStatusLoading.value) return "Checking";
|
||||
@@ -697,6 +698,39 @@ async function refreshTelegramBusinessConnectionFromApi() {
|
||||
}
|
||||
}
|
||||
|
||||
async function completeTelegramBusinessConnectFromToken(token: string) {
|
||||
const t = String(token || "").trim();
|
||||
if (!t) return;
|
||||
|
||||
try {
|
||||
const result = await $fetch<{
|
||||
ok: boolean;
|
||||
status: string;
|
||||
businessConnectionId?: string;
|
||||
}>("/api/omni/telegram/business/connect/complete", {
|
||||
method: "POST",
|
||||
body: { token: t },
|
||||
});
|
||||
|
||||
if (result?.ok) {
|
||||
telegramConnectStatus.value = "connected";
|
||||
telegramConnectNotice.value = "Telegram успешно привязан.";
|
||||
await loadTelegramConnectStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result?.status === "awaiting_telegram_start") {
|
||||
telegramConnectNotice.value = "Сначала нажмите Start в Telegram, затем нажмите кнопку в боте снова.";
|
||||
} else if (result?.status === "invalid_or_expired_token") {
|
||||
telegramConnectNotice.value = "Ссылка привязки истекла. Нажмите Connect в CRM заново.";
|
||||
} else {
|
||||
telegramConnectNotice.value = "Не удалось завершить привязку. Запустите Connect заново.";
|
||||
}
|
||||
} catch {
|
||||
telegramConnectNotice.value = "Ошибка завершения привязки. Попробуйте снова.";
|
||||
}
|
||||
}
|
||||
|
||||
function pilotToUiMessage(message: PilotMessage): UIMessage {
|
||||
return {
|
||||
id: message.id,
|
||||
@@ -2012,6 +2046,14 @@ onMounted(() => {
|
||||
|
||||
uiPathSyncLocked.value = true;
|
||||
try {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const tgLinkToken = String(params.get("tg_link_token") ?? "").trim();
|
||||
if (tgLinkToken) {
|
||||
void completeTelegramBusinessConnectFromToken(tgLinkToken);
|
||||
params.delete("tg_link_token");
|
||||
const nextSearch = params.toString();
|
||||
window.history.replaceState({}, "", `${window.location.pathname}${nextSearch ? `?${nextSearch}` : ""}`);
|
||||
}
|
||||
applyPathToUi(window.location.pathname, window.location.search);
|
||||
} finally {
|
||||
uiPathSyncLocked.value = false;
|
||||
@@ -4057,6 +4099,9 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
|
||||
{{ telegramRefreshBusy ? "Syncing..." : "Refresh from API" }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="telegramConnectNotice" class="text-[11px] leading-snug text-base-content/70">
|
||||
{{ telegramConnectNotice }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 border-t border-base-300 pt-2">
|
||||
|
||||
Reference in New Issue
Block a user