(apiBaseUrl: string, accountId?: string, botType = DEFAULT_ILINK_BOT_TYPE)
| 243 | } |
| 244 | |
| 245 | async function fetchWeChatQrCode(apiBaseUrl: string, accountId?: string, botType = DEFAULT_ILINK_BOT_TYPE): Promise<QrCodeResponse> { |
| 246 | const base = apiBaseUrl.endsWith('/') ? apiBaseUrl : `${apiBaseUrl}/`; |
| 247 | const url = new URL(`ilink/bot/get_bot_qrcode?bot_type=${encodeURIComponent(botType)}`, base); |
| 248 | const headers: Record<string, string> = {}; |
| 249 | const routeTag = loadWeChatRouteTag(accountId); |
| 250 | if (routeTag) { |
| 251 | headers.SKRouteTag = routeTag; |
| 252 | } |
| 253 | |
| 254 | const response = await fetch(url.toString(), { headers }); |
| 255 | if (!response.ok) { |
| 256 | const body = await response.text().catch(() => '(unreadable)'); |
| 257 | throw new Error(`Failed to fetch QR code: ${response.status} ${response.statusText} ${body}`); |
| 258 | } |
| 259 | return await response.json() as QrCodeResponse; |
| 260 | } |
| 261 | |
| 262 | async function pollWeChatQrStatus(apiBaseUrl: string, qrcode: string, accountId?: string): Promise<QrStatusResponse> { |
| 263 | const base = apiBaseUrl.endsWith('/') ? apiBaseUrl : `${apiBaseUrl}/`; |
no test coverage detected