diff --git a/webhook.php b/webhook.php new file mode 100644 index 0000000..6bd0228 --- /dev/null +++ b/webhook.php @@ -0,0 +1,62 @@ + $chat_id, 'text' =>$post_message, 'parse_mode' => 'html'); + if ($reply != false) { + if ($reply === true){ + $post_msg['reply_to_message_id'] = $decoded->{'message'}->{'message_id'}; + } + else { + $post_msg['reply_to_message_id'] = $reply; + } + } + $options = array( + 'http' => array( + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", + 'method' => 'POST', + 'content' => http_build_query($post_msg) + ) + ); + $context = stream_context_create($options); + $result = file_get_contents($url, false, $context); +} + +function add_to_db($success) { + global $decoded; + $user_id = $decoded->{"message"}->{"from"}->{"id"}; + $timestamp = $decoded->{"message"}->{"forward_date"}; + $mysql = require('mysql_credentials.php'); + $conn = new mysqli($mysql['servername'], $mysql['username'], $mysql['password'], $mysql['database']); + if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); + } + $stmt = $conn->prepare("INSERT INTO data (id, timestamp, success) VALUES (?,?,?);"); + $stmt->bind_param('iii', $user_id, $timestamp, $success); + $stmt->execute(); + $conn->close(); +} + +// Get JSON from post, store it and decode it. +$var = file_get_contents('php://input'); +$decoded = json_decode($var); + +// Store the chat ID +$chat_id = $decoded->{"message"}->{"chat"}->{"id"}; +if ($decoded->{"message"}->{"forward_from"}->{"username"} != "chtwrsbot") { + exit(); +} + +if (!isset($decoded->{"message"}->{"text"})){ + exit(); +} + +$text = $decoded->{"message"}->{"text"}; + +?>