From 6a7db03c5ad564e853ba99c309dffdbc21005d1f Mon Sep 17 00:00:00 2001 From: UltraDesu Date: Wed, 17 Jan 2018 14:22:56 +0300 Subject: [PATCH] user registration via telegram --- .gitignore | 2 ++ webhook/index.php | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 .gitignore create mode 100644 webhook/index.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2e9ec51 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +settings.ini +.vscode/* \ No newline at end of file diff --git a/webhook/index.php b/webhook/index.php new file mode 100644 index 0000000..5c69886 --- /dev/null +++ b/webhook/index.php @@ -0,0 +1,78 @@ + $id, + 'text' => $msg + ); + $options = array( + 'http' => array( + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", + 'method' => 'POST', + 'content' => http_build_query($data) + ) + ); + $context = stream_context_create($options); + $result = file_get_contents($url, false, $context); + if ($result === FALSE) { return FALSE; } + return TRUE; +} + +if( !$request ) +{ + die(); +} +elseif( !isset($request['update_id']) || !isset($request['message']) ) +{ + die(); +} +else +{ + $chatId = $request['message']['chat']['id']; + $message = $request['message']['text']; + $user_id = $request['message']['from']['id']; + $username = $request['message']['from']['username']; + + if($message == '/start') + { + $stmt = $dbh->query( + 'SELECT id FROM `contact` + WHERE user_id = "'.$user_id.'"' + ); + if($stmt->rowCount() == 0) + { + $stmt = $dbh->query( + 'INSERT into contact (username, user_id) + VALUES ("'.$username.'","'.$user_id.'")' + ); + send( + $user_id, + 'Hello! Send me an URL and i will notify you when topic will be updated.', + $config + ); + } + else + { + send( + $user_id, + 'Hello again. Send me an URL and i will notify you when topic will be updated.', + $config + ); + die(); + } + // if message is an URL + }elseif(!(filter_var($message, FILTER_VALIDATE_URL) === FALSE)) { + send( + $user_id, + 'Recognized as an URL', + $config + ); + } +} +?> \ No newline at end of file