> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vzaps.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeBot

> Configure TypeBot and manage sessions with the PHP SDK

Use `$vzaps->typeBots()` to connect TypeBot flows to a VZaps instance.

Common fields on all calls:

| Field           | Type     | Required | Description     |
| --------------- | -------- | -------- | --------------- |
| `instanceId`    | `string` | Yes      | Instance ID.    |
| `instanceToken` | `string` | Yes      | Instance token. |

## `typeBots()->list($instanceId, $instanceToken = null)`

Lists TypeBots configured on the instance.

```php theme={null}
$typebots = $vzaps->typeBots()->list('VZ...', 'instance-token');

print_r($typebots);
```

**Return:** array of TypeBot configs for the instance (IDs, triggers, priority, etc.).

## `typeBots()->create($request)`

Creates a TypeBot configuration.

```php theme={null}
$created = $vzaps->typeBots()->create([
    'instanceId' => 'VZ...',
    'instanceToken' => 'instance-token',
    'enabled' => true,
    'description' => 'Welcome',
    'typebotUrl' => 'https://typebot.io',
    'publicId' => 'my-public-flow',
    'triggerType' => 'keyword',
    'triggerValue' => 'hello',
    'priority' => 10,
    'expireInMinutes' => 30,
    'keywordFinish' => 'stop',
    'defaultDelayMs' => 800,
    'unknownMessage' => 'Sorry, I did not understand. Can you rephrase?',
    'transcribeAudio' => true,
    'listenFromMe' => false,
    'stopBotFromMe' => true,
    'keepOpen' => false,
    'debounceMs' => 1500,
    'ignoreGroups' => false,
]);

print_r($created);
```

**Return:** created config, including `typebot_id` for later updates.

Main payload fields:

| Field             | Type      | Required    | Description                                                                  |
| ----------------- | --------- | ----------- | ---------------------------------------------------------------------------- |
| `enabled`         | `boolean` | Yes         | Enables or disables the TypeBot during trigger evaluation.                   |
| `description`     | `string`  | Yes         | Display name for identification.                                             |
| `typebotUrl`      | `string`  | Yes         | TypeBot base URL.                                                            |
| `publicId`        | `string`  | Yes         | Public flow identifier.                                                      |
| `triggerType`     | `string`  | Yes         | `all`, `keyword`, `contains`, `starts_with`, `regex`, `advanced`, or `none`. |
| `triggerValue`    | `string`  | Conditional | Trigger text or regex.                                                       |
| `triggerOperator` | `string`  | Conditional | Used when `triggerType` is `advanced`.                                       |
| `priority`        | `number`  | Yes         | Evaluation order. Higher value first.                                        |
| `expireInMinutes` | `number`  | Yes         | Expires session after inactivity. `0` means no expiration.                   |

## `typeBots()->update($request)`

Updates an existing TypeBot. Provide `typebotId` returned by create or list.

```php theme={null}
$vzaps->typeBots()->update([
    'instanceId' => 'VZ...',
    'instanceToken' => 'instance-token',
    'typebotId' => '550e8400-e29b-41d4-a716-446655440000',
    'enabled' => true,
    'description' => 'Updated welcome',
    'triggerType' => 'contains',
    'triggerValue' => 'help',
    'priority' => 20,
    'expireInMinutes' => 60,
]);
```

**Return:** updated config or `{ status: "ok" }`.

## `typeBots()->delete($request)`

Removes the configuration and associated sessions.

```php theme={null}
$vzaps->typeBots()->delete([
    'instanceId' => 'VZ...',
    'instanceToken' => 'instance-token',
    'typebotId' => '550e8400-e29b-41d4-a716-446655440000',
]);
```

**Return:** deletion confirmation (`{ status: "ok" }` or equivalent message).

## `typeBots()->startSession($request)`

Starts a session manually with a contact.

By `publicId`:

```php theme={null}
$vzaps->typeBots()->startSession([
    'instanceId' => 'VZ...',
    'instanceToken' => 'instance-token',
    'publicId' => 'support',
    'phone' => '5511999999999',
    'pushName' => 'Customer',
    'message' => 'I need support',
]);
```

**Return:** started session (session UUID, contact, `opened` status).

By `typebotId`:

```php theme={null}
$vzaps->typeBots()->startSession([
    'instanceId' => 'VZ...',
    'instanceToken' => 'instance-token',
    'typebotId' => '550e8400-e29b-41d4-a716-446655440000',
    'phone' => '5511999999999',
    'message' => 'I need support',
]);
```

| Field       | Type     | Required    | Description                                            |
| ----------- | -------- | ----------- | ------------------------------------------------------ |
| `publicId`  | `string` | Conditional | Public flow identifier. Use `publicId` or `typebotId`. |
| `typebotId` | `string` | Conditional | Internal TypeBot ID.                                   |
| `phone`     | `string` | Yes         | Contact phone.                                         |
| `message`   | `string` | Yes         | Initial message sent to the flow.                      |
| `pushName`  | `string` | No          | Contact display name.                                  |

## `typeBots()->listSessions($instanceId, $instanceToken = null)`

Lists active and closed sessions.

```php theme={null}
$sessions = $vzaps->typeBots()->listSessions('VZ...', 'instance-token');

print_r($sessions);
```

**Return:** session list (`opened`, `paused`, `closed`) per contact/flow.

## `typeBots()->pauseSession($request)`

Pauses an open session. Use the session UUID in `session`.

```php theme={null}
$vzaps->typeBots()->pauseSession([
    'instanceId' => 'VZ...',
    'instanceToken' => 'instance-token',
    'session' => '550e8400-e29b-41d4-a716-446655440001',
]);
```

**Return:** session with `paused` status.

## `typeBots()->closeSession($request)`

Closes a session manually.

By session UUID:

```php theme={null}
$vzaps->typeBots()->closeSession([
    'instanceId' => 'VZ...',
    'instanceToken' => 'instance-token',
    'session' => '550e8400-e29b-41d4-a716-446655440001',
]);
```

**Return:** closed session or confirmation by phone number.

By contact phone (closes all active sessions for that number):

```php theme={null}
$vzaps->typeBots()->closeSession([
    'instanceId' => 'VZ...',
    'instanceToken' => 'instance-token',
    'session' => '5511999999999',
]);
```
