---
title: "AI assistant — analyse a deal, create a follow-up task"
description: "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."
canonical_url: "https://bitrix24.github.io/b24jssdk/docs/examples/ai-assistant"
last_updated: "2026-06-02"
---
# 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

```bash
pnpm add openai
```

## Environment

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

## Run

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

## Source

[`skills/b24jssdk-recipes/examples/08-ai-assistant.ts`](https://github.com/bitrix24/b24jssdk/blob/main/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.

## Sitemap

See the full [sitemap](/b24jssdk/sitemap.md) for all pages.
