Skip to content

Instantly share code, notes, and snippets.

@paksv
Forked from noplanman/broadcast.php
Created August 9, 2017 12:44
Show Gist options
  • Save paksv/a53a6f16e3b668c4fde5c2ca14878bee to your computer and use it in GitHub Desktop.
Save paksv/a53a6f16e3b668c4fde5c2ca14878bee to your computer and use it in GitHub Desktop.
<?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