Skip to content

Instantly share code, notes, and snippets.

@rizkytegar
Last active August 26, 2023 03:06
Show Gist options
  • Save rizkytegar/c795e8622c2ea3b0e99abe7d93cc6d15 to your computer and use it in GitHub Desktop.
Save rizkytegar/c795e8622c2ea3b0e99abe7d93cc6d15 to your computer and use it in GitHub Desktop.
<?php
$token = "xx:xxx";
$telegram_id = "xxx";
$text = "Ini adalah notifikasi dari website.";
$url = "https://api.telegram.org/bot" . $token . "/sendMessage";
$data = array(
'chat_id' => $telegram_id,
'text' => $text
);
$options = array(
'http' => array(
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === false) {
echo "Gagal mengirim notifikasi.";
} else {
echo "Notifikasi berhasil dikirim.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment