# Helpteo Application Integration API

Create an **Application integration** connection inside your project. Each connection has its own API key, webhook signing secret, fields and actions. Keep the API key and private identity signing key on your backend.

Base URL: `https://api.helpteo.ru/api/v1`.
Server requests: `Authorization: Bearer YOUR_INTEGRATION_API_KEY` and `Content-Type: application/json`.
The key is scoped to its connection and does not expose private team notes.

## Customers and requests

Configure your custom fields first. The following example assumes a customer text field named `plan` and a conversation text field named `device`.

```http
PUT /integration/customers/customer_42

{"name":"Alex","email":"alex@example.com","language":"fr","data":{"plan":"Premium"}}
```

```http
PUT /integration/conversations/request_7

{"customer_id":"customer_42","name":"Connection issue","data":{"device":"iPhone"}}
```

Save the returned `conversation_id`. Stable external IDs make retries deterministic. A customer can have several requests. A request cannot be reassigned to another customer. The `data` object is a complete snapshot: preserve fields you still need when updating it.

Send a customer message from your backend:

```http
POST /integration/threads/CONVERSATION_ID/messages

{"client_id":"request_7_message_1","content":"I cannot connect","attachments":[]}
```

Reuse the same `client_id` and identical content when retrying. Operator replies arrive through signed `message.created` webhooks and thread history. Do not send an operator reply back as a new customer message.

Read history with `GET /integration/threads/CONVERSATION_ID/messages`. Exclusive `after` and `before` message-ID cursors retrieve newer or older pages; do not use both together. Continue while a page contains 200 messages. Update the customer read marker only after actual viewing with `POST /integration/threads/CONVERSATION_ID/read` and `{"message_id":123}`.

## Customer chat access

Your backend can proxy the chat while keeping server credentials private. For direct customer access, configure your Ed25519 public key and sign a short-lived EdDSA identity JWT on your server: `sub` is the external customer ID, `aud` the connection ID, and `iat`/`exp` limit its lifetime to at most 300 seconds.

```http
POST /integration/sessions

{"channel_id":"YOUR_API_CHANNEL_ID","identity_token":"SIGNED_IDENTITY_JWT","conversation_external_id":"request_7"}
```

The returned customer session is bound to that customer and conversation. It is not an Integration API key. Keep the private signing key on the server and reset customer access when they sign out.

## Context, files and actions

Project-defined fields carry customer details, subscription links, selected objects and diagnostic summaries. Use private attachments for full reports. Do not place server credentials or confidential subscription URLs in public page code.

Project actions can open a link or call your application's signed endpoint. Sensitive actions can require operator confirmation; your application must still validate the customer, object, authorization and current state before applying the action. Retry the same operation rather than performing it twice.

## Signed webhooks

Available events include `message.created`, `message.received`, `conversation.created`, `conversation.assigned`, `conversation.resolved` and `conversation.reopened`.

Verify the HMAC-SHA256 signature over the exact bytes `timestamp + "." + body` with your webhook secret. Read `X-Helpteo-Timestamp`, `X-Helpteo-Signature` (the `sha256=` prefix), `X-Helpteo-Event` and `Idempotency-Key`. Reject stale timestamps, verify the connection/customer/request scope and deduplicate by event ID. Persist an event before acknowledging it. Retain the previous secret temporarily when rotating it because queued events may use that secret.

## Automatic translation

Enable translation in the project's settings and pass the customer's language when available. Helpteo translates incoming text into the operator's preferred language. The operator previews the outgoing translation before sending; your application receives the approved customer-language text. Original operator text remains private to Helpteo.

## Confirmed message edits

Application editing is opt-in. Configure `config.message_edit_url` with an HTTPS endpoint that implements this synchronous contract. Omitting the field while saving settings preserves its current value; an empty string disables editing.

Helpteo sends a signed `message.edit_requested` event. Its stable ID is also the idempotency key. The data contains `message_id`, `previous_revision`, `revision`, `previous_content`, `content` and `content_sha256`. The outer envelope identifies `channel_id`, `customer_id`, `conversation_id` and `external_id`.

Validate scope, the previous text and revision. Update the existing message and store the immutable result in one transaction. Notify connected clients that the same message changed; do not create a replacement message or a new-message push.

After applying the edit durably, return HTTP 200:

```json
{"status":"succeeded","message_id":123,"revision":1,"content_sha256":"SHA256_HEX_OF_UTF8_CONTENT"}
```

Helpteo changes its history only after matching the acknowledgement to the message, revision and desired UTF-8 text hash. A generic 202 acknowledgement is insufficient. A retry must return the original result without undoing a newer edit. Files and internal notes are not exported as replacement customer messages.
