From 5c697b52403759e50132640d3094e087131a615d Mon Sep 17 00:00:00 2001 From: osaajani <> Date: Tue, 29 Oct 2024 13:00:24 +0100 Subject: [PATCH] Add a simpler URL to send a sms with nothing but a GET request and an URL --- controllers/publics/Api.php | 41 +++++++++++++++++++++++++++++++++++++ routes.php | 3 +++ 2 files changed, 44 insertions(+) diff --git a/controllers/publics/Api.php b/controllers/publics/Api.php index 40afc8e..7760c7f 100644 --- a/controllers/publics/Api.php +++ b/controllers/publics/Api.php @@ -304,6 +304,47 @@ namespace controllers\publics; return $this->json($return); } + /** + * Simplest method to send a SMS immediately with nothing but a URL and a GET query + * @param string $_GET['to'] = Phone number to send sms to + * @param string $_GET['text'] = Text of the SMS + * @param ?int $_GET['id_phone'] = Id of the phone to use, if null use a random phone + */ + public function get_send_sms() + { + $to = \controllers\internals\Tool::parse_phone($_GET['to'] ?? ''); + $text = $_GET['text'] ?? false; + $id_phone = empty($_GET['id_phone']) ? null : $_GET['id_phone']; + + if (!$to || !$text) + { + $return = self::DEFAULT_RETURN; + $return['error'] = self::ERROR_CODES['MISSING_PARAMETER']; + $return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . ($to ? '' : 'to ') . ($text ? '' : 'text'); + $this->auto_http_code(false); + + return $this->json($return); + } + $at = (new \DateTime())->format('Y-m-d H:i:s'); + + $scheduled_id = $this->internal_scheduled->create($this->user['id'], $at, $text, $id_phone); + if (!$scheduled_id) + { + $return = self::DEFAULT_RETURN; + $return['error'] = self::ERROR_CODES['CANNOT_CREATE']; + $return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE']; + $this->auto_http_code(false); + + return $this->json($return); + } + + $return = self::DEFAULT_RETURN; + $return['response'] = $scheduled_id; + $this->auto_http_code(true); + + return $this->json($return); + } + /** * Schedule a message to be send. * diff --git a/routes.php b/routes.php index e3746db..bff3f98 100644 --- a/routes.php +++ b/routes.php @@ -221,6 +221,9 @@ '/api/invalid_number/', '/api/invalid_number/{page}/', ], + 'get_send_sms' => [ + '/api/send-sms/', + ], 'post_scheduled' => [ '/api/scheduled/', ],