Telegram bot webhook setting
Get Web hook info
https://api.telegram.org/bot<bot_token>/getWebhookInfo
Set webhook "
https://api.telegram.org/bot123456:ABC-DEF1x57W2v1u123ew11/setWebhook?url=https://www.example.com
"
Simple bot "
//////////////////////////////////////////////////////////////
<?php
// Set your Telegram bot token and chat IDs
$token = "6362906582:AS_J3JurrZPqpGRcx_kGXinYQjg";
$chatIDs = ["1306957765", "1175802040"]; // Add more chat IDs as needed
// Function to send a message to Telegram
function sendMessage($message, $chatID) {
global $token;
$url = "https://api.telegram.org/bot$token/sendMessage?chat_id=$chatID&text=" . urlencode($message);
file_get_contents($url);
}
// Database credentials
$dbHost = "localhost";
$dbUser = "";
$dbPass = "";
$dbName = "";
// Set the interval in seconds
// Read the last checked ID from a file
$lastCheckedIDFile = "last_checked_id.txt";
if (file_exists($lastCheckedIDFile)) {
$lastCheckedID = intval(file_get_contents($lastCheckedIDFile));
} else {
$lastCheckedID = 0;
}
while (true) {
// Create a connection to the database
$conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
// Check for connection errors
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query for new rows in the "recharge" table
$query = "SELECT * FROM recharge WHERE id > $lastCheckedID";
$result = $conn->query($query);
if ($result->num_rows > 0) {
// Process and send messages for new rows
while ($row = $result->fetch_assoc()) {
$username = $row["username"];
$recharge = $row["recharge"];
$status = $row["status"];
$utr = $row["utr"];
// Compose the message
$message = "New Recharge:\nUsername: $username\nRecharge: $recharge\nStatus: $status\nUTR: $utr";
// Send the message to all chat IDs
foreach ($chatIDs as $chatID) {
sendMessage($message, $chatID);
}
// Update the last checked ID
$lastCheckedID = $row["id"];
// Save the last checked ID to the file
file_put_contents($lastCheckedIDFile, $lastCheckedID);
}
}
// Close the database connection
$conn->close();
}
?>
"
Comments
Post a Comment