Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
add inbound sms
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiez committed May 4, 2022
1 parent 8f506c2 commit 998ec94
Show file tree
Hide file tree
Showing 33 changed files with 980 additions and 2,779 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# [sms77](https://www.sms77.io/) SMS module for Suite CRM

This module requires at least PHP 7.3.
Only tested with SuiteCRM 7.x, but it should work well with 6.x too.

## Installation

- Download latest release
Expand Down
6 changes: 6 additions & 0 deletions SuiteModules/EntryPoint/sms77_inbound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

$entry_point_registry['sms77_inbound'] = [
'auth' => false,
'file' => 'modules/sms77/receiveSMS.php',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
//WARNING: The contents of this file are auto-generated

if (!isset($mod_strings)) $mod_strings = [];

$mod_strings['LBL_SMS77_TITLE'] = 'sms77 Konfiguration';
$mod_strings['LBL_SMS77_DESC'] = '';

$mod_strings['LBL_SMS77_CONFIGURATION_TITLE'] = 'sms77 API-Konfiguration';
$mod_strings['LBL_SMS77_CONFIGURATION_DESC'] = 'sms77 Konfiguration';

$mod_strings['LBL_SMS77_TEMPLATE_CONFIGURATION_TITLE'] = 'Kontakt Vorlagen-Konfiguration';
$mod_strings['LBL_SMS77_TEMPLATE_CONFIGURATION_DESC'] = 'Kontakt Vorlagen-Konfiguration';

$mod_strings['LBL_SMS77_LEAD_CONFIGURATION_TITLE'] = 'Lead Vorlagen-Konfiguration';
$mod_strings['LBL_SMS77_LEAD_CONFIGURATION_DESC'] = 'Lead Vorlagen-Konfiguration';

$mod_strings['LBL_SMS77_PANEL_HEADING'] = 'SMS via sms77';
?>
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

$mod_strings['LBL_SMS77_LEAD_CONFIGURATION_TITLE'] = 'Lead Template Configuration';
$mod_strings['LBL_SMS77_LEAD_CONFIGURATION_DESC'] = 'Lead Template Configuration';

$mod_strings['LBL_SMS77_PANEL_HEADING'] = 'SMS by sms77';
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$mod_strings['LBL_SMS77_FROM'] = 'Absendekennung';
$mod_strings['LBL_SMS77_MESSAGES'] = 'Nachrichten';
$mod_strings['LBL_SMS77_MISSING_TEXT'] = 'Bitte Nachrichtentext eingeben';
$mod_strings['LBL_SMS77_PANEL_HEADING'] = 'SMS-Verlauf';
$mod_strings['LBL_SMS77_SEND_SMS_VIA'] = 'SMS-Versand via sms77';
$mod_strings['LBL_SMS77_SEND_SMS'] = 'SMS versenden';
$mod_strings['LBL_SMS77_TEXT'] = 'Text';
$mod_strings['LBL_SMS77_TO'] = 'Anrufziel';
$mod_strings['LBL_SMS77_TO_HELP'] = 'Mehrere Anrufziele per Komma getrennt angeben';
$mod_strings['LBL_SMS77_WRITE_SMS'] = 'SMS schreiben';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$mod_strings['LBL_SMS77_FROM'] = 'From';
$mod_strings['LBL_SMS77_MESSAGES'] = 'Messages';
$mod_strings['LBL_SMS77_MISSING_TEXT'] = 'Please enter a message';
$mod_strings['LBL_SMS77_PANEL_HEADING'] = 'SMS History';
$mod_strings['LBL_SMS77_SEND_SMS_VIA'] = 'Send SMS via sms77';
$mod_strings['LBL_SMS77_SEND_SMS'] = 'Send SMS';
$mod_strings['LBL_SMS77_TEXT'] = 'Text';
$mod_strings['LBL_SMS77_TO'] = 'To';
$mod_strings['LBL_SMS77_TO_HELP'] = 'Add more recipients separated by comma';
$mod_strings['LBL_SMS77_WRITE_SMS'] = 'Write SMS';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
// created: 2022-04-26 10:39:04
$dictionary['Contact']['fields']['sms77_compose_sms']['inline_edit'] = '0';
$dictionary['Contact']['fields']['sms77_compose_sms']['labelValue'] = 'Write SMS';

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$mod_strings['LBL_SMS77_FROM'] = 'Absendekennung';
$mod_strings['LBL_SMS77_MESSAGES'] = 'Nachrichten';
$mod_strings['LBL_SMS77_MISSING_TEXT'] = 'Bitte Nachrichtentext eingeben';
$mod_strings['LBL_SMS77_PANEL_HEADING'] = 'SMS-Verlauf';
$mod_strings['LBL_SMS77_SEND_SMS_VIA'] = 'SMS-Versand via sms77';
$mod_strings['LBL_SMS77_SEND_SMS'] = 'SMS versenden';
$mod_strings['LBL_SMS77_TEXT'] = 'Text';
$mod_strings['LBL_SMS77_TO'] = 'Anrufziel';
$mod_strings['LBL_SMS77_TO_HELP'] = 'Mehrere Anrufziele per Komma getrennt angeben';
$mod_strings['LBL_SMS77_WRITE_SMS'] = 'SMS schreiben';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$mod_strings['LBL_SMS77_FROM'] = 'From';
$mod_strings['LBL_SMS77_MESSAGES'] = 'Messages';
$mod_strings['LBL_SMS77_MISSING_TEXT'] = 'Please enter a message';
$mod_strings['LBL_SMS77_PANEL_HEADING'] = 'SMS History';
$mod_strings['LBL_SMS77_SEND_SMS_VIA'] = 'Send SMS via sms77';
$mod_strings['LBL_SMS77_SEND_SMS'] = 'Send SMS';
$mod_strings['LBL_SMS77_TEXT'] = 'Text';
$mod_strings['LBL_SMS77_TO'] = 'To';
$mod_strings['LBL_SMS77_TO_HELP'] = 'Add more recipients separated by comma';
$mod_strings['LBL_SMS77_WRITE_SMS'] = 'Write SMS';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
// created: 2022-04-26 10:39:04
$dictionary['Contact']['fields']['sms77_compose_sms']['inline_edit'] = '0';
$dictionary['Contact']['fields']['sms77_compose_sms']['labelValue'] = 'Write SMS';

?>
37 changes: 37 additions & 0 deletions SuiteModules/modules/Contacts/views/view.detail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once 'modules/Contacts/views/view.detail.php';
require_once 'modules/sms77/sms77_util.php';

class CustomContactsViewDetail extends ContactsViewDetail {
public function display() {
global $sugar_config;

$history = array_merge($this->getOutboundSms(), $this->getInboundSms());

usort($history, function (SugarBean $a, SugarBean $b) {
return strcmp($a->date_entered, $b->date_entered);
});

/** @var Contact $contact */
$contact = $this->bean;
$this->ss->assign('SMS77_BEAN_ID', $this->bean->id);
$this->ss->assign('SMS77_FROM', $sugar_config['sms77_sender'] ?? '');
$this->ss->assign('SMS77_MODULE', $this->module);
$this->ss->assign('SMS77_SMS_HISTORY', $history);
$this->ss->assign('SMS77_TO', $contact->phone_mobile);

echo $this->ss->fetch('modules/sms77/tpls/sms_compose.tpl');

parent::display();
}

private function getInboundSms(): array {
return sms77_util::getSMS('sms77_sms_inbound', $this->bean);
}

private function getOutboundSms(): array {
return sms77_util::getSMS('sms77_sms', $this->bean);
}
}
37 changes: 37 additions & 0 deletions SuiteModules/modules/Leads/views/view.detail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once 'modules/Leads/views/view.detail.php';
require_once 'modules/sms77/sms77_util.php';

class CustomLeadsViewDetail extends LeadsViewDetail {
public function display() {
global $sugar_config;

$history = array_merge($this->getOutboundSms(), $this->getInboundSms());

usort($history, function (SugarBean $a, SugarBean $b) {
return strcmp($a->date_entered, $b->date_entered);
});

/** @var Lead $bean */
$bean = $this->bean;
$this->ss->assign('SMS77_BEAN_ID', $this->bean->id);
$this->ss->assign('SMS77_FROM', $sugar_config['sms77_sender'] ?? '');
$this->ss->assign('SMS77_MODULE', $this->module);
$this->ss->assign('SMS77_SMS_HISTORY', $history);
$this->ss->assign('SMS77_TO', $bean->phone_mobile);

echo $this->ss->fetch('modules/sms77/tpls/sms_compose.tpl');

parent::display();
}

private function getInboundSms(): array {
return sms77_util::getSMS('sms77_sms_inbound', $this->bean);
}

private function getOutboundSms(): array {
return sms77_util::getSMS('sms77_sms', $this->bean);
}
}
126 changes: 60 additions & 66 deletions SuiteModules/modules/sms77/FeedPusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,96 @@
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once 'modules/SugarFeed/feedLogicBase.php';
error_reporting(0);
require_once 'modules/sms77/sms77_util.php';

class FeedPusher extends FeedLogicBase {
public $module = 'Contacts';

private function getPhoneNumbers($phones) {
$numbers = [];

foreach ($phones as $phone)
if ($this->isValidPhoneNumber($phone)) $numbers[] = $phone;

return $numbers;
}

public function pushFeed($bean, $event, $arguments) {
global $locale, $sms;

require_once 'modules/sms77/sendSMS.php'; // initializes $sms

$this->module = $_REQUEST['module'] ?? $this->module;

if (!empty($bean->fetched_row)) return;
if ($_REQUEST['module']) $this->module = $_REQUEST['module'];

$officePhone = $bean->phone_work;
$mobilePhone = $bean->phone_mobile;
$fullName = $locale->getLocaleFormattedName($bean->first_name, $bean->last_name);
$fullName = trim($fullName);
[$firstName, $lastName] = explode(' ', $fullName);

require_once 'modules/sms77/sendSMS.php'; // initializes $sms

$relation = $bean;
if ('Contacts' === $this->module) {
$templateActive = $sms->getTemplateActive();
$template = $sms->getTemplateBody();
} elseif ('Leads' === $this->module) {
$templateActive = $sms->getLeadActive();
$template = $sms->getLeadBody();
} else {
$templateActive = 'no';
$templateActive = false;
$template = '';
$relation = null;
}

$numbers = $this->getPhoneNumbers([$mobilePhone, $officePhone]);
$sms->setRelation($relation);

if ('yes' === $templateActive && count($numbers)) {
$msg = str_replace([
'{first-name}',
'{last-name}',
'{full-name}',
'{office-phone}',
'{mobile-number}',
'{job-title}',
'{department}',
'{account-name}',
'{email}',
'{primary-address}',
'{primary-city}',
'{primary-state}',
'{primary-postalcode}',
'{primary-country}',
'{alter-address}',
'{alter-city}',
'{alter-state}',
'{alter-postalcode}',
'{alter-country}',
'{description}',
'{date}',
], [
$firstName,
$lastName,
$bean->first_name . ' ' . $bean->last_name,
$officePhone,
$mobilePhone,
$bean->title,
$bean->department,
$bean->account_name,
$bean->email1,
$bean->primary_address_street,
$bean->primary_address_city,
$bean->primary_address_state,
$bean->primary_address_postalcode,
$bean->primary_address_country,
$bean->alt_address_street,
$bean->alt_address_city,
$bean->alt_address_state,
$bean->alt_address_postalcode,
$bean->alt_address_country,
$bean->description,
date('d/m/Y'),
], trim($template));
if ($templateActive) {
$numbers = sms77_util::getValidPhoneNumbers([$mobilePhone, $officePhone]);

$sms->apiCall($sms->getSender(), $msg, implode(',', $numbers));
if (count($numbers)) {
$msg = str_replace([
'{first-name}',
'{last-name}',
'{full-name}',
'{office-phone}',
'{mobile-number}',
'{job-title}',
'{department}',
'{account-name}',
'{email}',
'{primary-address}',
'{primary-city}',
'{primary-state}',
'{primary-postalcode}',
'{primary-country}',
'{alter-address}',
'{alter-city}',
'{alter-state}',
'{alter-postalcode}',
'{alter-country}',
'{description}',
'{date}',
], [
$firstName,
$lastName,
$bean->first_name . ' ' . $bean->last_name,
$officePhone,
$mobilePhone,
$bean->title,
$bean->department,
$bean->account_name,
$bean->email1,
$bean->primary_address_street,
$bean->primary_address_city,
$bean->primary_address_state,
$bean->primary_address_postalcode,
$bean->primary_address_country,
$bean->alt_address_street,
$bean->alt_address_city,
$bean->alt_address_state,
$bean->alt_address_postalcode,
$bean->alt_address_country,
$bean->description,
date('d/m/Y'),
], trim($template));

$sms->apiCall($sms->getSender(), $msg, implode(',', $numbers));
}
}

SugarFeed::pushFeed2('{SugarFeed.CREATED_CONTACT} [' . $bean->module_dir . ':'
. $bean->id . ':' . $fullName . ']', $bean);
}

private function isValidPhoneNumber($phone) {
return !empty($phone) && strlen($phone) >= 9;
}
}
25 changes: 0 additions & 25 deletions SuiteModules/modules/sms77/RenderSmsButtons.php

This file was deleted.

Loading

0 comments on commit 998ec94

Please sign in to comment.