Integrate chatbots
Working principle
Section titled “Working principle”Use webhooks to connect a GPTunneL bot, such as a support bot, to an external chat service. Requests use HTTP POST with the integration token in the Authorization header and a JSON body.

When a user sends a message, the chat service posts CLIENT_MESSAGE to the bot’s webhook. The bot processes it and sends BOT_MESSAGE to the chat service’s webhook.
If the bot needs to hand the conversation to a human agent, it sends INVITE_AGENT.
Authorisation and errors
Section titled “Authorisation and errors”For all three methods, send the integration token in the Authorization header without the Bearer prefix. For the examples below, save that token in the GPTUNNEL_BOT_TOKEN environment variable.
| HTTP status | When it occurs |
|---|---|
| 401 | The token is missing, invalid, revoked or does not identify an active bot and its owner unambiguously. Deleting the bot or its owner’s account also ends access. |
| 403 | For /api/bot/balance, the bot owner lacks active membership in the linked organization or the organization has been deleted. |
| 400 | The JSON could not be parsed or the /api/bot event has an invalid format. CLIENT_MESSAGE requires a nonempty string chat_id and a message object. |
| 413 | The body of an authorized request exceeds the permissible size. |
On 401, /api/bot/config and /api/bot/balance return the following body.
{ "ok": false, "message": "Authorization required!" }The 401 response from /api/bot has an empty body. On 403, /api/bot/balance returns { "ok": false, "message": "Access denied!" } without a balance.
Check the HTTP status before parsing a successful response. If your HTTP client throws on 4xx, inspect the status and body in the error handler. Authorization failures use their HTTP status. An authorized /api/bot/config request with an invalid webHookUrl still returns 200 with ok: false and an explanation in message.
Address for events
Section titled “Address for events”https://gptunnel.ru/api/botcurl -X POST https://gptunnel.ru/api/bot \ -H "Authorization: ${GPTUNNEL_BOT_TOKEN:?Set GPTUNNEL_BOT_TOKEN}" \ -H 'Content-Type: application/json' \ -d '{ "event": "CLIENT_MESSAGE", "id": "9f7b373e-fce1-11ee-9da4-a912f79ee445", "chat_id": "4976", "client_id": "30005", "message": { "type": "TEXT", "text": "Добрый день", "timestamp": 1713375646 }, "agents_online": false }'When the event is accepted, the API returns 200 with an empty body. The bot processes the event and sends BOT_MESSAGE or INVITE_AGENT to the chat service’s webhook.
Main events
Section titled “Main events”{ "event": "CLIENT_MESSAGE", "id": "9f7b373e-fce1-11ee-9da4-a912f79ee445", "chat_id": "4976", "client_id": "30005", "message": { "type": "TEXT", "text": "Добрый день", "timestamp": 1713375646 }, "agents_online": false}{ "event": "BOT_MESSAGE", "id": "6620ce58bb349500015fa366", "chat_id": "4976", "client_id": "30005", "client_event_id": "9f7b373e-fce1-11ee-9da4-a912f79ee445", "message": { "type": "MARKDOWN", "content": "Здравствуйте! Чем могу помочь?", "text": "Здравствуйте! Чем могу помочь?", "timestamp": 1713375648 }}{ "event": "INVITE_AGENT", "id": "6620ce58bb349500015fa367", "chat_id": "4976", "client_id": "30005", "client_event_id": "9f7b373e-fce1-11ee-9da4-a912f79ee445"}Additional events
Section titled “Additional events”A human agent has taken over the conversation.
{ "event": "AGENT_JOINED", "id": "9f7b373e-fce1-11ee-9da4-a912f79ee445", "chat_id": "4976", "client_id": "30005"}No human agent is available after INVITE_AGENT.
{ "event": "AGENT_UNAVAILABLE", "id": "9f7b373e-fce1-11ee-9da4-a912f79ee445", "chat_id": "4976", "client_id": "30005"}The client has closed the conversation.
{ "event": "CHAT_CLOSED", "id": "9f7b373e-fce1-11ee-9da4-a912f79ee445", "chat_id": "4976", "client_id": "30005"}Get Balance
Section titled “Get Balance”https://gptunnel.ru/api/bot/balancecurl -X POST https://gptunnel.ru/api/bot/balance \ -H "Authorization: ${GPTUNNEL_BOT_TOKEN:?Set GPTUNNEL_BOT_TOKEN}" \ -H 'Content-Type: application/json'{ "ok": true, "message": "OK", "balance": "354.91"}For an organization bot, the response contains the linked organization’s balance and includes balanceHidden and canSpend.
{ "ok": true, "message": "OK", "balance": "0", "balanceHidden": true, "canSpend": true}If the bot owner lacks permission to view the balance, balanceHidden is true and balance is the string "0". canSpend indicates whether the balance plus the credit limit is positive, even if the balance is hidden. Other restrictions still apply when processing a message. If the bot owner lacks access to the linked organization, the API returns 403 and does not fall back to the personal balance.
Configure a webhook through the API
Section titled “Configure a webhook through the API”https://gptunnel.ru/api/bot/configcurl -X POST https://gptunnel.ru/api/bot/config \ -H "Authorization: ${GPTUNNEL_BOT_TOKEN:?Set GPTUNNEL_BOT_TOKEN}" \ -H 'Content-Type: application/json' \ -d '{"webHookUrl": "https://bot.example.com/webhook"}'{ "ok": true, "message": "OK"}For integration questions, contact t.me/gptunnel_ru or @ScriptHeads on Telegram.