Skip to content

Instantly share code, notes, and snippets.

@ariefbayu
Last active June 15, 2018 11:28
Show Gist options
  • Save ariefbayu/e3ffe27f9c50cb674edd to your computer and use it in GitHub Desktop.
Save ariefbayu/e3ffe27f9c50cb674edd to your computer and use it in GitHub Desktop.
<?php
$loader = require __DIR__.'/vendor/autoload.php';
use Longman\TelegramBot\Request;
$API_KEY = '--botfather-api-keu--';
$BOT_NAME = '--bofather-bot-name--';
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
$message = isset($argv[2]) ? $argv[2] : '';
$telegramId = isset($argv[1]) ? $argv[1] : '';
if($message !== '' && $telegramId !== ''){
$data = [];
$data['chat_id'] = $telegramId;
$data['text'] = $message;
$result = Request::sendMessage($data);
if ($result->isOk()) {
echo 'Message sent succesfully to: '.$data['chat_id'] ;
} else {
echo 'Sorry message not sent to: '.$data['chat_id'] ;
}
}
//to use it, just call: $php broadcast.php [telegram-chat-id] [message]
@ariefbayu
Copy link
Author

revision 2 based on the following suggestion: php-telegram-bot/core#71 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment