Telegram is an amazing platform to get notifications quickly. In order to do so, follow these instructions:
/token
// Telegram Bot API token and chat ID
$telegram_bot_token = 'YOUR_TELEGRAM_BOT_TOKEN';
$telegram_chat_id = 'YOUR_TELEGRAM_CHAT_ID';
// Post title from the event
$post_title = $event->post->get_title();
// Message content
$message_content = '"' . $post_title . '" website has been submitted.';
// Telegram API URL
$url = "https://api.telegram.org/bot$telegram_bot_token/sendMessage";
// Setup request to send JSON via POST
$data = array(
'chat_id' => $telegram_chat_id,
'text' => $message_content,
);
$post = json_encode($data);
// Set up cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// Send the request and get the response
$response = curl_exec($ch);
$error = curl_error($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close cURL session handle
curl_close($ch);
// Check for errors and process the response
if ($error) {
error_log('Curl error: ' . $error);
} else {
// Process the response as needed
error_log('Telegram API response: ' . $response);
}
Be sure to change the TOKENs in the code to your own and the message content as needed.