-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from LinkNacional/dev
3.2.1 - implementation of internationalization
- Loading branch information
Showing
66 changed files
with
3,195 additions
and
1,492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
105 changes: 105 additions & 0 deletions
105
...cation/src/Notifications/Chatwoot/WhatsAppPrivateNote/WhatsAppPrivateNoteNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/** | ||
* Code: WhatsAppPrivateNote | ||
*/ | ||
|
||
namespace Lkn\HookNotification\Notifications\Chatwoot\WhatsAppPrivateNote; | ||
|
||
use Exception; | ||
use Lkn\HookNotification\Config\Platforms; | ||
use Lkn\HookNotification\Config\ReportCategory; | ||
use Lkn\HookNotification\Config\Settings; | ||
use Lkn\HookNotification\Domains\Platforms\Chatwoot\AbstractChatwootNotification; | ||
use Lkn\HookNotification\Helpers\Config; | ||
use Lkn\HookNotification\Helpers\Lang; | ||
use Lkn\HookNotification\Helpers\WhmcsApi; | ||
|
||
final class WhatsAppPrivateNoteNotification extends AbstractChatwootNotification | ||
{ | ||
public string $notificationCode = 'WhatsAppPrivateNote'; | ||
public ?string $channel = 'wp'; | ||
|
||
/** | ||
* For this notification to work properly, the hook params passed must be: | ||
* | ||
* [ instance => AbstractWhatsAppNotifcation|AbstractChatwootNotification ] | ||
* | ||
* @since 1.0.0 | ||
* @var array | ||
*/ | ||
public array $hookParams; | ||
|
||
public function run(): bool | ||
{ | ||
return $this->sendMessage(); | ||
} | ||
|
||
public function sendMessage(): array|bool | ||
{ | ||
/** | ||
* @var \Lkn\HookNotification\Domains\Platforms\WhatsApp\AbstractWhatsAppNotifcation|\Lkn\HookNotification\Domains\Platforms\Chatwoot\AbstractChatwootNotification | ||
*/ | ||
$notificationInstance = $this->hookParams['instance']; | ||
|
||
/** | ||
* @var \Lkn\HookNotification\Config\ReportCategory | ||
*/ | ||
$reportCategory = $notificationInstance->reportCategory; | ||
$reportCategoryId = $notificationInstance->reportCategoryId; | ||
|
||
$this->setReportCategory($reportCategory); | ||
$this->setReportCategoryId($reportCategoryId); | ||
|
||
$clientId = $notificationInstance->clientId; | ||
$searchBy = $this->getClientWhatsAppNumber($clientId); | ||
|
||
$this->setClientId($clientId); | ||
|
||
$whatsAppInboxId = Config::get(Platforms::CHATWOOT, Settings::CW_WHATSAPP_INBOX_ID); | ||
|
||
if ($whatsAppInboxId === null) { | ||
throw new Exception('WhatsApp inbox ID setting is empty.'); | ||
} | ||
|
||
$categoryUrl = $this->getUrlPathForObject( | ||
$reportCategory, | ||
$reportCategoryId, | ||
$clientId | ||
); | ||
|
||
$msg = Lang::text('notification') . ": {$notificationInstance->lang['notification_title']} [#{$reportCategoryId}]({$categoryUrl})"; | ||
|
||
$response = $this->api->sendMessageToClient( | ||
$clientId, | ||
$whatsAppInboxId, | ||
$searchBy, | ||
$msg, | ||
true | ||
); | ||
|
||
$success = $response['success']; | ||
|
||
$this->report($success); | ||
|
||
return $success; | ||
} | ||
|
||
private function getUrlPathForObject( | ||
ReportCategory $object, | ||
string $objectId, | ||
int $clientId | ||
) { | ||
$objectUrlPath = match ($object) { | ||
ReportCategory::TICKET => 'supporttickets.php?action=view&id=:objectId', | ||
ReportCategory::SERVICE => 'clientsservices.php?userid=:clientId&id=:objectId', | ||
ReportCategory::INVOICE => 'invoices.php?action=edit&id=:objectId', | ||
ReportCategory::ORDER => 'orders.php?action=view&id=:objectId', | ||
ReportCategory::DOMAIN => 'clientsdomains.php?userid=:clientId&id=:objectId' | ||
}; | ||
|
||
$objectUrlPath = str_replace(':objectId', $objectId, $objectUrlPath); | ||
$objectUrlPath = str_replace(':clientId', $clientId, $objectUrlPath); | ||
|
||
return WhmcsApi::getAdminRootUrl($objectUrlPath); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ddons/lknhooknotification/src/Notifications/Chatwoot/WhatsAppPrivateNote/lang/english.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
$lang['notification_title'] = 'WhatsApp private note'; | ||
$lang['notification_description'] = 'This is used by other notifications for sending a private note to a client.'; | ||
|
||
return $lang; |
6 changes: 6 additions & 0 deletions
6
...lknhooknotification/src/Notifications/Chatwoot/WhatsAppPrivateNote/lang/portuguese-br.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
$lang['notification_title'] = 'Nota privada do WhatsApp'; | ||
$lang['notification_description'] = 'É usada por outras notificações para enviar uma nota privada a um cliente.'; | ||
|
||
return $lang; |
6 changes: 6 additions & 0 deletions
6
...lknhooknotification/src/Notifications/Chatwoot/WhatsAppPrivateNote/lang/portuguese-pt.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
$lang['notification_title'] = 'Nota privada do WhatsApp'; | ||
$lang['notification_description'] = 'É usada por outras notificações para enviar uma nota privada a um cliente.'; | ||
|
||
return $lang; |
32 changes: 15 additions & 17 deletions
32
...fication/src/Notifications/WhatsApp/AfterModuleSuspend/AfterModuleSuspendNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...addons/lknhooknotification/src/Notifications/WhatsApp/AfterModuleSuspend/lang/english.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
$lang['notification_title'] = 'Suspended service'; | ||
$lang['notification_description'] = 'Runs when a client service is suspended.'; | ||
|
||
// Parameters labels | ||
|
||
$lang['service_id'] = 'Service ID'; | ||
$lang['client_first_name'] = 'Client first name'; | ||
$lang['client_full_name'] = 'Client full name'; | ||
|
||
return $lang; |
12 changes: 12 additions & 0 deletions
12
.../lknhooknotification/src/Notifications/WhatsApp/AfterModuleSuspend/lang/portuguese-br.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
$lang['notification_title'] = 'Serviço suspenso'; | ||
$lang['notification_description'] = 'Executada quando o serviço de um cliente é suspenso.'; | ||
|
||
// Nomes dos parâmetros | ||
|
||
$lang['service_id'] = 'ID do serviço'; | ||
$lang['client_first_name'] = 'Primeiro nome do cliente'; | ||
$lang['client_full_name'] = 'Nome completo do cliente'; | ||
|
||
return $lang; |
12 changes: 12 additions & 0 deletions
12
.../lknhooknotification/src/Notifications/WhatsApp/AfterModuleSuspend/lang/portuguese-pt.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
$lang['notification_title'] = 'Serviço suspenso'; | ||
$lang['notification_description'] = 'Executada quando o serviço de um cliente é suspenso.'; | ||
|
||
// Nomes dos parâmetros | ||
|
||
$lang['service_id'] = 'ID do serviço'; | ||
$lang['client_first_name'] = 'Primeiro nome do cliente'; | ||
$lang['client_full_name'] = 'Nome completo do cliente'; | ||
|
||
return $lang; |
114 changes: 114 additions & 0 deletions
114
.../Notifications/WhatsApp/DomainRenewal5DaysBefore/DomainRenewal5DaysBeforeNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/** | ||
* Code: DomainRenewal5DaysBefore | ||
*/ | ||
|
||
namespace Lkn\HookNotification\Notifications\WhatsApp\DomainRenewal5DaysBefore; | ||
|
||
use DateTime; | ||
use Lkn\HookNotification\Config\Hooks; | ||
use Lkn\HookNotification\Config\Platforms; | ||
use Lkn\HookNotification\Config\ReportCategory; | ||
use Lkn\HookNotification\Config\Settings; | ||
use Lkn\HookNotification\Domains\Platforms\WhatsApp\AbstractWhatsAppNotifcation; | ||
use Lkn\HookNotification\Helpers\Config; | ||
use Lkn\HookNotification\Helpers\Logger; | ||
use Lkn\HookNotification\Notifications\Chatwoot\WhatsAppPrivateNote\WhatsAppPrivateNoteNotification; | ||
use Throwable; | ||
use WHMCS\Database\Capsule; | ||
|
||
final class DomainRenewal5DaysBeforeNotification extends AbstractWhatsAppNotifcation | ||
{ | ||
public string $notificationCode = 'DomainRenewal5DaysBefore'; | ||
public Hooks|array|null $hook = Hooks::DAILY_CRON_JOB; | ||
|
||
public function run(): bool | ||
{ | ||
// Disable the event of sending a private note to Chatwoot, which is by default for registered clients. | ||
$this->events = []; | ||
$this->enableAutoReport = false; | ||
|
||
// Setup properties for reporting purposes (not required). | ||
$this->setReportCategory(ReportCategory::DOMAIN); | ||
|
||
$threeDaysLater = (new DateTime())->modify('+3 days'); | ||
|
||
$domainsDueInThreeDays = Capsule::table('tbldomains') | ||
->where('nextduedate', $threeDaysLater->format('Y-m-d')) | ||
->get(['id', 'userid', 'domain']) | ||
->toArray(); | ||
|
||
foreach ($domainsDueInThreeDays as $domain) { | ||
$domainId = $domain->id; | ||
$clientId = $domain->userid; | ||
$domainUrl = $domain->domain; | ||
|
||
$this->setReportCategoryId($domainId); | ||
|
||
// Setup client ID for getting its WhatsApp number (required). | ||
$this->setClientId($clientId); | ||
|
||
$this->setHookParams([ | ||
'domain_id' => $domainId, | ||
'domain_url' => $domainUrl, | ||
'client_id' => $clientId | ||
]); | ||
|
||
try { | ||
// Send the message and get the raw response (converted to array) from WhatsApp API. | ||
$response = $this->sendMessage(); | ||
|
||
// Defines if response tells if the message was sent successfully. | ||
$success = isset($response['messages'][0]['id']); | ||
|
||
$this->report($success); | ||
|
||
if ( | ||
$success | ||
&& class_exists('Lkn\HookNotification\Notifications\Chatwoot\WhatsAppPrivateNote\WhatsAppPrivateNoteNotification') | ||
&& Config::get(Platforms::CHATWOOT, Settings::CW_LISTEN_WHATSAPP) | ||
) { | ||
(new WhatsAppPrivateNoteNotification(['instance' => $this]))->run(); | ||
} | ||
} catch (Throwable $th) { | ||
$this->report(false); | ||
|
||
Logger::log( | ||
"{$this->getNotificationLogName()} error for domain {$domainId}", | ||
[ | ||
'msg' => 'Unable to send notification for this domain.', | ||
'context' => ['order' => $domain] | ||
], | ||
[ | ||
'response' => $response, | ||
'error' => $th->__toString() | ||
] | ||
); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function defineParameters(): void | ||
{ | ||
$this->parameters = [ | ||
'domain_id' => [ | ||
'label' => $this->lang['domain_id'], | ||
'parser' => fn () => $this->hookParams['domain_id'] | ||
], | ||
'domain_url' => [ | ||
'label' => $this->lang['domain_url'], | ||
'parser' => fn () => $this->hookParams['domain_url'] | ||
], | ||
'client_first_name' => [ | ||
'label' => $this->lang['client_first_name'], | ||
'parser' => fn () => $this->getClientFirstNameByClientId($this->clientId), | ||
], | ||
'client_full_name' => [ | ||
'label' => $this->lang['client_full_name'], | ||
'parser' => fn () => $this->getClientFullNameByClientId($this->clientId), | ||
] | ||
]; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
.../addons/lknhooknotification/src/Notifications/WhatsApp/DomainRenewal5DaysBefore/hooks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
use Lkn\HookNotification\Domains\Notifications\Messenger; | ||
use Lkn\HookNotification\Notifications\WhatsApp\DomainRenewal5DaysBefore\DomainRenewal5DaysBeforeNotification; | ||
|
||
Messenger::run(DomainRenewal5DaysBeforeNotification::class); |
Oops, something went wrong.