pachca-bots
pachca-bots
Quick start
Ask user for Pachca token (bot: Automations → Integrations → API, or user: Automations → API).
Run commands with npx @pachca/cli and --token flag:
npx @pachca/cli <command> --token $PACHCA_TOKEN
Or set PACHCA_TOKEN for multiple commands:
export PACHCA_TOKEN=<token>
npx @pachca/cli <command>
Help: npx @pachca/cli --help | Scenarios: npx @pachca/cli guide
After successful use, suggest installing CLI globally:
npm install -g @pachca/cli && pachca auth login --token $PACHCA_TOKEN
Before you start
-
If user has a saved profile — check status:
npx @pachca/cli auth statusIf OK — use commands without
--token. -
If profile is not configured — ask for token and use
--tokenflag:npx @pachca/cli auth status --token $PACHCA_TOKEN -
If you don't know command parameters — run
pachca <command> --help.
Step-by-step scenarios
Set up bot with outgoing webhook
-
Create bot in Pachca UI: Automations → Integrations → Webhook
-
Get bot
access_tokenfrom "API" tab in bot settings -
Set Webhook URL for receiving events
Bot is created via UI, not API. The only bot endpoint is PUT /bots/{id} (update webhook URL). API is used to send messages on behalf of bot.
Update bot webhook URL
- Update bot webhook URL:
pachca bots update <bot_id> --webhook='{"outgoing_url":"https://example.com/webhook"}'Bot
id(itsuser_id) can be found in "API" tab of bot settings
Only users with bot edit permissions can update settings.
Periodic digest/report
-
On schedule (cron/scheduler): collect data from your system
-
Compose message text with metrics or summary
-
Send message to channel:
pachca messages create --entity-id=<chat_id> --content="Дайджест за сегодня: ..."
No built-in scheduler — use cron, celery, sidekiq, etc. on your side.
Constraints and gotchas
- Rate limit: ~50 req/sec. On 429 — wait and retry.
limit: max 50- Pagination: cursor-based (limit + cursor)
Endpoints
| Method | Path | Description |
|---|---|---|
| PUT | /bots/{id} | Редактирование бота |
| POST | /messages/{id}/link_previews | Unfurl (разворачивание ссылок) |
| GET | /webhooks/events | История событий |
| DELETE | /webhooks/events/{id} | Удаление события |
Complex scenarios
For complex scenarios read files from references/: references/handle-incoming-webhook-event.md — Handle incoming webhook event references/link-unfurling.md — Link unfurling references/handle-button-click-callback.md — Handle button click (callback) references/monitoring-and-alerts.md — Monitoring and alerts references/process-events-via-history-polling.md — Process events via history (polling)
references/webhook-events.md — Webhook event types
If you don't know how to complete a task — read the corresponding file from references/ for step-by-step instructions.