Telegram neu organisiert
This commit is contained in:
@@ -6,7 +6,8 @@ error_reporting(E_ALL);
|
||||
|
||||
$config = require __DIR__ . '/../../config/database.php';
|
||||
$telegramConfig = require __DIR__ . '/../../config/telegram.php';
|
||||
require_once __DIR__ . '/../../config/telegram_message_footer.php';
|
||||
require_once __DIR__ . '/../../scripts/telegram/lib/message_footer.php';
|
||||
require_once __DIR__ . '/../../scripts/telegram/lib/http.php';
|
||||
|
||||
$dsn = sprintf(
|
||||
'mysql:host=%s;dbname=%s;charset=%s',
|
||||
@@ -33,50 +34,6 @@ function telegramWebhookRespond(array $payload, int $statusCode = 200): never
|
||||
exit;
|
||||
}
|
||||
|
||||
function telegramHttpPostJson(string $url, array $payload): bool
|
||||
{
|
||||
$jsonPayload = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if ($jsonPayload === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (function_exists('curl_init')) {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($jsonPayload),
|
||||
],
|
||||
CURLOPT_POSTFIELDS => $jsonPayload,
|
||||
CURLOPT_TIMEOUT => 15,
|
||||
]);
|
||||
|
||||
$body = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $body !== false;
|
||||
}
|
||||
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => implode("\r\n", [
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($jsonPayload),
|
||||
]),
|
||||
'content' => $jsonPayload,
|
||||
'timeout' => 15,
|
||||
'ignore_errors' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $context);
|
||||
|
||||
return $body !== false;
|
||||
}
|
||||
|
||||
function telegramSendBotMessage(array $telegramConfig, string $chatId, string $messageText): void
|
||||
{
|
||||
$botToken = trim((string) ($telegramConfig['bot_token'] ?? ''));
|
||||
|
||||
Reference in New Issue
Block a user