Skip to content

Commit

Permalink
add workflow action sevenSms
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiez committed Dec 5, 2023
1 parent 7cead7a commit 6b357af
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Only tested with SuiteCRM 7.x, but it should work well with 6.x too.

### Placeholders

You can use the following placeholders in your messages:
You can use the following placeholders in your messages (not workflows):

#### Contact / Lead

Expand Down Expand Up @@ -85,6 +85,15 @@ You can use the following placeholders in your messages:
- {ticker_symbol}
- {website}

### Workflows
You can use the workflow action *sevenSms* to send SMS.
The action works with the following modules:
- Accounts
- Contacts
- Employees
- Leads
- Users

## Support

Need help? Feel free to [contact us](https://www.seven.io/en/company/contact/).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$aow_actions_list[] = 'SevenSms';
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php /** @noinspection PhpUnused */

require_once __DIR__ . '/../../../../modules/AOW_Actions/actions/actionBase.php';

class actionSevenSms extends actionBase {
public function __construct($id = '') {
parent::__construct($id);
}

public function loadJS() {
return [];
}

public function edit_display($line, SugarBean $bean = null, $params = []) {
return "<input maxlength='16' name='aow_actions_param[" . $line . "][from]' placeholder='"
. translate('LBL_SEVENSMS_FROM', 'AOW_Actions') . "' type='tel' value=' " . $params['from']
. "'>"
. "<textarea cols='110' name='aow_actions_param[" . $line . "][text]' placeholder='"
. translate('LBL_SEVENSMS_TEXT', 'AOW_Actions') . "' rows='5'>" . $params['text']
. "</textarea>";
}

protected function getPhoneFromParams(SugarBean $bean, array $params): ?string {
switch ($bean->module_name) {
case 'Accounts':
/** @var Account $bean */

return $bean->phone_alternate;
case 'Contacts':
/** @var Contact $bean */

return $bean->phone_mobile;
case 'Employees':
/** @var Employee $bean */

return $bean->phone_mobile;
case 'Leads':
/** @var Lead $bean */

return $bean->phone_mobile;
case 'Users':
/** @var User $bean */

return $bean->phone_mobile;
default:
return null;
}
}

/**
* Return true on success otherwise false.
* Use actionSevenSms::getLastMessagesSuccess() and actionSevenSms::getLastMessagesFailed()
* methods to get last SMS sending status
* @param SugarBean $bean
* @param array $params
* @param bool $in_save
* @return boolean
*/
public function run_action(SugarBean $bean, $params = [], $in_save = false) {
global $sugar_config;

$to = $this->getPhoneFromParams($bean, $params);
if (!$to) return false;

$apiKey = $sugar_config['seven_api_key'];
if (!$apiKey) return false;

$text = $params['text'];
$from = $params['from'];

$ch = curl_init('https://gateway.seven.io/api/sms');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(compact('from', 'text', 'to')));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json',
'Content-type: application/json',
'X-Api-Key: ' . $sugar_config['seven_api_key'],
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$result = json_decode($result);
curl_close($ch);

return 100 === $result->success;
}
}
11 changes: 11 additions & 0 deletions SuiteModules/Extension/modules/AOW_Actions/language/en_us.lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}

$mod_strings = [
'LBL_SEVENSMS' => 'seven SMS',
'LBL_SEVENSMS_FROM' => 'From',
'LBL_SEVENSMS_TEXT' => 'Text',
];
6 changes: 4 additions & 2 deletions logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
'is_uninstallable' => true,
'key' => '',
'name' => 'seven',
'published_date' => 'November 17, 2023',
'published_date' => 'December 05, 2023',
'readme' => '',
'remove_tables' => 'prompt',
'type' => 'module',
'version' => 'v0.4.0',
'version' => 'v0.5.0',
];

$installdefs = [
Expand Down Expand Up @@ -69,6 +69,10 @@
'from' => '<basepath>/SuiteModules/Extension/modules/Leads',
'to' => 'custom/Extension/modules/Leads',
],
[
'from' => '<basepath>/SuiteModules/Extension/modules/AOW_Actions',
'to' => 'custom/Extension/modules/AOW_Actions',
],
[
'from' => '<basepath>/SuiteModules/modules/seven',
'to' => 'modules/seven',
Expand Down

0 comments on commit 6b357af

Please sign in to comment.