-
-
Save noplanman/5f81bf74a8defccb4509 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"; | |
} | |
} |
Outgoing messages aren't saved to the database, you will have to do that yourself. You can create your own table in the database and fill it with the message content.
Hope that helps
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I understand that the messages that people enter in the chat goes to the mysql database, yes, i got them and i use them. Is there any way i can add something to this broadcast.php code so the messages from the bot get saved in the mysql database too? Thanks a lot.