Skip to content

Commit

Permalink
Merge pull request #29 from nguyenanhung/v3.x
Browse files Browse the repository at this point in the history
V3.x
  • Loading branch information
nguyenanhung authored Mar 15, 2023
2 parents cc89e77 + 8ecbcd0 commit f7efbbb
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

- [x] Send Message with Simple Card

## Google Chat

- [x] SendMessage via SpaceID

### Contact

| STT | Name | Email | Skype |
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"nguyenanhung/mantis-connector": "^2.0",
"nguyenanhung/slack": "^2.0",
"nguyenanhung/telegram-messenger": "^2.0",
"nguyenanhung/google-chat-notifier": "^2.0",
"nguyenanhung/microsoft-teams-connector": "^2.0"
},
"require-dev": {
Expand Down
18 changes: 18 additions & 0 deletions helpers/system_notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ function system_notification_to_telegram(array $sdkConfig = array(), string $mod
return nguyenanhung\Monitor\SystemNotification::telegram($sdkConfig, $module, $message, $roomId);
}
}
if (!function_exists('system_notification_to_google_chat')) {
/**
* Hàm gửi thông báo, cảnh báo hệ thống bằng Google Chat
*
* @param array $sdkConfig Cấu hình SDK
* @param string $module Tên Module cần báo lỗi / cảnh báo
* @param string $message Nội dung cảnh báo / Lỗi
* @param null|string|int $spaceId ID của phòng chat / người nhận
*
* @author : 713uk13m <dev@nguyenanhung.com>
* @copyright: 713uk13m <dev@nguyenanhung.com>
* @time : 2/12/20 04:37
*/
function system_notification_to_google_chat(array $sdkConfig = array(), string $module = '', string $message = '', $spaceId = null): bool
{
return nguyenanhung\Monitor\SystemNotification::google_chat($sdkConfig, $module, $message, $spaceId);
}
}
if (!function_exists('system_notification_to_teams')) {
/**
* Hàm gửi thông báo, cảnh báo hệ thống bằng Microsoft Teams
Expand Down
4 changes: 2 additions & 2 deletions src/ProjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
interface ProjectInterface
{
const VERSION = '3.0.6';
const LAST_MODIFIED = '2022-03-08';
const VERSION = '3.0.7';
const LAST_MODIFIED = '2022-03-15';
const AUTHOR_NAME = 'Hung Nguyen';
const AUTHOR_EMAIL = 'dev@nguyenanhung.com';
const PROJECT_NAME = 'Monitor Connector';
Expand Down
49 changes: 49 additions & 0 deletions src/SystemNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use nguyenanhung\Microsoft\Teams\MicrosoftTeamsConnector;
use nguyenanhung\Monitor\Slack\SlackMessenger;
use nguyenanhung\Monitor\Telegram\TelegramMessenger;
use nguyenanhung\Platform\Notification\GoogleChat\Notifier;

/**
* Class SystemNotification
Expand Down Expand Up @@ -159,6 +160,54 @@ public static function telegram(array $sdkConfig = array(), string $module = '',
return false;
}

/**
* Hàm gửi thông báo, cảnh báo hệ thống bằng Google Chat
*
* @param array $sdkConfig Cấu hình SDK
* @param string $module Tên Module cần báo lỗi / cảnh báo
* @param string $message Nội dung cảnh báo / Lỗi
* @param null|string|int $spaceId ID của phòng chat / người nhận
*
* @return bool
* @author : 713uk13m <dev@nguyenanhung.com>
* @copyright: 713uk13m <dev@nguyenanhung.com>
* @time : 10/10/19 08:52
*/
public static function google_chat(array $sdkConfig = array(), string $module = '', string $message = '', $spaceId = null): bool
{
$config_key = 'google_chat';
try {
$config = $sdkConfig[$config_key];
if (isset($sdkConfig[$config_key]) && !empty($sdkConfig[$config_key])) {
$title = isset($sdkConfig['SERVICES']['monitorProjectName']) ? '[' . $sdkConfig['SERVICES']['monitorProjectName'] . '] - ' : '';
$message = $title . $module . ' -> ' . $message;
if (!empty($spaceId)) {
$chatId = $spaceId;
} elseif (isset($config['default_space_id'])) {
$chatId = $config['default_space_id'];
} else {
$chatId = null;
}
$access_key = $config['access_key'] ?? null;
$access_token = $config['access_token'] ?? null;
$handle = new Notifier();
$handle->setSpaceId($chatId)
->setKey($access_key)
->setToken($access_token)
->setMessage($message);

return $handle->send();
}
} catch (Exception $e) {
if (function_exists('log_message')) {
log_message('error', 'Error Message: ' . $e->getMessage());
log_message('error', 'Error Trace As String: ' . $e->getTraceAsString());
}
}

return false;
}

/**
* Hàm gửi thông báo, cảnh báo hệ thống bằng Microsoft Teams
*
Expand Down

0 comments on commit f7efbbb

Please sign in to comment.