Skip to content

Integrate chatbots

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.

Integration scheme

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.

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.

POSThttps://gptunnel.ru/api/bot
Окно терминала
curl -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.

{
"event": "CLIENT_MESSAGE",
"id": "9f7b373e-fce1-11ee-9da4-a912f79ee445",
"chat_id": "4976",
"client_id": "30005",
"message": {
"type": "TEXT",
"text": "Добрый день",
"timestamp": 1713375646
},
"agents_online": false
}

A human agent has taken over the conversation.

{
"event": "AGENT_JOINED",
"id": "9f7b373e-fce1-11ee-9da4-a912f79ee445",
"chat_id": "4976",
"client_id": "30005"
}
POSThttps://gptunnel.ru/api/bot/balance
Окно терминала
curl -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.

POSThttps://gptunnel.ru/api/bot/config
Окно терминала
curl -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.