-
-
Save paksv/a53a6f16e3b668c4fde5c2ca14878bee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Usage on CLI: $ php broadcast.php [telegram-chat-id] [message] | |
*/ | |
require __DIR__ . '/vendor/autoload.php'; | |
use Longman\TelegramBot\Request; | |
use Longman\TelegramBot\Telegram; | |
$API_KEY = '--botfather-api-key--'; | |
$BOT_NAME = '--botfather-bot-name--'; | |
$telegram = new Telegram($API_KEY, $BOT_NAME); | |
// Get the chat id and message text from the CLI parameters. | |
$chat_id = isset($argv[1]) ? $argv[1] : ''; | |
$message = isset($argv[2]) ? $argv[2] : ''; | |
if ($chat_id !== '' && $message !== '') { | |
$data = [ | |
'chat_id' => $chat_id, | |
'text' => $message, | |
]; | |
$result = Request::sendMessage($data); | |
if ($result->isOk()) { | |
echo 'Message sent succesfully to: ' . $chat_id . "\n"; | |
} else { | |
echo 'Sorry message not sent to: ' . $chat_id . "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment