Skip to content

Commit

Permalink
4.48v
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Sep 20, 2024
1 parent 56d60b8 commit 2537a57
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<li role="presentation" class="nav-item"><a class="nav-link" href="#outputrest-rest-{{$index}}" aria-controls="headers" role="tab" data-bs-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Output parsing');?></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" href="#conditions-rest-{{$index}}" aria-controls="headers" role="tab" data-bs-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Conditions');?></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" href="#remote-msg-{{$index}}" aria-controls="headers" role="tab" data-bs-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Remote Message ID');?></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" href="#polling-{{$index}}" aria-controls="headers" role="tab" data-bs-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Polling');?></a></li>
</ul>

<!-- Tab panes -->
Expand Down Expand Up @@ -426,6 +427,9 @@
<input type="text" class="form-control form-control-sm" ng-model="paramOutput.success_location_meta" placeholder="response:msg">
</div>

<h6><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Preg replace rules to apply extracted content.')?></h6>
<textarea ng-model="paramOutput.success_preg_replace" class="form-control form-control-sm" placeholder="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','You can apply preg replace rules to extracted content. One rule per row. Format example: ^.{5,}+$==>Replace with content')?>"></textarea>

<h6><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Custom event')?></h6>

<div class="input-group input-group-sm">
Expand Down Expand Up @@ -468,7 +472,9 @@
<input type="text" class="form-control form-control-sm" ng-model="paramOutput.success_compare_value" placeholder="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Value to compare')?>">
</div>
</div>
</div>

<div class="row">
<div class="col-4">
<div class="form-group">
<label>2. <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','If required you can also have condition to check')?>. <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Response Location. It will also fail if attribute is not found.')?></label>
Expand Down Expand Up @@ -497,7 +503,6 @@
<input type="text" class="form-control form-control-sm" ng-model="paramOutput.success_compare_value_2" placeholder="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','Value to compare')?>">
</div>
</div>

</div>
</div>

Expand All @@ -506,6 +511,20 @@
<p><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('genericbot/restapi','If you want to add custom data within each send message to its meta_data attribute you can provide response path here')?></p>
<input type="text" class="form-control form-control-sm" ng-model="param.remote_message_id" placeholder="messages:0:id" value="" />
</div>

<div role="tabpanel" class="tab-pane" id="polling-{{$index}}">
<div class="row">
<div class="col-6">
<label>Repeat request n times if conditions is not met (polling)</label>
<input type="number" class="form-control form-control-sm" ng-model="param.polling_n_times" placeholder="0" min="0" max="10" />
</div>
<div class="col-6">
<label>Making n seconds delay between each request</label>
<input type="number" class="form-control form-control-sm" ng-model="param.polling_n_delay" placeholder="1" min="1" max="5" />
</div>
</div>
</div>

</div>
</div>

Expand Down
12 changes: 12 additions & 0 deletions lhc_web/doc/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
4.48v

1. Mobile notifications will work now for Mobile App. Although correct windows may not open.
2. Chat GPT Flow support In Rest API section. Polling support.
3. Survey page will show only collected items for departments agent is assigned to.
4. Replaceable variables will be supported also in proactive chat invitations.
5. Message edit action support for web UI if visitor edit's it's message.

execute doc/update_db/update_318.sql for update

4.47v

1. Blinking title fixes with one page applications.
Expand All @@ -7,6 +17,8 @@
5. Statistic chart will not include 17 as default work hour.
6. SSO extension compatibility

execute doc/update_db/update_317.sql for update

4.46v

1. More options to parse incoming request for incoming webhooks
Expand Down
4 changes: 2 additions & 2 deletions lhc_web/doc/update_db/structure.json
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@
},
{
"field": "last_error",
"type": "varchar(255)",
"type": "text",
"null": "NO",
"key": "",
"default": null,
Expand Down Expand Up @@ -11999,7 +11999,7 @@
"lh_departament_limit_group_member": "CREATE TABLE `lh_departament_limit_group_member` ( `id` int(11) NOT NULL AUTO_INCREMENT, `dep_id` int(11) NOT NULL, `dep_limit_group_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `dep_limit_group_id` (`dep_limit_group_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
"lh_departament_group": "CREATE TABLE `lh_departament_group` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
"lh_departament_limit_group": "CREATE TABLE `lh_departament_limit_group` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL,`pending_max` int(11) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
"lh_users_session": "CREATE TABLE `lh_users_session` (`id` int(11) NOT NULL AUTO_INCREMENT,`token` varchar(40) NOT NULL,`device_type` int(11) NOT NULL,`device_token` varchar(255) NOT NULL,`user_id` int(11) NOT NULL, `created_on` int(11) NOT NULL,`updated_on` int(11) NOT NULL, `expires_on` int(11) NOT NULL,PRIMARY KEY (`id`),KEY `device_token_device_type_v2` (`device_token`(191),`device_type`),KEY `token` (`token`)) ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lh_users_session": "CREATE TABLE `lh_users_session` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `token` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,\n `device_type` int(11) NOT NULL,\n `device_token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,\n `user_id` int(11) NOT NULL,\n `created_on` int(11) NOT NULL,\n `updated_on` int(11) NOT NULL,\n `expires_on` int(11) NOT NULL,\n `notifications_status` int(11) NOT NULL DEFAULT 1,\n `error` int(11) NOT NULL DEFAULT 0,\n `last_error` text COLLATE utf8mb4_unicode_ci NOT NULL,\n PRIMARY KEY (`id`),\n KEY `token` (`token`),\n KEY `device_token_device_type_v2` (`device_token`(191),`device_type`),\n KEY `error` (`error`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lh_canned_msg_tag_link": "CREATE TABLE `lh_canned_msg_tag_link` ( `id` int(11) NOT NULL AUTO_INCREMENT, `tag_id` int(11) NOT NULL, `canned_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `canned_id` (`canned_id`), KEY `tag_id` (`tag_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
"lh_canned_msg_tag": "CREATE TABLE `lh_canned_msg_tag` ( `id` int(11) NOT NULL AUTO_INCREMENT, `tag` varchar(40) NOT NULL, PRIMARY KEY (`id`), KEY `tag` (`tag`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
"lh_group_work": "CREATE TABLE `lh_group_work` ( `id` int(11) NOT NULL AUTO_INCREMENT, `group_id` int(11) NOT NULL, `group_work_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `group_id` (`group_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
Expand Down
1 change: 1 addition & 0 deletions lhc_web/doc/update_db/update_318.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `lh_users_session` CHANGE `last_error` `last_error` text NOT NULL;
4 changes: 2 additions & 2 deletions lhc_web/lib/core/lhcore/lhupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class erLhcoreClassUpdate
{

const DB_VERSION = 317;
const LHC_RELEASE = 447;
const DB_VERSION = 318;
const LHC_RELEASE = 448;

public static function doTablesUpdate($definition){
$updateInformation = self::getTablesStatus($definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,21 @@ public static function process($chat, $action, $trigger, $params)
'method' => & $method
));

$response = self::makeRequest($restAPI->configuration_array['host'], $method, array('rest_api' => $restAPI, 'action' => $action, 'rest_api_method_params' => $action['content']['rest_api_method_params'], 'chat' => $chat, 'params' => $params));
if (
isset($method['polling_n_times']) && (int)$method['polling_n_times'] >= 1 && $method['polling_n_times'] <= 10 &&
isset($method['polling_n_delay']) && (int)$method['polling_n_delay'] >= 1 && $method['polling_n_delay'] <= 10
) {
for ($i = 0; $i < (int)$method['polling_n_times']; $i++) {
sleep($method['polling_n_delay']);
$response = self::makeRequest($restAPI->configuration_array['host'], $method, array('rest_api' => $restAPI, 'action' => $action, 'rest_api_method_params' => $action['content']['rest_api_method_params'], 'chat' => $chat, 'params' => $params));
// Request succeeded we can exit a loop
if (isset($response['conditions_met']) && $response['conditions_met'] == true) {
break;
}
}
} else {
$response = self::makeRequest($restAPI->configuration_array['host'], $method, array('rest_api' => $restAPI, 'action' => $action, 'rest_api_method_params' => $action['content']['rest_api_method_params'], 'chat' => $chat, 'params' => $params));
}

erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.rest_api_after_request', array(
'restapi' => & $restAPI,
Expand Down Expand Up @@ -127,6 +141,8 @@ public static function process($chat, $action, $trigger, $params)
}
}



// We have found exact matching response type
// Let's check has user checked any trigger to execute.
if (isset($response['id'])) {
Expand Down Expand Up @@ -1252,8 +1268,19 @@ public static function makeRequest($host, $methodSettings, $paramsCustomer)
'content_5' => (isset($responseValueSub[5]) ? $responseValueSub[5] : ''),
'content_6' => (isset($responseValueSub[6]) ? $responseValueSub[6] : ''),
'meta' => $meta,
'conditions_met' => true,
'id' => $outputCombination['id']);

if (isset($outputCombination['success_preg_replace']) && $outputCombination['success_preg_replace'] != '') {
$replaceRules = explode("\n", $outputCombination['success_preg_replace']);
foreach ($replaceRules as $replaceRule) {
$replaceRuleOptions = explode('==>',$replaceRule);
for ($i = 1; $i <= 6; $i++) {
$responseFormatted['content' . ($i > 1 ? '_' . $i : '')] = preg_replace('/'.$replaceRuleOptions[0].'/is',(isset($replaceRuleOptions[1]) ? $replaceRuleOptions[1] : ''), $responseFormatted['content' . ($i > 1 ? '_' . $i : '')]);
}
}
}

if (isset($outputCombination['method_name']) && !empty(trim($outputCombination['method_name']))) {
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.genericbot_rest_api_method.' . trim($outputCombination['method_name']),
array( 'method_settings' => $methodSettings,
Expand All @@ -1276,6 +1303,7 @@ public static function makeRequest($host, $methodSettings, $paramsCustomer)
'http_code' => $httpcode,
'http_error' => $http_error,
'http_data' => $http_data,
'conditions_met' => false,
'content_2' => '',
'content_3' => '',
'content_4' => '',
Expand All @@ -1291,6 +1319,7 @@ public static function makeRequest($host, $methodSettings, $paramsCustomer)
'http_code' => $httpcode,
'http_error' => $http_error,
'http_data' => $http_data,
'conditions_met' => false,
'content_2' => '',
'content_3' => '',
'content_4' => '',
Expand Down
101 changes: 60 additions & 41 deletions lhc_web/lib/core/lhmobile/lhmobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,29 +442,45 @@ public static function sendAndoid(erLhcoreClassModelUserSession $session, $chat,
throw new Exception('FCM Key is not set');
}

// API access key from Google API's Console
$registrationIds = array( $session->device_token );
$accessToken = explode('__',$options['fcm_key']);

if (count($accessToken) != 2 || (int)$accessToken[1] < time() + 60) {
$newAccessToken = json_decode(erLhcoreClassModelChatOnlineUser::executeRequest('https://mobiletoken.livehelperchat.com/', [], ['timeout' => 7, 'connect_timeout' => 7]),true);
if (isset($newAccessToken['accessToken']) && isset($newAccessToken['exp'])) {
$accessToken[0] = $newAccessToken['accessToken'];
$mbOptions = erLhcoreClassModelChatConfig::fetch('mobile_options');
$options['fcm_key'] = $newAccessToken['accessToken'] . '__' . $newAccessToken['exp'];
$mbOptions->explain = '';
$mbOptions->type = 0;
$mbOptions->hidden = 1;
$mbOptions->identifier = 'mobile_options';
$mbOptions->value = serialize($options);
$mbOptions->saveThis();
} else {
erLhcoreClassLog::write('Fetching AccessToken failed. Make sure you server can connect to https://mobiletoken.livehelperchat.com/');
return false;
}
}

// API access key from Google API's Console
$chatSimplified = $chat->getState();

$fields = array
(
'registration_ids' => $registrationIds,
'notification'=>array(
"title" => $params['title'],
"sound" => "default",
"body" => isset($params['msg']) ? preg_replace('#\[[^\]]+\]#', '',strip_tags($params['msg'])) : preg_replace('#\[[^\]]+\]#', '', erLhcoreClassChat::getGetLastChatMessagePending($chat->id))
),
'data' => array(
"click_action"=> "FLUTTER_NOTIFICATION_CLICK",
"server_id" => $session->token,
"m" => $params['title'],
"chat_type" => $params['chat_type'],
"msg" => isset($params['msg']) ? preg_replace('#\[[^\]]+\]#', '',strip_tags($params['msg'])) : preg_replace('#\[[^\]]+\]#', '', erLhcoreClassChat::getGetLastChatMessagePending($chat->id)),
"chat" => json_encode($chatSimplified)
),
"priority" => "high"
);
$fields = ["message" => [
'token' => $session->device_token,
'notification' => array(
"title" => $params['title'],
"body" => isset($params['msg']) ? preg_replace('#\[[^\]]+\]#', '',strip_tags($params['msg'])) : preg_replace('#\[[^\]]+\]#', '', erLhcoreClassChat::getGetLastChatMessagePending($chat->id))
),
'data' => array(
"click_action"=> "FLUTTER_NOTIFICATION_CLICK",
"server_id" => $session->token,
"m" => $params['title'],
"chat_type" => $params['chat_type'],
"msg" => isset($params['msg']) ? preg_replace('#\[[^\]]+\]#', '',strip_tags($params['msg'])) : preg_replace('#\[[^\]]+\]#', '', erLhcoreClassChat::getGetLastChatMessagePending($chat->id)),
"chat" => json_encode($chatSimplified)
)
]
];

$channelName = '';

Expand All @@ -479,42 +495,45 @@ public static function sendAndoid(erLhcoreClassModelUserSession $session, $chat,
}

if ($channelName != '') {
$fields['android'] = [
$fields['message']['android'] = [
'notification' => [
"channel_id" => $channelName,
"android_channel_id" => $channelName
"click_action" => "FLUTTER_NOTIFICATION_CLICK",
"channel_id" => $channelName
]
];
$fields['notification']['channel_id'] = $channelName;
$fields['notification']['android_channel_id'] = $channelName;
$fields['message']['apns']['payload']['aps']['category'] = 'FLUTTER_NOTIFICATION_CLICK';
}


$headers = array
(
'Authorization: key=' . $options['fcm_key'],
'Authorization: Bearer ' . $accessToken[0],
'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
curl_setopt($ch,CURLOPT_URL, 'https://fcm.googleapis.com/v1/projects/livehelperchat-85489/messages:send' );
curl_setopt($ch,CURLOPT_POST, true );
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
curl_setopt($ch,CURLOPT_TIMEOUT, 10);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_USERAGENT, 'curl/7.29.0');

$result = curl_exec($ch );
curl_close( $ch );

$data = json_decode($result,true);
if ($data['failure'] == 1) {
foreach ($data['results'] as $item) {
if (isset($item['error']) && ($item['error'] == 'NotRegistered' || $item['error'] == 'InvalidRegistration')) {
$session->error = 1;
$session->last_error = json_encode($data['results']);
$session->updateThis();
}
}
if (isset($data['error']) && $data['error']['status'] == 'NOT_FOUND') {
$session->error = 1;
$session->last_error = json_encode($data);
$session->updateThis();
} elseif (isset($data['error'])) {
$session->last_error = json_encode($data);
$session->updateThis();
}

return $data;
Expand Down
Loading

0 comments on commit 2537a57

Please sign in to comment.