Skip to main content
Bot platform adapters now ship in the praisonai-bot package. praisonai bot serve still works exactly as documented here; for a standalone install see praisonai-bot Migration.
Bot pairing lets unknown users self-request access to your bot with secure 8-character codes that you approve from the CLI.
The user DMs the bot for the first time; PraisonAI issues an 8-character code you approve from the CLI.

Quick Start

1

Enable Pairing Policy

The same config from gateway.yaml — both keys are read per-channel (PR #2856):
2

Approve Pairing Requests


How It Works

The pairing flow now fires only when BotConfig.is_explicitly_allowed(user_id) returns False (empty allowlist, or user not on it). Users on allowed_users skip pairing entirely — PR #2856.

Policy Configuration

Unknown User Policies

Pairing Rate Limiting

The system includes built-in protection against code generation spam:
  • Rate Limit: 10 minutes between code generations per channel
  • Code TTL: Codes expire after a configurable time (default: check PaisingStore implementation)
  • Automatic Cleanup: Stale rate limit entries are automatically evicted

CLI Commands

List Commands

Approve Command

Revoke Access


Web-UI / HTTP API Approval

Approve, list, and revoke pairings from a web admin UI via the gateway’s HTTP API.

Endpoints

GET /api/pairing/pendingReturns pending pairing requests awaiting approval.
All three routes are gated by an admin auth checker (auth_admin) wired in by create_pairing_routes(pairing_store, auth_admin). Non-admin sessions receive 403. Invalid codes return 404.
The code parameter on /approve is consumed atomically — replays return 404.

Reacting to Pairing Approvals (EventBus)

Subscribe to the pairing_approved event to run agent logic the moment a channel is approved — for example, send a welcome DM, log to your CRM, or warm a per-user memory store.

Event Payload

Handlers run synchronously in the request path — keep them fast or hand off to a background queue.

Platform Support

Current Implementation

Platform Implementation Status: PR #1504 ships the pairing system and CLI with full Telegram support. Other platform adapters need handler wiring to complete the integration.

Telegram Integration


Security Model

Code Generation

  • 8-character codes: Hex format (e.g., ABCD1234)
  • HMAC signatures: Codes are cryptographically signed
  • Per-install secret: Auto-generated if PRAISONAI_GATEWAY_SECRET unset
  • Channel binding: Codes can be bound to specific channel IDs

Secret Management

Secret Persistence & Remediation (updated in PR #2850):Without PRAISONAI_GATEWAY_SECRET, a per-install HMAC secret is auto-generated at <store_dir>/.gateway_secret with mode 0o600. This file signs pairing codes, so world-readable permissions would let an attacker forge codes. Every PairingStore(...) construction re-checks and remediates the file — not only at creation:
  • POSIX: any mode other than 0o600 is chmod-ed to 0o600 and an INFO line is logged ("Remediated insecure gateway secret permissions <mode> -> 0o600 at <path>"). If chmod itself fails, PairingStore construction raises OSError (fail closed). It deliberately does not fall back to regenerating the secret, because regeneration would rotate the HMAC key and invalidate every outstanding pairing code.
  • Windows: POSIX mode bits are not authoritative. A best-effort ACL lockdown runs via %SystemRoot%\System32\icacls.exe <path> /inheritance:r /grant:r "<user>":F — inheritance stripped, current user granted Full access. icacls is resolved from System32 (not PATH) to avoid a hijacked binary. Success and failure both log at DEBUG only, no operator action is required, and this path never raises.
An existing 0o666 file left over from an older install is fixed automatically on the next startup — no manual chmod needed. See Security → PR #2850 for the hardening summary.

Security Features

  1. Rate Limiting: 600s (10 min) window per channel prevents spam
  2. HMAC Verification: Codes are cryptographically signed and verified
  3. TTL Expiration: Codes automatically expire after configured time
  4. Atomic Operations: Pairing state persisted atomically to disk

User Interaction Flow

Step-by-Step Process

  1. Unknown User DMs Bot
  2. Bot Generates Pairing Code
  3. Owner Approves via CLI
  4. User Can Now Interact Normally

Rate Limit Handling

If a user tries to generate codes too frequently:
The user must wait for the rate limit window (10 minutes) to expire before requesting a new code.

Configuration Options

Store Directory

Environment Variables


Best Practices

Set PRAISONAI_GATEWAY_SECRET explicitly in production environments to ensure consistent code verification across deployments.
Watch for rate limiting warnings in logs - they indicate potential pairing spam or legitimate users hitting limits.
Add labels when approving pairings to identify channels later.
Periodically review paired channels and revoke access for inactive users.

Pair a user with a non-empty --label (the canonical id) and StoreBackedIdentityResolver automatically unifies their session across every channel paired under the same label. No separate praisonai identity link calls needed. See Cross-Platform Sessions › StoreBackedIdentityResolver.

Bot Security

Comprehensive bot security and DM policies

Messaging Bots

Bot platform setup and configuration

Cross-Platform Sessions

Unified per-user sessions across platforms