Перейти к содержимому

Справочник API портала

6 операций, на которых держится экран поддержки в вашем приложении. Справочник сгенерирован из самого API, а зачем всё это нужно, рассказывает руководство.

Как читать пути

Все пути ниже указаны относительно https://api.helpwing.ru/portal и принимают одни и те же один-два id, поэтому под каждой операцией они не повторяются: {public_key} — публичный ключ вашего проекта, pk_…, а {ticket_id} — диалог, на который указывает путь.

Первую операцию вызывают с вашего сервера, и ей нужен секрет подтверждения личности проекта. Все остальные вызываются из браузера с токеном, полученным в X-Helpwing-Session, и видят только диалоги клиента, для которого этот токен выпущен.

Signing a user in — from your server

Exchange a signed claim for a browser session

POST/{public_key}/sessions/

Called from your server, never from the browser. It is the one portal endpoint that takes a signature, and the signature needs the project's identity secret - the same one the chat widget's userHash is keyed with, found in the dashboard under the widget's Identity settings.

user_hash = hex(hmac_sha256(key=identity_secret, message=external_id))

Hand the returned token to the page you are rendering and send it back in X-Helpwing-Session on every other call here. It reaches exactly one customer's conversations, and it expires - when it does, ask your server for another, because your server is the only party that knows whether that person is still signed in.

There is no unverified mode. The widget can afford one, because a visitor who proves nothing still gets a conversation of their own; here an unproved claim would be a request to read a stranger's support history, so an unsigned or wrongly signed claim is refused outright.

The customer is matched on external_id. A first-time caller whose email matches a customer who has never been identified takes over that record - which is the point: the conversations they had by email before they ever signed in are the history the portal exists to show them. A record already carrying a different external_id is left alone.

Тело запроса

external_idstringобязательный
The id your application knows this person by. The customer is matched on it, and it is the value the signature covers.
user_hashstringобязательный
hex HMAC-SHA256 of `external_id`, keyed with the project identity secret.
emailstring (email)
Their address. Used the first time only, to take over the record they already had from before they ever signed in - the conversations the portal exists to show them.
namestring
Display name. Fills a blank on the record; it never overwrites what an agent corrected.
metadataobject
Free-form JSON merged into the customer's record: plan, account id, seat count. Signed by your server, so unlike a conversation's own metadata it is a fact rather than a claim.

Ответы

Conversations — from the browser

List the customer's conversations

GET/{public_key}/conversations/

Every conversation belonging to the customer this session was minted for, newest activity first - email, chat and portal alike. A support history is one list, and which door a question came in by is the customer's least interesting fact about it.

Paginated like every other list in the API. Spam is left out: a conversation an agent has marked as spam is one nobody is going to answer, and listing it promises a reply that is not coming.

Параметры запроса

pageinteger
Which page to return. Defaults to 1.
page_sizeinteger
Conversations per page, up to 200. Defaults to 25.

Ответы

Open a conversation from the portal

POST/{public_key}/conversations/

Files a new ticket for the customer this session belongs to, on the project's default inbox, with the project's default assignee and priority - the same routing an inbound email gets. The ticket.created and message.created webhooks fire.

The conversation's source is portal, which is what tells the agent answering it that the customer is reading their replies in the project's own application and not in a mailbox.

metadata is free-form JSON kept on the ticket and shown beside it - what the form asked, the page they were on, the order they were looking at. It comes from the browser, so treat it as a claim: anything that has to be true belongs in the session exchange's metadata instead, which your server signs and which lands on the customer's record.

Тело запроса — JSON или multipart, чтобы приложить файлы

subjectstringобязательный
What the conversation is called, as the customer typed it. Required.
body_textstring
Their first message. Required unless the conversation opens with a file.
filesstring (binary)[]
Files to attach, as multipart. The widget's per-message caps apply here too.
metadataobject
Free-form JSON stored on the ticket and shown to the agent beside it - the form's own fields, the page the customer was on, an order number. At most 4096 bytes, and sent by the browser, so it is a claim rather than a fact.

Ответы

Read a conversation

GET/{public_key}/conversations/{ticket_id}/

The transcript the customer is allowed to see - their own messages, agent replies and system entries, never internal notes - plus a cursor to follow it with.

Ответы

Reply in a conversation

POST/{public_key}/conversations/{ticket_id}/messages/

Appends a message, exactly as an inbound email on the same ticket would: the inbox ordering, preview and counters follow it, a resolved conversation reopens when the project enables reopen_on_customer_reply, the timeline records customer_replied, the message.created webhook fires and the assignee is notified.

Unlike the chat widget, reading a conversation here does not suppress the emailed copy of the agent's reply. A chat panel is open or it is not; a portal is a page somebody may have left open in a tab since Tuesday, and a customer who never comes back to it should still hear the answer.

Send a client_message_id if you retry. Repeating one returns the message it already stored instead of storing a second.

Тело запроса — JSON или multipart, чтобы приложить файлы

body_textstring
What they wrote. Required unless the message carries a file.
filesstring (binary)[]
Files to attach, as multipart. The widget's per-message caps apply here too.
client_message_idstring
An id the sender makes up for this message, e.g. a UUID. Sending it again returns the message it already stored instead of storing a second one.

Ответы

Poll a conversation for replies

GET/{public_key}/conversations/{ticket_id}/updates/

The customer's half of the live update feed, over the same cursor the chat widget and the agent inbox use. Send the cursor from the previous response as since; with wait the request is held open until an agent replies or the wait expires.

Long polling rather than server-sent events, for the reason the widget documents: EventSource cannot set a request header, so a stream would have to carry the session token in the query string.

Параметры запроса

sincestring
Cursor from the previous response.
waitinteger
Seconds to hold the request open waiting for a reply. 0 (default) returns at once.

Ответы

Объекты

Что возвращает API. Каждый объект описан один раз, а не под каждым эндпоинтом, который его отдаёт. Все поля здесь только для чтения: это ответы, а что принимает запрос, указано у самой операции.

PortalConversation

One conversation as a row in the customer's own list.

idstring (uuid)только чтение
Use it in the paths below. Only this customer's conversations resolve.
referencestringтолько чтение
The conversation's public identifier. Opaque, and the only one a customer ever sees.
subjectstringтолько чтение
What the conversation is called.
statusstringтолько чтение
`open`, `pending`, `resolved` or `closed`. * `open` - Open * `pending` - Pending * `resolved` - Resolved * `closed` - ClosedОдно изopen, pending, resolved, closed
sourcestringтолько чтение
Which door it came in by: `email`, `chat`, `portal` or `api`. * `email` - Email * `chat` - Chat * `api` - API * `portal` - PortalОдно изemail, chat, api, portal
last_message_atstring (date-time)только чтение
When anybody last wrote in it. What the list is ordered by.
last_message_previewstringтолько чтение
The opening of the most recent message, for the list row.
message_countintegerтолько чтение
How many messages it holds, internal notes excluded.
created_atstring (date-time)только чтение
When it was opened.

PortalCustomer

The person the session belongs to, as they are allowed to see themselves.

idstring (uuid)только чтение
Helpwing's own id for this customer.
external_idstringтолько чтение
The id you signed in the claim, echoed back.
emailstring (email)только чтение
The address their conversations are had at, when there is one.
namestringтолько чтение
Their display name, as an agent sees it.
avatar_urlstring (uri)только чтение
Their avatar, when the project has one for them.

PortalTranscript

One conversation and everything in it the customer may read.

conversationPortalConversationтолько чтение
The conversation itself.
messagesPublicMessage[]только чтение
Oldest first. Only what the customer may read - their own messages, agent replies and system entries. Internal notes are never here. Just the new message when one was posted.
typingobject| nullтолько чтение
`{name}` of the agent typing a reply, or null.
cursorstringтолько чтение
Pass back as `?since=` to the updates endpoint.

PortalUpdates

What happened on the conversation since the cursor you sent.

cursorstringтолько чтение
Send this back as the next `?since=`.
has_changesbooleanтолько чтение
Whether anything happened. False is what a `wait` that timed out returns.
statusstringтолько чтение
The conversation's status right now.
messagesPublicMessage[]только чтение
Messages written after the cursor you sent, oldest first.
typingobject| nullтолько чтение
`{name}` of the agent typing a reply, or null.

PublicMessage

One message as the visitor sees it: who wrote it, what it says, what is attached.

idstring (uuid)только чтение
The message's own id, stable across every read of the conversation.
authorstringтолько чтение
`agent`, `customer` or `system`.
author_namestringтолько чтение
Who wrote it, as a name. An agent's display name, never their email address.
author_avatar_urlstringтолько чтение
Their avatar, when there is one.
body_textstringтолько чтение
What was written, as markdown. Render it the way the dashboard does.
body_htmlstringтолько чтение
The same message as HTML, when the channel it arrived by carried one.
attachmentsobject[]только чтение
Files on the message: `id`, `filename`, `content_type`, `size_bytes`, `is_inline`, `content_id` and a `url` that expires. An `is_inline` file is a picture written into `body_text` as `![name](cid:<content_id>)`; show it there and leave it out of the file list.
created_atstring (date-time)только чтение
When it was written. The transcript is ordered by it.
client_message_idstringтолько чтение
The id the sender made up for this message, echoed back. Only ever set on a message this customer sent, and only when they sent one - which is what lets a client that drew the message before sending it recognise its own copy.
is_assistantbooleanтолько чтение
Written by the AI assistant. `author` is still `agent`, so older clients show it as one.

Session

A minted session. The token is returned here and never again.

tokenstringтолько чтение
Send it back in `X-Helpwing-Session` on every portal call. Store it in memory, not on disk.
expires_atstring (date-time)только чтение
When the token stops working.
expires_inintegerтолько чтение
Seconds until the token stops working.
customerPortalCustomerтолько чтение
Who the session was minted for.
ДальшеREST API →Создавайте тикеты и отвечайте на них со своего бэкенда по API-ключу проекта и узнавайте об изменениях.