Update api.twilio.php

This commit is contained in:
Namhyeon Go 2019-10-07 18:55:51 +09:00 committed by GitHub
parent 2894386112
commit cb62eef752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,26 +3,50 @@
* @file api.twilio.php
* @date 2019-04-15
* @author Go Namhyeon <gnh1201@gmail.com>
* @brief Twilio API controller
*/
* @brief Twilio API controller (or domestic API)
*/
loadHelper("twilio.api");
loadHelper("twilio.api"); // for voice, or international
loadHelper("lguplus.api"); // for domestic
loadHelper("string.utils");
$action = get_requested_value("action", array("_JSON", "_ALL"));
$message = get_requested_value("message", array("_JSON", "_ALL"));
$to = get_requested_value("to", array("_JSON", "_ALL"));
$country = get_requested_value("country", array("_JSON", "_ALL"));
$is_domestic = array_key_equals("lguplus_country", $config, $country);
if(!$is_domestic) {
$to = sprintf("+%s%s", $country, $to);
}
$response = false;
// temporary filter
$terms = get_tokenized_text($message);
if(!(in_array("LNCPLIMSDB", $terms) || in_array("LNCPSRMDBDEV", $terms))) {
exit;
}
switch($action) {
case "text":
$response = twilio_send_message($message, $to);
if(!$is_domestic) {
$response = twilio_send_message($message, $to);
} else {
$response = lguplus_send_message($message, $to);
}
break;
case "voice":
$response = twilio_send_voice($message, $to);
break;
default:
$response = array("error" => "action is required");
break;
}
write_common_log(sprintf("message: %s, to: %s", $message, $to), "api.twilio");
header("Content-Type: application/json");
echo json_encode($response);