* @throws CRM_Core_Exception
*/
public function processInbound($from, $body, $to = NULL, $trackID = NULL) {
- $formatFrom = $this->formatPhone($this->stripPhone($from), $like, "like");
- $escapedFrom = CRM_Utils_Type::escape($formatFrom, 'String');
- $fromContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone JOIN civicrm_contact ON civicrm_contact.id = civicrm_phone.contact_id WHERE !civicrm_contact.is_deleted AND phone LIKE "%' . $escapedFrom . '"');
+ $fromContactID = NULL;
+ $toContactID = NULL;
+ // call hook_civicrm_inboundSMS
+ CRM_Utils_Hook::inboundSMS($from, $fromContactID, $to, $toContactID, $body, $trackID);
+
+ if (!$fromContactID) {
+ // find sender by phone number if $fromContactID not set by hook
+ $formatFrom = $this->formatPhone($this->stripPhone($from), $like, "like");
+ $escapedFrom = CRM_Utils_Type::escape($formatFrom, 'String');
+ $fromContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone JOIN civicrm_contact ON civicrm_contact.id = civicrm_phone.contact_id WHERE !civicrm_contact.is_deleted AND phone LIKE "%' . $escapedFrom . '"');
+ }
if (!$fromContactID) {
// unknown mobile sender -- create new contact
$fromContactID = $fromContact->id;
}
- if ($to) {
- $to = CRM_Utils_Type::escape($to, 'String');
- $toContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone JOIN civicrm_contact ON civicrm_contact.id = civicrm_phone.contact_id WHERE !civicrm_contact.is_deleted AND phone LIKE "%' . $to . '"');
- }
- else {
- $toContactID = $fromContactID;
+ if (!($toContactID)) {
+ // find recipient if $toContactID not set by hook
+ if ($to) {
+ $to = CRM_Utils_Type::escape($to, 'String');
+ $toContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone JOIN civicrm_contact ON civicrm_contact.id = civicrm_phone.contact_id WHERE !civicrm_contact.is_deleted AND phone LIKE "%' . $to . '"');
+ }
+ else {
+ $toContactID = $fromContactID;
+ }
}
if ($fromContactID) {
);
}
+ /**
+ * This hook is called before an inbound SMS is processed.
+ *
+ * @param string $from
+ * The phone number the message is from, as set by SMS provider
+ * @param int $fromContactID
+ * Set to override default matching
+ * @param string $to
+ * The optional phone number the message is to, as set by SMS provider
+ * @param int $toContactID
+ * Set to override default matching
+ * @param string $body
+ * The body text of the message
+ * @param string $trackID
+ * The tracking ID of the message
+ *
+ * @return mixed
+ */
+ public static function inboundSMS(&$from, &$fromContactID = NULL, &$to, &$toContactID = NULL, &$body, &$trackID) {
+ return self::singleton()
+ ->invoke(6, $from, $fromContactID, $to, $toContactID, $body, $trackID, 'civicrm_inboundSMS');
+ }
+
}