imbot.v2.Chat.get
Получить информацию о чате
Описание
Метод imbot.v2.Chat.get возвращает информацию о чате. Бот должен быть участником чата.
Параметры
botId
integer
обязательный
ID бота
botToken
string
необязательный
Уникальный токен авторизации бота. Обязателен при авторизации через вебхук, не нужен для OAuth.
Передавайте тот же botToken, который был указан при регистрации чат-бота
dialogId
string
обязательный
ID диалога. Для групповых чатов — chat{chatId}, для личных — {userId}
Примеры запроса
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"botId":456,"botToken":"my_bot_token","dialogId":"chat5"}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/imbot.v2.Chat.get
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"botId":456,"dialogId":"chat5","auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/imbot.v2.Chat.get
try {
const response = await $b24.callMethod('imbot.v2.Chat.get', {
botId: 456,
dialogId: 'chat5',
});
const { result } = response.getData();
console.log('result:', result);
} catch (error) {
console.error('Error:', error);
}
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
try:
bitrix_response = client.imbot.v2.chat.get(
bot_id=456,
dialog_id="chat5",
).response
result = bitrix_response.result
print(result)
except BitrixAPIError as error:
print(
"Ошибка Bitrix API",
f"error: {error.error}",
f"error_description: {error.error_description}",
sep="\n",
)
except BitrixSDKException as error:
print(f"Ошибка Bitrix SDK: {error.message}")
except Exception as error:
print(f"Непредвиденная ошибка: {error}")
try {
$response = $b24Service
->core
->call(
'imbot.v2.Chat.get',
[
'botId' => 456,
'dialogId' => 'chat5',
]
);
$result = $response
->getResponseData()
->getResult();
echo 'result: '. print_r($result, true);
} catch (Throwable $exception) {
error_log($exception->getMessage());
echo 'Error: '. $exception->getMessage();
}
BX24.callMethod(
'imbot.v2.Chat.get',
{
botId: 456,
dialogId: 'chat5',
},
function(result) {
if (result.error()) {
console.error(result.error().ex);
} else {
console.log(result.data());
}
}
);
require_once('crest.php');
$result = CRest::call(
'imbot.v2.Chat.get',
[
'botId' => 456,
'dialogId' => 'chat5',
]
);
if (!empty($result['error'])) {
echo 'Error: '. $result['error_description'];
} else {
echo 'Chat name: '. $result['result']['chat']['name'];
}
// client и ctx уже созданы — см. раздел «SDK для Go»
res, err := client.Core().Call(ctx, "imbot.v2.Chat.get", b24.Params{
"botId": 456,
"botToken": "my_bot_token",
"dialogId": "chat5",
}, b24.WithIdempotent())
if err != nil {
return fmt.Errorf("imbot.v2.Chat.get: %w", err)
}
// Метод заворачивает ответ в объект с ключом "chat".
raw, ok := b24.Unwrap(res.Result, "chat")
if !ok {
return fmt.Errorf("в ответе нет ключа chat")
}
var item struct {
ID b24.ID `json:"id"`
DialogID string `json:"dialogId"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
MessageType string `json:"messageType"`
}
if err := json.Unmarshal(raw, &item); err != nil {
return fmt.Errorf("разбор ответа: %w", err)
}
fmt.Println(item.ID, item.DialogID)
Ответ
HTTP-статус: 200
{
"result": {
"chat": {
"id": 5,
"dialogId": "chat5",
"name": "Support Chat",
"description": "",
"type": "chat",
"messageType": "C",
"owner": 456,
"color": "#4ba984",
"avatar": "",
"extranet": false,
"containsCollaber": false,
"entityType": "",
"entityId": "",
"entityData1": "",
"entityData2": "",
"entityData3": "",
"entityLink": {},
"diskFolderId": 42,
"role": "owner",
"permissions": {},
"muteList": [],
"parentChatId": null,
"parentMessageId": null,
"isNew": false,
"textFieldEnabled": "Y",
"backgroundId": null,
"dateCreate": "2025-01-15T10:00:00+03:00",
"lastMessageId": 789,
"lastMessageViews": "{}",
"lastId": 789,
"managerList": [],
"markedId": null,
"messageCount": 15,
"public": "",
"unreadId": null,
"userCounter": 3
}
},
"time": {
"start": 1728626400.123,
"finish": 1728626400.234,
"duration": 0.111,
"processing": 0.045,
"date_start": "2024-10-11T10:00:00+03:00",
"date_finish": "2024-10-11T10:00:00+03:00"
}
}
Обработка ошибок
HTTP-статус: 400
{
"error": "ACCESS_DENIED",
"error_description": "Access denied"
}
| Код | Описание | Значение |
|---|---|---|
BOT_TOKEN_NOT_SPECIFIED |
Bot token is not specified | Не указан botToken. Обязателен при авторизации через вебхук |
BOT_ID_REQUIRED |
Bot ID is required | Не указан botId |
BOT_NOT_FOUND |
Bot not found | Бот не найден |
BOT_OWNERSHIP_ERROR |
Bot is registered by another application | Бот зарегистрирован другим приложением |
ACCESS_DENIED |
Access denied | Бот не является участником чата |

