Skip to content

weixin-ts / bot/src / requestQRCode

Function: requestQRCode()

requestQRCode(options?): Promise<QRCodeResult>

Defined in: bot/src/auth/login.ts:116

Request a QR code for WeChat bot login.

Returns the QR URL and a poll() function to wait for scan confirmation. This is the entry point for the login flow.

Parameters

options?

QRLoginOptions

Returns

Promise<QRCodeResult>

Example

ts
import { requestQRCode } from '@weixin-ts/bot'

const { qrcodeUrl, poll } = await requestQRCode()

// Display QR however you want (terminal, web page, etc.)
console.log('Scan this:', qrcodeUrl)

// Wait for user to scan and confirm
const result = await poll({
  onScanned: () => console.log('Scanned! Please confirm in WeChat.'),
})

if (result.success) {
  console.log('Token:', result.botToken)
}

Released under the MIT License.