SKILL.md
Language Markdown4.0 KB85 lines
---name: bitrix-task-routerdescription: >-Auto-assign Bitrix24 tasks by a routing rule so nobody has to babysit the queue. Pulls open tasksvia the Bitrix REST API, decides who each one belongs to based on the task ID's parity and whetherthe title contains a keyword (default "RUSH"), shows a preview table, and writes the assignmentsback only after confirmation. Use when someone wants tasks distributed automatically between teammembers, mentions "assign tasks", "route tasks", "even/odd task assignment", "RUSH tasks", orwants to stop manually checking the Bitrix queue to hand work out. Built for Marco'seven-to-me/odd-to-Rafael rule but the routing is fully configurable.---# Bitrix Task RouterAssign Bitrix24 tasks to the right person automatically, by rule, with a human check before anything is written.## What it does1. Reads open tasks from Bitrix24 via an inbound webhook.2. Applies a routing rule to decide the responsible person for each task.3. Prints a preview of every proposed change (task → new owner, and why).4. Writes the assignments back to Bitrix **only** when run with `--commit`. Default is a dry run.Writing to the CRM is a real change to live data, so the script never writes on its own. Preview first, confirm, then commit. Once the team trusts the output, it can be wired to a scheduled task.## The routing ruleDefault rule:- Decide **parity** from the numeric task ID: even ID vs. odd ID.- If the task **title contains the keyword** (default `RUSH`, case-insensitive): even → Hazel, odd → Matt.- Otherwise (no keyword): even → Marco, odd → Rafael.**Assumptions baked in that need confirming:**- "Ending in an even/odd number" is read as the task **ID** being even/odd. If Marco means a different number (an order number in the title, a custom field), change `parity_source` in the config.- The `RUSH` keyword is matched against the task **title**. If it lives in a tag, group, or custom field instead, change `keyword_field` in the config.- A `RUSH` match **fully overrides** the default Marco/Rafael split. If instead it should be an additional filter on top, that's a different rule, so flag it.All of this is in `config.json`, so tuning the rule does not mean touching the code.## Setup1. Copy `config.example.json` to `config.json` and fill in:- `user_ids`: the Bitrix user IDs for Marco, Rafael, Hazel, Matt.- `parity_source`, `keyword`, `keyword_field`: leave as defaults unless the assumptions above are wrong.- `task_filter`: which tasks to consider (default: open and not closed).2. Copy `.env.example` to `.env` and set `BITRIX_WEBHOOK_URL` to the inbound webhook base URL (the `https://<domain>.bitrix24.com/rest/<user_id>/<token>/` one). The webhook needs **task** scope (read + write).The webhook URL carries its own auth, so treat `.env` like a password. Don't commit it.## Running itDry run (the default: shows the plan, writes nothing):```bashpython scripts/bitrix_router.py```Try the rule with no Bitrix connection, using bundled fake data:```bashpython scripts/bitrix_router.py --mock```Commit the assignments to Bitrix (after you've eyeballed the dry run):```bashpython scripts/bitrix_router.py --commit```## OutputA table, one row per task: ID, title, current owner, proposed owner, and the reason ("RUSH + even -> hazel"). In dry-run mode it ends with a count of what *would* change. With `--commit` it reports each write and any failures.## How to read failures- `BITRIX_WEBHOOK_URL not set` → `.env` missing or empty.- HTTP 401 / "Invalid token" → webhook URL wrong or revoked.- "INVALID_USER" on write → a user ID in `config.json` doesn't exist in Bitrix.- Tasks come back empty → check `task_filter`; the default only pulls open tasks.## Going automaticOnce the dry runs look right and the team trusts it, this can run on a schedule (e.g. every 30 minutes) with `--commit`. Don't schedule the commit step until the preview has been validated against live data for a few days. An unsupervised mis-route is annoying to unwind.