diff --git a/schema/data-actions.json b/schema/data-actions.json index 649daf6e5..7ce3d9549 100644 --- a/schema/data-actions.json +++ b/schema/data-actions.json @@ -144,6 +144,7 @@ ["SIS", "selector.set"], ["SIS", "selector.query"], ["SIS", "news"], + ["SIS", "whatsapp.incoming"], ["Stats", "mostMessagedTimeslotYear"], ["Stats", "mostListenedTimeslotYear"], ["Stats", "mostListenedShowYear"], diff --git a/schema/data-actionsauth.json b/schema/data-actionsauth.json index c39e14d67..879243841 100644 --- a/schema/data-actionsauth.json +++ b/schema/data-actionsauth.json @@ -163,6 +163,7 @@ ["SIS", "tracklist.findTrack", "AUTH_USESIS"], ["SIS", "webcam.get", "AUTH_USESIS"], ["SIS", "webcam.set", "AUTH_MODIFYWEBCAM"], + ["SIS", "whatsapp.incoming", "AUTH_NOLOGIN"], ["Stats", "bapsPlayCounter", "AUTH_TRACKSTATISTICS"], ["Stats", "fullTracklist", "AUTH_TRACKSTATISTICS"], ["Stats", "jukeboxPlayCounter", "AUTH_TRACKSTATISTICS"], diff --git a/schema/patches/19.sql b/schema/patches/19.sql new file mode 100644 index 000000000..28f06feb9 --- /dev/null +++ b/schema/patches/19.sql @@ -0,0 +1 @@ +INSERT INTO commtype (descr) VALUES ('WhatsApp'); diff --git a/src/Classes/Config.php b/src/Classes/Config.php index 0d311bc02..0d7328be6 100644 --- a/src/Classes/Config.php +++ b/src/Classes/Config.php @@ -555,6 +555,10 @@ final class Config public static $autoviz_clips_path = ''; public static $autoviz_public_clips_base = '/media/autoviz-clips'; + public static $sis_whatsapp_enable = false; + public static $sis_whatsapp_verify_token = ''; + public static $sis_whatsapp_api_token = ''; + /** * Array of tabs and plugins to be used by SIS. They will be loaded in order. */ diff --git a/src/Classes/ServiceAPI/MyRadio_Timeslot.php b/src/Classes/ServiceAPI/MyRadio_Timeslot.php index 0c4774625..b334f3ae8 100644 --- a/src/Classes/ServiceAPI/MyRadio_Timeslot.php +++ b/src/Classes/ServiceAPI/MyRadio_Timeslot.php @@ -1343,7 +1343,8 @@ public function getMessages($offset = 0) subject AS title, content AS body, (statusid = 2) AS read, - comm_source AS source + comm_source AS source, + sender AS sender FROM sis2.messages c INNER JOIN schedule.show_season_timeslot ts ON (c.timeslotid = ts.show_season_timeslot_id) WHERE statusid <= 2 AND c.timeslotid = $1 @@ -1357,11 +1358,14 @@ public function getMessages($offset = 0) $result[$k]['time'] = intval($v['time']); $result[$k]['id'] = intval($v['id']); //Add the IP metadata - if ($v['type'] == 3) { + if ($v['type'] === 3) { $result[$k]['location'] = SIS_Utils::ipLookup($v['source']); } $result[$k]['title'] = htmlspecialchars($v['title']); $result[$k]['body'] = htmlspecialchars($v['body']); + if ($v['type'] === 6) { + $result[$k]['author'] = htmlspecialchars($v['sender']); + } } return $result; @@ -1409,6 +1413,49 @@ public function sendMessage($message) return $this; } + /** + * Sends a message to the timeslot for display in SIS. + * + * @param string $message the message to be sent + * @param $sender + * @param $number + * @return MyRadio_Timeslot + */ + public function sendWhatsappMessage($message, $sender, $number): MyRadio_Timeslot + { + $message = trim($message); + + if (empty($message)) { + throw new MyRadioException('Message is empty.', 400); + } + + $junk = SIS_Utils::checkMessageSpam($message); + $warning = SIS_Utils::checkMessageSocialEngineering($message); + + if ($warning !== false) { + $prefix = '
' . $warning . '
'; + } else { + $prefix = ''; + } + + self::$db->query( + 'INSERT INTO sis2.messages (timeslotid, commtypeid, sender, subject, content, statusid, comm_source) + VALUES ($1, $2, $3, $4, $5, $6, $7)', + [ + $this->getID(), // timeslot + 6, // commtypeid : website + $sender, // sender + substr($message, 0, 144), // subject : trancated message + $prefix . $message, // content : message with prefix + $junk ? 4 : 1, // statusid : junk or unread + $number, // comm_source : sender mobile number + // TODO: ^ maybe not (GDPR) + ] + ); + + return $this; + } + /** * Signs the given user into the timeslot to say they were * on air at this time, if they haven't been signed in already. diff --git a/src/Controllers/SIS/whatsapp.incoming.php b/src/Controllers/SIS/whatsapp.incoming.php new file mode 100644 index 000000000..ae675dacd --- /dev/null +++ b/src/Controllers/SIS/whatsapp.incoming.php @@ -0,0 +1,63 @@ +sendWhatsappMessage($body, $from_name, $from); + } + } + } + } + } +} diff --git a/src/Controllers/root.php b/src/Controllers/root.php index afd0adef0..9ad288c7d 100644 --- a/src/Controllers/root.php +++ b/src/Controllers/root.php @@ -13,7 +13,7 @@ * This number is incremented every time a database patch is released. * Patches are scripts in schema/patches. */ -define('MYRADIO_CURRENT_SCHEMA_VERSION', 18); +define('MYRADIO_CURRENT_SCHEMA_VERSION', 19); /* * Turn on Error Reporting for the start. Once the Config object is loaded diff --git a/src/Public/js/sis.messages.js b/src/Public/js/sis.messages.js index ca5e22d09..ba0d601fd 100644 --- a/src/Public/js/sis.messages.js +++ b/src/Public/js/sis.messages.js @@ -3,8 +3,8 @@ var Messages = function () { var highest_message_id = 0, unreadMessages = 0, - glyphicons = ["question-sign", "envelope", "phone", "globe"], - locationNames = ["unknown method", "email", "text message", "the website"], + glyphicons = ["question-sign", "envelope", "phone", "globe", "globe", "globe", "phone"], + locationNames = ["unknown method", "email", "text message", "the website", "request", "mobile site", "WhatsApp"], table = document.createElement("table"), clickHandler = function (context, row, message) { $(row).click(function () { @@ -30,7 +30,11 @@ var Messages = function () { location = location + " (" + message.location[1] + ")"; } } - myradio.createDialog("Message", "" + location); + var listener = 'Listener'; + if (message.type === 6) { + listener = message.sender; + } + myradio.createDialog("Message", "" +message.body + "
" + location); }); };" +message.body + "