Описание
Используйте этот метод, чтобы вновь открыть закрытую 'Общую' тему в супергрупповом чате форума. Бот должен быть администратором в чате для работы этого метода и иметь права администратора can_manage_topics. Тема будет автоматически отображена, если она была скрыта. Возвращает True при успешном выполнении.
| Параметр | Тип | Обязательный | Описание |
|---|---|---|---|
| chat_id | Целое число или Строка | Да | Уникальный идентификатор целевого чата или имя пользователя целевой супергруппы (в формате @supergroupusername) |
Примеры
php
<?php
$botToken = 'YOUR_BOT_TOKEN';
$chatId = 'YOUR_CHAT_ID'; // Can be integer ID or username like @supergroupname
$apiUrl = "https://api.telegram.org/bot{$botToken}/reopenGeneralForumTopic";
$data = [
'chat_id' => $chatId,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: multipart/form-data',
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$result = json_decode($response, true);
if ($result['ok'] === true) {
echo "General forum topic reopened successfully!\n";
} else {
echo "Error: " . $result['description'] . "\n";
}
} else {
echo "HTTP Error: " . $httpCode . "\n";
}
// Alternative using file_get_contents with stream context
/*
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data',
'content' => http_build_query($data),
],
];
$context = stream_context_create($options);
$response = file_get_contents($apiUrl, false, $context);
$result = json_decode($response, true);
if ($result['ok'] === true) {
echo "General forum topic reopened successfully!\n";
} else {
echo "Error: " . $result['description'] . "\n";
}
*/
python
import requests
def reopen_general_forum_topic(bot_token, chat_id):
"""
Reopens a closed 'General' topic in a forum supergroup chat.
Args:
bot_token (str): Telegram Bot API token
chat_id (int or str): Unique identifier for the target chat or
username of the target supergroup (e.g., @supergroupusername)
Returns:
bool: True on success, False on failure
"""
url = f"https://api.telegram.org/bot{bot_token}/reopenGeneralForumTopic"
payload = {
"chat_id": chat_id
}
try:
response = requests.post(url, json=payload)
response.raise_for_status()
result = response.json()
if result.get("ok"):
return True
else:
print(f"Error: {result.get('description')}")
return False
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
return False
# Пример использования:
if __name__ == "__main__":
BOT_TOKEN = "YOUR_BOT_TOKEN_HERE"
# Пример с числовым chat_id
chat_id = -1001234567890
success = reopen_general_forum_topic(BOT_TOKEN, chat_id)
# Пример с username
# chat_id = "@my_supergroup"
# success = reopen_general_forum_topic(BOT_TOKEN, chat_id)
if success:
print("General forum topic reopened successfully")
else:
print("Failed to reopen general forum topic")
История изменений
- API 6.4. Добавлен метод reopenGeneralForumTopic