Skip to content

Quick Start

This guide walks you through creating an AI agent (bot), configuring its behaviour, and connecting it to a Telegram chat — all via the Worken REST API. The same flow works for any supported channel.

Prerequisites

1. Install the SDK (optional)

You can call the REST API directly with curl, or use the official TypeScript SDK:

sh
npm install worken
# or
bun add worken
typescript
import { WorkenClient } from 'worken'

const worken = new WorkenClient({ apiKey: process.env.WORKEN_API_KEY })

2. Create a bot

A bot (also called a virt) is the AI agent that will handle conversations.

sh
curl https://api.worken.ru/bots \
  -X POST \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{"name": "Support Bot"}'
typescript
const bot = await worken.bots.create({ name: 'Support Bot' })
console.log(bot.id) // bot_01j...
python
bot = client.bots.create(name="Support Bot")
print(bot.id)  # bot_01j...

The response:

typescript
type Bot = {
  id: string
  name: string
  status: 'active' | 'disabled' | 'error'
  project_id: string
  created_at: string
}

3. Configure the agent

Set the system instruction, AI model, and parameters using the settings endpoint:

sh
curl https://api.worken.ru/bots/${BOT_ID}/settings \
  -X POST \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "ai": {
      "instruction": "You are a friendly support agent for Acme Inc. Answer concisely and always offer to escalate if you are unsure.",
      "model": {
        "id": "openai/gpt-4o-mini",
        "temperature": 0.4,
        "max_tokens": 1024
      },
      "memory": {
        "lastMessages": 20,
        "semanticRecall": true,
        "workingMemory": { "enabled": true },
        "generateTitle": true
      }
    }
  }'
typescript
await worken.bots.settings.update(bot.id, {
  ai: {
    instruction:
      'You are a friendly support agent for Acme Inc. Answer concisely and always offer to escalate if you are unsure.',
    model: {
      id: 'openai/gpt-4o-mini',
      temperature: 0.4,
      max_tokens: 1024,
    },
    memory: {
      lastMessages: 20,
      semanticRecall: true,
      workingMemory: { enabled: true },
      generateTitle: true,
    },
  },
})

Available models

Model IDNotes
openai/gpt-4oHighest quality
openai/gpt-4o-miniFastest, lowest cost
anthropic/claude-3-5-sonnetExcellent reasoning
google/gemini-2.0-flashBest for long context
yandex/yandexgpt-proRussian-language optimised

4. Create an integration

An integration is a connection to an external platform (Telegram, WhatsApp, amoCRM, etc.) that delivers messages to your bot.

Connect Telegram

sh
curl https://api.worken.ru/integrations \
  -X POST \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Telegram Bot",
    "vendor": "telegram",
    "auth_data": {
      "token": "7123456789:AAHxxxxxxx"
    }
  }'
typescript
const integration = await worken.integrations.create({
  name: 'My Telegram Bot',
  vendor: 'telegram',
  auth_data: { token: process.env.TELEGRAM_BOT_TOKEN },
})

The response includes an id you will use in the next step.

5. Create a chat and connect it to the bot

A chat represents a specific channel within an integration (e.g. a Telegram group or direct-message inbox) associated with your bot.

sh
curl https://api.worken.ru/integrations/${INTEGRATION_ID}/chats \
  -X POST \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "bot_id": "bot_01j...",
    "name": "Customer Support"
  }'
typescript
const chat = await worken.integrations.chats.create(integration.id, {
  bot_id: bot.id,
  name: 'Customer Support',
})

6. Activate the chat

sh
curl https://api.worken.ru/integrations/${INTEGRATION_ID}/chats/${CHAT_ID}/status \
  -X POST \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{"status": "active"}'
typescript
await worken.integrations.chats.setStatus(integration.id, chat.id, 'active')

Your bot is now live. Any message sent to the Telegram bot will be processed by the AI agent and answered automatically.

7. Monitor conversations

List active threads (conversations) for the chat:

sh
curl "https://api.worken.ru/threads?chat_id=${CHAT_ID}&limit=20" \
  -H "Authorization: Bearer sk-..."
typescript
const threads = await worken.threads.list({ chat_id: chat.id, limit: 20 })
for (const thread of threads.data) {
  console.log(thread.id, thread.mode, thread.last_message_at)
}

Subscribe to real-time thread events via SSE:

typescript
const stream = worken.threads.events()
for await (const event of stream) {
  // event.type: 'thread.updated' | 'message.created' | ...
  console.log(event.thread_id, event.pending_count)
}

8. Send a message as an operator

When a thread is in manual mode, operators can send messages directly:

typescript
await worken.threads.send(thread.id, {
  text: 'Let me transfer you to a specialist who can help.',
})

Complete example

typescript
import { WorkenClient } from 'worken'

const worken = new WorkenClient({ apiKey: process.env.WORKEN_API_KEY })

async function setup() {
  const bot = await worken.bots.create({ name: 'Support Bot' })

  await worken.bots.settings.update(bot.id, {
    ai: {
      instruction: 'You are a helpful support agent.',
      model: { id: 'openai/gpt-4o-mini', temperature: 0.3 },
    },
  })

  const integration = await worken.integrations.create({
    name: 'Telegram Support',
    vendor: 'telegram',
    auth_data: { token: process.env.TELEGRAM_BOT_TOKEN },
  })

  const chat = await worken.integrations.chats.create(integration.id, {
    bot_id: bot.id,
    name: 'Customer Support',
  })

  await worken.integrations.chats.setStatus(integration.id, chat.id, 'active')

  console.log('Bot is live! Chat ID:', chat.id)
}

setup()

Next steps

Руководство пользователя Worken AI