v1.2.0

AI assistant — analyse a deal, create a follow-up task

Load a deal and its activities, ask GPT-4o for the next-best action, create a task bound to the deal with priority and deadline.

What it does

Given a deal id on the command line, it fetches the deal (crm.item.get via actions.v2.call.make) and its activity timeline (crm.activity.list via actions.v2.callList.make). Sends a structured prompt to GPT-4o, asks for a JSON recommendation, and creates a task (tasks.task.add via actions.v3.call.make) bound to the deal via UF_CRM_TASK.

Stack

Node.js 18+, openai.

Install

pnpm add openai

Environment

export B24_HOOK='https://your.bitrix24.com/rest/1/secret'
export OPENAI_API_KEY='sk-...'

Run

npx tsx 08-ai-assistant.ts <DEAL_ID>

Source

skills/b24jssdk-recipes/examples/08-ai-assistant.ts.

Notes

  • The deal lookup uses v3 (camelCase) fields; the activity list uses classic uppercase fields (OWNER_TYPE_ID, OWNER_ID, CREATED).
  • Switching to OpenAI tool-calling (tools parameter, function-calling loop) is the modern shape — see the suggested-examples list.
  • The prompt asks for a strict JSON response and uses response_format: { type: 'json_object' } to enforce it.
  • Priority mapping: high → 2, medium → 1, low → 0 matches Bitrix24's task priority enum.