sms ready for test

This commit is contained in:
merdan 2022-01-18 17:15:26 +05:00
parent 76430ea979
commit daa334ef0b
6 changed files with 53 additions and 74 deletions

View File

@ -5,12 +5,13 @@ namespace TPS\Birzha\Actions;
use Backend\Models\UserGroup as AdminGroupModel;
use Illuminate\Support\Facades\Log;
use RainLab\Notify\Classes\ActionBase;
use TPS\Birzha\Classes\SMS;
class SendSMSAction extends ActionBase
{
public $recipientModes = [
'user' => 'User phone number (if applicable)',
'admin' => 'Back-end administrators phones',
// 'admin' => 'Back-end administrators phones',
'custom' => 'Specific phone number',
];
@ -33,6 +34,9 @@ class SendSMSAction extends ActionBase
{
return [
'send_to_mode' => 'required',
'send_to_custom' => 'required_if:send_to_mode,custom',
// 'send_to_admin' => 'required_if:send_to_mode,admin',
'message' => 'required'
];
}
/**
@ -50,14 +54,14 @@ class SendSMSAction extends ActionBase
return $modes;
}
public function getSendToAdminOptions()
{
$options = ['' => '- All administrators -'];
$groups = AdminGroupModel::lists('name', 'id');
return $options + $groups;
}
// public function getSendToAdminOptions()
// {
// $options = ['' => '- All administrators -'];
//
// $groups = AdminGroupModel::lists('name', 'id');
//
// return $options + $groups;
// }
public function getTitle()
{
@ -66,43 +70,7 @@ class SendSMSAction extends ActionBase
}
return 'Send sms to customers';
}
public function getText()
{
$hostObj = $this->host;
$recipient = array_get($this->recipientModes, $hostObj->send_to_mode);
if ($this->isAdminMode()) {
if ($groupId = $this->host->send_to_admin) {
if ($group = AdminGroupModel::find($groupId)) {
$adminText = $group->name;
}
else {
$adminText = '?';
}
$adminText .= ' admin group';
}
else {
$adminText = 'all admins';
}
return sprintf(
'Send a sms to %s',
$adminText,
$hostObj->mail_template
);
}
if ($hostObj->mail_template) {
return sprintf(
'Send smd to %s',
mb_strtolower($recipient),
$hostObj->mail_template
);
}
return parent::getText();
}
public function getActionIcon()
{
return 'icon-envelope-square';
@ -115,10 +83,20 @@ class SendSMSAction extends ActionBase
*/
public function triggerAction($params)
{
Log::info(json_encode($params));
}
protected function isAdminMode()
{
return $this->host->send_to_mode == 'admin';
if($this->host->send_to_mode == 'user' && $params['user']){
$to = $params['user']['username'];
}else{
$to = $this->host->send_to_custom;
}
SMS::send($to,$this->host->message);
// Log::info(json_encode($params));
}
// protected function isAdminMode()
// {
// return $this->host->send_to_mode == 'admin';
// }
}

View File

@ -93,7 +93,7 @@ class VerifyAction extends ActionBase
}
private function sendSMS($phone,$code){
$message = "tmex.gov.tm verification code: {$code}";
$message = "tmex.gov.tm%20verification%20code:%20{$code}";
SMS::send($phone,$message);
}

View File

@ -19,13 +19,16 @@ fields:
action: show
field: send_to_mode
condition: value[custom]
#
# send_to_admin:
# label: Send to admin group
# span: right
# type: dropdown
# trigger:
# action: show
# field: send_to_mode
# condition: value[admin]
send_to_admin:
label: Send to admin group
span: right
type: dropdown
trigger:
action: show
field: send_to_mode
condition: value[admin]
message:
cssClass: radio-align
label: Message

View File

@ -9,10 +9,9 @@ use October\Rain\Support\Facades\Http;
class SMS
{
public static function send($to, $content){
$url = env('SMS_API')."+99363432211/{$content}";
$url = urlencode(env('SMS_API')."$to/{$content}");
try {
$response = Http::get($url);
Log::info($response);
}
catch (Exception $exception){
Log::error($exception);

View File

@ -21,23 +21,23 @@ class MessageReceivedEvent extends \RainLab\Notify\Classes\EventBase
/**
* Defines the usable parameters provided by this class.
*/
public function defineParams()
{
return [
'name' => [
'title' => 'Name',
'label' => 'Name of the user',
],
// ...
];
}
// public function defineParams()
// {
// return [
// 'name' => [
// 'title' => 'Name',
// 'label' => 'Name of the user',
// ],
// // ...
// ];
// }
public static function makeParamsFromEvent(array $args, $eventName = null)
{
return [
'user' => array_get($args, 0),
'message' => array_get($args, 1)
'message' => array_get($args, 1),
];
}
}

View File

@ -23,7 +23,6 @@ class PaymentReviewedEvent extends EventBase
return [
'payment' => array_get($args, 0),
'user' => array_get($args, 1),
'message' => 'sizin balansynyz doldurldy'
];
}