From 82fdb73ad7e7057939dc93410a1cf967c57fc659 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 22 Jul 2018 01:52:48 +0530 Subject: [PATCH] Add basecode. Added send_html(), add_to_db() and base code for dealing with the webhook. --- webhook.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 webhook.php 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"}; + +?>