wapair

package
v0.0.0-...-a981527 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package wapair drives the WhatsApp Web QR pairing flow.

It is the WhatsApp counterpart to internal/devicecode: a small, UI-agnostic driver that both `forge channel whatsapp-login` and the init wizard's channel step use, so the pairing state machine lives in exactly one place.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QRDimensions

func QRDimensions(code string) (rows, cols int)

QRDimensions reports the rows and columns RenderQR needs for code, so a caller can warn before drawing something the terminal will wrap into unscannable noise.

func RenderQR

func RenderQR(code string, w io.Writer)

RenderQR writes code as a scannable QR block.

Half-block rendering keeps the code square in a terminal whose cells are taller than they are wide; a full-block render is stretched and many phones fail to lock onto it. QuietZone is 1 rather than qrterminal's default 4 — the standard 4-module margin costs 6 rows and 6 columns, which is the difference between fitting and not fitting in a typical 80x30 terminal. Phones scan reliably at 1 against a contrasting terminal background.

Types

type Event

type Event struct {
	Kind    EventKind
	Code    string        // EventQR: the raw payload to encode
	Timeout time.Duration // EventQR: how long until the next code
	JID     string        // EventPaired: the linked account
	Err     error         // EventError
}

Event is one step of the pairing flow.

type EventKind

type EventKind int

EventKind discriminates the events a pairing session emits.

const (
	// EventQR carries a new code to display. WhatsApp rotates codes every
	// ~20s, so several of these arrive before the user finishes scanning.
	EventQR EventKind = iota
	// EventScanned means the phone accepted the code and the post-pair
	// handshake is running. NOT yet usable — EventPaired is the completion.
	EventScanned
	// EventPaired means the scan succeeded and the session is persisted.
	EventPaired
	// EventError is terminal: the session cannot complete.
	EventError
)

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session is an in-flight pairing attempt. Close it when done — it holds an open socket and a SQLite handle.

func Start

func Start(ctx context.Context, sessionPath string) (*Session, error)

Start opens (creating if absent) the session store at sessionPath and begins a pairing attempt. Events are delivered on Events() until the channel closes.

The caller owns the returned Session and must Close it.

func (*Session) Close

func (s *Session) Close() error

Close tears down the socket and the session store. Safe to call repeatedly.

func (*Session) Events

func (s *Session) Events() <-chan Event

Events returns the pairing event stream. It closes when the flow reaches a terminal state.

func (*Session) SessionPath

func (s *Session) SessionPath() string

SessionPath is where the pairing is persisted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL