router_add("/appeals/", function () { appeal_save(); }, array("post")); function appeal_save() { $appeal_title = $_POST["title"]; $appeal = new Appeals(0); $appeal->create("Заявка - " . $appeal_title, ""); foreach ($_POST as $key => $value) $appeal->set_prop($key, $value); appeal_send($appeal->item_id); echo json_encode(array("ok" => true)); exit(); } function appeal_send($appeal_id) { global $b; $root_url = $b->router_get_root_uri(); $text = " 💬 Новое обращение: "; $text .= $b->get_view($_POST["title"]) . "\n\n"; if(isset($_POST["name"])) $text .= "Имя: " . $b->get_view($_POST["name"]) . "\n"; if(isset($_POST["email"])) $text .= "Email: " . $b->get_view($_POST["email"]) . "\n"; if(isset($_POST["phone"])) $text .= "Телефон: " . $b->get_view($_POST["phone"]) . "\n"; if(isset($_POST["message"])) $text .= "\nСообщение: " . $b->get_view($_POST["message"]) . "\n"; if(isset($_POST["url"])) $text .= "\nСтраница пользователя: " . $b->get_view($_POST["url"]) . "\n"; $text .= "\nПолная информация "; appeal_send_tg($text); } function appeal_send_tg($text) { // $tg_chat_id = "-1001914432978"; // $tg_token = "6133273622:AAEhbwiXUV89XGw3KumQPKWQIrYkh8p8LwY"; // $apiUrl = "https://api.telegram.org/bot" . $tg_token . "/sendMessage"; // // $postData = array( // 'chat_id' => $tg_chat_id, // 'text' => $text, // 'parse_mode' => "HTML", // 'disable_web_page_preview' => true // ); // // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, $apiUrl); // curl_setopt($ch, CURLOPT_POST, 1); // curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_exec($ch); // curl_close($ch); }