Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conn = mysqli_connect("localhost", "root", "password_here", "dbname");
- $content = file_get_contents("php://input");
- $update = json_decode($content, true);
- $bot_token = "1809829596:AAF5zQdYM4lSddaXzpH8pfU_0OBpXh2tjdE";
- $chat_id = $update["message"]["chat"]["id"];
- $message = $update["message"]["text"];
- $command1 = explode(" ", $message, 2);
- $command = $command1[0];
- if($command == "/add_user"){
- $user_name = $command1[1];
- mysqli_query($conn, "INSERT INTO tablename (username) VALUES ($user_name)");
- send_message($chat_id, "A user '$user_name' added to database");
- }
- if($command == "/get_user"){
- $output_name = "";
- $query = mysqli_query($conn, "SELECT * FROM tablename");
- while($fetch = mysqli_fetch_assoc($query)){
- $output_name .= $fetch["username"]."\n";
- }
- send_message($chat_id, $output_name);
- }
- function send_message($id, $text)
- {
- global $bot_token;
- $text = urlencode($text);
- file_get_contents("https://api.telegram.org/bot$bot_token/sendMessage?chat_id=$id&text=$text");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement