$DELETEEXISTENTWBHOOK = false; $REGISTERWEBHOOK = true; $TOKEN = "..."; $SSLCERTIFICATEFILE = "@certificate.pem"; $WEBHOOKURL = "https://www.yourwebsite.org/webhook.php"; $SETUPDB = true; $SETUPDBQUERIES = ["CREATE TABLE `Logs` (`id` bigint(20) NOT NULL AUTO_INCREMENT, `bot` varchar(100) NOT NULL, `action` varchar(100) NOT NULL, `chat` int(11) NOT NULL, `type` varchar(30) NOT NULL, `content` varchar(250) NOT NULL, `date` varchar(30) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `bot` (`bot`,`action`,`chat`,`date`));"]; include_once "lib/telegram.php"; if ($DELETEEXISTENTWBHOOK) { echo "Deleting registered webhook...\n"; $bot = new telegram_bot($TOKEN); $bot->set_webhook(); echo "Deleted!\n"; } else { // you can register a new webhook only if you're not deleting existent webhook if ($REGISTERWEBHOOK) { echo "Registering webhook...\n"; $bot = new telegram_bot($TOKEN); //$bot->set_webhook(); $bot->set_webhook($WEBHOOKURL, $SSLCERTIFICATEFILE); echo "Registered!\n"; } } if ($SETUPDB) { echo "Configuring Logs database...\n"; foreach ($SETUPDBQUERIES as $q) { db_nonquery($q); } echo "Configured!\n"; } echo "Installation completed!\n";
function trigger_err($p) { if ($p->chatid() < 0) { // if message has been sent from a member of a Telegram group // ignore it and do not reply (to avoid not necessary messages on the group) $response = logarray('ignore', null); } else { // reply with an error message $answer = "Error..."; $p->bot()->send_message($p->chatid(), $answer); $response = logarray('error', $answer); } return $response; } // instantiating a new bot $bot = new telegram_bot($token); // instantiating a new triggers set $ts = new telegram_trigger_set($botname, $singletrigger); // registering the triggers $ts->register_trigger_command("trigger_welcome", ["/start", "/welcome", "/hi"], 0); $ts->register_trigger_command("trigger_help", ["/help"], 0); $ts->register_trigger_command("trigger_photo", ["/getphoto", "/photo", "/picture"], -1); // parameters count is ignore // error trigger $ts->register_trigger_error("trigger_err"); // receiving data sent from the user $message = $bot->read_post_message(); $date = $message->message->date; $chatid = $message->message->chat->id; $text = $message->message->text; // running triggers management
function trigger_err($p) { if ($p->chatid() < 0) { // if message has been sent from a member of a Telegram group // ignore it and do not reply (to avoid not necessary messages on the group) $response = logarray('ignore', null); } else { // reply with an error message $answer = "Error..."; $p->bot()->send_message($p->chatid(), $answer); $response = logarray('error', $answer); } return $response; } // instantiating a new bot $bot = new telegram_bot($TELEGRAM_TOKEN); // receiving data sent from the user $data = $bot->read_post_message(); $message = $data->message; $date = $message->date; $chatid = $message->chat->id; $text = @$message->text; // instantiating a new triggers set $ts = new telegram_trigger_set($TELEGRAM_BOTNAME, $chatid, $singletrigger); // registering the triggers $ts->register_trigger_text_command("trigger_welcome", ["/start", "/welcome", "/hi"], 0); // state parameter is ignored $ts->register_trigger_text_command("trigger_help", ["/help"], 0); // state parameter is ignored $ts->register_trigger_text_command("trigger_photo", ["/lena", "/getphoto", "/photo", "/picture"]); // state and count parameters are ignored
$chatid = null; // send message to all registered chats if (isset($_GET['chatid'])) { $chatid = $_GET['chatid']; } else { if (!$BROADCASTS_ALLOWED) { exit("Broadcast messages are not allowed"); } } $message = $_GET['message']; // checking if logs are enabled (see https://github.com/auino/php-telegram-bot-library for more information) if (!LOGS_ENABLED) { exit("Logs are not enabled for this bot."); } // creating the bot object $bot = new telegram_bot($TELEGRAM_TOKEN); try { // creating base chat list $chatlist = array(); if ($chatid != null) { array_push($chatlist, $chatid); } else { $chatlist = db_getchatlist($TELEGRAM_BOTNAME); } // iterating over the chat list foreach ($chatlist as $chat) { // getting current date $date = (string) time(); // sending the message $r = $bot->send_message($chat, $message); // log sent message on the database
{ if ($p->chatid() < 0) { // if message has been sent from a member of a Telegram group // ignore it and do not reply (to avoid not necessary messages on the group) $response = logarray('ignore', null); } else { // reply with an error message $answer = "Error..."; $answer = "" . print_r($p->message(), true); $p->bot()->send_message($p->chatid(), $answer); $response = logarray('error', $answer); } return $response; } // instantiating a new bot $bot = new telegram_bot($token); // receiving data sent from the user $data = $bot->read_post_message(); // reading standard message data $message = $data->message; $date = $message->date; $chatid = $message->chat->id; $text = @$message->text; // reading inline query basic data $inline_query = $data->inline_query; $inline_query_id = $inline_query->id; // managing inline query results if ($inline_query_id != "") { // getting additional inline data $inline_query_msg = $inline_query->query; $inline_chatid = $inline_query->from->id;