# SDK

{% hint style="info" %}
The functionality of this SDK will soon move to the [Touchpoint SDK](/platform/developers/conversation-sdk/touchpoint.md).
{% endhint %}

The Voice+ Core SDK ([`@nlxai/voice-plus-core`](https://github.com/nlxai/sdk/tree/main/packages/voice-plus-core)) is a lightweight JavaScript library designed to simplify the integration of Voice+ multimodal features into your web applications.

It handles authentication headers, session management, and API calls to the Voice+ Track API automatically, allowing you to focus on tracking journey steps and synchronizing state.

### Installation

Install the package via npm or yarn:

```bash
npm install @nlxai/voice-plus-core
# or
yarn add @nlxai/voice-plus-core
```

### Initialization

To start tracking a journey, import the `create` function and initialize a client. You will need the credentials found in your Voice+ journey configuration.

```javascript
import { create } from "@nlxai/voice-plus-core";

// Initialize the client
const client = create({
  apiKey: "YOUR_VOICE_PLUS_API_KEY",    // Specific Voice+ Key (x-api-key)
  workspaceId: "YOUR_WORKSPACE_ID",     // Your Workspace ID (x-nlx-id)
  scriptId: "YOUR_SCRIPT_ID",           // The UUID of the journey/script
  conversationId: "XXXXXXXXX",          // Conversation ID for the active voice session
  languageCode: "en-US"                 // Language code (e.g., en-US)
});
```

{% hint style="info" %}
The `conversationId` is typically passed to your web application via a URL parameter (e.g., sent via SMS during the call) or through a push notification.
{% endhint %}

### Tracking steps

Use the `sendStep` method to notify the Voice+ application that a user has reached a specific point in the journey or performed an action.

**Basic usage**

```javascript
// distinct step UUID defined in your Voice+ script
const STEP_ID = "550e8400-e29b-41d4-a716-446655440000";

try {
  await client.sendStep(STEP_ID);
  console.log("Step tracked successfully");
} catch (error) {
  console.error("Failed to track step", error);
}
```

**Sending context**

You can pass an optional context object to send data back to the voice bot (e.g., form selections, user choices).

```javascript
const context = {
  selectedSeat: "4A",
  mealPreference: "vegetarian"
};

await client.sendStep(STEP_ID, context);
```

**With trigger description**

You can also provide a description of what triggered the step for analytics debugging.

```javascript
await client.sendStep({
  stepId: STEP_ID,
  stepTriggerDescription: "User clicked the 'Confirm Seat' button"
});
```

### API Reference

#### **`create(config)`**

Creates a new Voice+ client instance.

| Parameter               | Type   | Description                                      |
| ----------------------- | ------ | ------------------------------------------------ |
| `config.apiKey`         | String | **Required.** The Voice+ API Key.                |
| `config.workspaceId`    | String | **Required.** The NLX Workspace ID.              |
| `config.scriptId`       | UUID   | **Required.** The Journey/Script ID.             |
| `config.conversationId` | String | **Required.** The active session ID.             |
| `config.languageCode`   | String | **Required.** IETF language tag (e.g., `en-US`). |

#### `client.sendStep(stepId, [context])`

| Parameter | Type   | Description                                   |
| --------- | ------ | --------------------------------------------- |
| `stepId`  | UUID   | **Required.** The ID of the step to track.    |
| `context` | Object | (Optional) JSON object containing state data. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nlx.ai/platform/developers/voice+-api/track/sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
