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

Commit 6b357af

Browse files
committed
add workflow action sevenSms
1 parent 7cead7a commit 6b357af

File tree

7 files changed

+131
-5
lines changed

7 files changed

+131
-5
lines changed

.idea/dataSources.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Only tested with SuiteCRM 7.x, but it should work well with 6.x too.
2323

2424
### Placeholders
2525

26-
You can use the following placeholders in your messages:
26+
You can use the following placeholders in your messages (not workflows):
2727

2828
#### Contact / Lead
2929

@@ -85,6 +85,15 @@ You can use the following placeholders in your messages:
8585
- {ticker_symbol}
8686
- {website}
8787

88+
### Workflows
89+
You can use the workflow action *sevenSms* to send SMS.
90+
The action works with the following modules:
91+
- Accounts
92+
- Contacts
93+
- Employees
94+
- Leads
95+
- Users
96+
8897
## Support
8998

9099
Need help? Feel free to [contact us](https://www.seven.io/en/company/contact/).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$aow_actions_list[] = 'SevenSms';
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php /** @noinspection PhpUnused */
2+
3+
require_once __DIR__ . '/../../../../modules/AOW_Actions/actions/actionBase.php';
4+
5+
class actionSevenSms extends actionBase {
6+
public function __construct($id = '') {
7+
parent::__construct($id);
8+
}
9+
10+
public function loadJS() {
11+
return [];
12+
}
13+
14+
public function edit_display($line, SugarBean $bean = null, $params = []) {
15+
return "<input maxlength='16' name='aow_actions_param[" . $line . "][from]' placeholder='"
16+
. translate('LBL_SEVENSMS_FROM', 'AOW_Actions') . "' type='tel' value=' " . $params['from']
17+
. "'>"
18+
. "<textarea cols='110' name='aow_actions_param[" . $line . "][text]' placeholder='"
19+
. translate('LBL_SEVENSMS_TEXT', 'AOW_Actions') . "' rows='5'>" . $params['text']
20+
. "</textarea>";
21+
}
22+
23+
protected function getPhoneFromParams(SugarBean $bean, array $params): ?string {
24+
switch ($bean->module_name) {
25+
case 'Accounts':
26+
/** @var Account $bean */
27+
28+
return $bean->phone_alternate;
29+
case 'Contacts':
30+
/** @var Contact $bean */
31+
32+
return $bean->phone_mobile;
33+
case 'Employees':
34+
/** @var Employee $bean */
35+
36+
return $bean->phone_mobile;
37+
case 'Leads':
38+
/** @var Lead $bean */
39+
40+
return $bean->phone_mobile;
41+
case 'Users':
42+
/** @var User $bean */
43+
44+
return $bean->phone_mobile;
45+
default:
46+
return null;
47+
}
48+
}
49+
50+
/**
51+
* Return true on success otherwise false.
52+
* Use actionSevenSms::getLastMessagesSuccess() and actionSevenSms::getLastMessagesFailed()
53+
* methods to get last SMS sending status
54+
* @param SugarBean $bean
55+
* @param array $params
56+
* @param bool $in_save
57+
* @return boolean
58+
*/
59+
public function run_action(SugarBean $bean, $params = [], $in_save = false) {
60+
global $sugar_config;
61+
62+
$to = $this->getPhoneFromParams($bean, $params);
63+
if (!$to) return false;
64+
65+
$apiKey = $sugar_config['seven_api_key'];
66+
if (!$apiKey) return false;
67+
68+
$text = $params['text'];
69+
$from = $params['from'];
70+
71+
$ch = curl_init('https://gateway.seven.io/api/sms');
72+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(compact('from', 'text', 'to')));
73+
curl_setopt($ch, CURLOPT_HTTPHEADER, [
74+
'Accept: application/json',
75+
'Content-type: application/json',
76+
'X-Api-Key: ' . $sugar_config['seven_api_key'],
77+
]);
78+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
79+
$result = curl_exec($ch);
80+
$result = json_decode($result);
81+
curl_close($ch);
82+
83+
return 100 === $result->success;
84+
}
85+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
if (!defined('sugarEntry') || !sugarEntry) {
4+
die('Not A Valid Entry Point');
5+
}
6+
7+
$mod_strings = [
8+
'LBL_SEVENSMS' => 'seven SMS',
9+
'LBL_SEVENSMS_FROM' => 'From',
10+
'LBL_SEVENSMS_TEXT' => 'Text',
11+
];

logo.svg

Lines changed: 4 additions & 2 deletions
Loading

manifest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
'is_uninstallable' => true,
2727
'key' => '',
2828
'name' => 'seven',
29-
'published_date' => 'November 17, 2023',
29+
'published_date' => 'December 05, 2023',
3030
'readme' => '',
3131
'remove_tables' => 'prompt',
3232
'type' => 'module',
33-
'version' => 'v0.4.0',
33+
'version' => 'v0.5.0',
3434
];
3535

3636
$installdefs = [
@@ -69,6 +69,10 @@
6969
'from' => '<basepath>/SuiteModules/Extension/modules/Leads',
7070
'to' => 'custom/Extension/modules/Leads',
7171
],
72+
[
73+
'from' => '<basepath>/SuiteModules/Extension/modules/AOW_Actions',
74+
'to' => 'custom/Extension/modules/AOW_Actions',
75+
],
7276
[
7377
'from' => '<basepath>/SuiteModules/modules/seven',
7478
'to' => 'modules/seven',

0 commit comments

Comments
 (0)