Skip to content

Commit

Permalink
Merge pull request #2071 from LiveHelperChat/master-continous
Browse files Browse the repository at this point in the history
4.34v
  • Loading branch information
remdex committed Mar 20, 2024
2 parents 14211d8 + 20a6bd1 commit 3f9732d
Show file tree
Hide file tree
Showing 20 changed files with 545 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lhc_web/design/defaulttheme/js/svelte/public/build/main.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -1 +1 @@
<li role="presentation" class="nav-item"><a class="nav-link" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('front/default','Active chats');?>" href="#activechats" aria-controls="activechats" role="tab" data-bs-toggle="tab"><i class="material-icons chat-active">chat</i><span>{{active_chats.list.length != false && active_chats.list.length > 0 ? ' ('+active_chats.list.length+')' : ''}}</span></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('front/default','Active chats');?>" href="#activechats" aria-controls="activechats" role="tab" data-bs-toggle="tab"><i class="material-icons chat-active">chat</i><span><lhc-chats-counter type="active_chats"></lhc-chats-counter></span></a></li>
@@ -1 +1 @@
<li role="presentation" class="nav-item"><a class="nav-link" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('front/default','Pending confirm');?>" href="#pendingchats" aria-controls="pendingchats" role="tab" data-bs-toggle="tab"><i class="material-icons chat-pending me-0">chat</i><span>{{pending_chats.list.length != false && pending_chats.list.length > 0 ? ' ('+pending_chats.list.length+')' : ''}}</span></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('front/default','Pending confirm');?>" href="#pendingchats" aria-controls="pendingchats" role="tab" data-bs-toggle="tab"><i class="material-icons chat-pending me-0">chat</i><span><lhc-chats-counter type="pending_chats"></lhc-chats-counter></span></a></li>
@@ -1 +1 @@
<li role="presentation" class="nav-item"><a class="nav-link" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('front/default','Unread messages');?>" href="#unreadchats" aria-controls="unreadchats" role="tab" data-bs-toggle="tab"><i class="material-icons chat-unread me-0">chat</i><span>{{unread_chats.list.length != false && unread_chats.list.length > 0 ? ' ('+unread_chats.list.length+')' : ''}}</span></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('front/default','Unread messages');?>" href="#unreadchats" aria-controls="unreadchats" role="tab" data-bs-toggle="tab"><i class="material-icons chat-unread me-0">chat</i><span><lhc-chats-counter type="unread_chats"></lhc-chats-counter></span></a></li>
Expand Up @@ -27,7 +27,9 @@
<?php if ($item->type == 0) : ?>
<?php echo htmlspecialchars($item->event)?>
<?php elseif ($item->type == 1) : ?>
<b><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('webhooks/module','Continuous event');?></b>
<b><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('webhooks/module','Continuous chat event');?></b>
<?php elseif ($item->type == 2) : ?>
<b><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('webhooks/module','Continuous mail event');?></b>
<?php endif; ?>
</td>
<td><?php echo htmlspecialchars($item->bot)?></td>
Expand Down
22 changes: 22 additions & 0 deletions lhc_web/design/defaulttheme/tpl/lhwebhooks/form.tpl.php
Expand Up @@ -26,6 +26,28 @@
<div class="form-group">
<label><input type="radio" value="2" name="type" <?php if ($item->type == 2) : ?>checked="checked"<?php endif;?> /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','This is continuous mail event');?></label>
<p><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Make sure you define some conditions. Only new, active mails are checked against these conditions.');?></p>

<p><b><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Execute if conditions are NOT valid');?></b> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','are not executed in this event type.');?></p>

<?php if ($item->type == 2 && $item->id > 0) : ?>
<a href="<?php echo erLhcoreClassDesign::baseurl('webhooks/edit')?>/<?php echo $item->id?>/(action)/reset_webhook" class="btn btn-danger btn-sm csfr-required"><span class="material-icons">restart_alt</span><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Reset events. We will process matching messages again.');?></a>
<?php include(erLhcoreClassDesign::designtpl('lhkernel/secure_links.tpl.php')); ?>
<ul>
<li><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Processed events');?> - <?php echo \LiveHelperChat\mailConv\Webhooks\Continous::getProcessedMailEvents($item); ?></li>
<li><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Last 10 messages processed');?>
<li><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Older events than 31 day are deleted automatically');?>
<?php foreach (\LiveHelperChat\mailConv\Webhooks\Continous::getLast10Events($item) as $event) : ?>
<span class="badge bg-info">
<?php $msg = erLhcoreClassModelMailconvMessage::fetch($event['message_id']); if ($msg instanceof erLhcoreClassModelMailconvMessage) : ?>
<a target="_blank" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Message ID followed by conversation ID')?>" href="<?php echo erLhcoreClassDesign::baseurl('mailconv/single')?>/<?php echo $msg->conversation_id?>">
<?php echo $event['message_id']?>, <?php echo $msg->conversation_id?>
</a>
<?php endif;?>
</span>
<?php endforeach; ?>
</li>
</ul>
<?php endif; ?>
</div>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions lhc_web/doc/CHANGELOG.txt
@@ -1,3 +1,13 @@
4.34v

1. Notification for assigned pending chat was missing.
2. Continuous webhooks for mails finished.
3. Check for CSV file encoding during import.
4. Option to filter for agents statistic who were online.
5. Country flag icon always will be the first icon in the widget.

execute doc/update_db/update_305.sql for update

4.33v

1. Delete and Delete and archive options has option to ignore imap delete independently.
Expand Down
13 changes: 12 additions & 1 deletion lhc_web/doc/update_db/structure.json
Expand Up @@ -10,6 +10,16 @@
"extra": "auto_increment"
}
],
"lh_mail_continuous_event": [
{
"field": "message_id",
"type": "bigint(20) unsigned",
"null": "NO",
"key": "PRI",
"default": null,
"extra": ""
}
],
"lh_brand_member": [
{
"field": "id",
Expand Down Expand Up @@ -11907,6 +11917,7 @@
"lh_brand_member" : "CREATE TABLE `lh_brand_member` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `dep_id` bigint(20) unsigned NOT NULL, `brand_id` bigint(20) unsigned NOT NULL, `role` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,\n PRIMARY KEY (`id`),\n KEY `dep_id` (`dep_id`),\n KEY `brand_id_role` (`brand_id`,`role`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lh_bot_condition" : "CREATE TABLE `lh_bot_condition` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `configuration` longtext COLLATE utf8mb4_unicode_ci NOT NULL,\n `name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,\n `identifier` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,\n PRIMARY KEY (`id`),\n KEY `identifier` (`identifier`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lhc_mailconv_delete_item" : "CREATE TABLE `lhc_mailconv_delete_item` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n `conversation_id` bigint(20) unsigned NOT NULL,\n `filter_id` bigint(20) unsigned NOT NULL,\n `status` tinyint(1) unsigned NOT NULL DEFAULT 0,\n PRIMARY KEY (`id`),\n KEY `filter_id_status` (`filter_id`,`status`),\n KEY `status` (`status`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lhc_mailconv_delete_filter" : "CREATE TABLE `lhc_mailconv_delete_filter` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,`delete_policy` tinyint(1) unsigned NOT NULL DEFAULT 0, `processed_records` bigint(20) unsigned NOT NULL DEFAULT 0, `updated_at` bigint(20) unsigned NOT NULL,\n `created_at` bigint(20) unsigned NOT NULL,\n `user_id` bigint(20) unsigned NOT NULL,\n `archive_id` int(11) unsigned NOT NULL DEFAULT 0,\n `status` tinyint(1) unsigned NOT NULL DEFAULT 0,\n `last_id` bigint(20) unsigned NOT NULL DEFAULT 0,\n `started_at` bigint(20) unsigned NOT NULL DEFAULT 0,\n `finished_at` bigint(20) unsigned NOT NULL DEFAULT 0,\n `filter` longtext COLLATE utf8mb4_unicode_ci NOT NULL,\n `filter_input` longtext COLLATE utf8mb4_unicode_ci NOT NULL,\n PRIMARY KEY (`id`),\n KEY `status` (`status`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
"lhc_mailconv_delete_filter" : "CREATE TABLE `lhc_mailconv_delete_filter` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,`delete_policy` tinyint(1) unsigned NOT NULL DEFAULT 0, `processed_records` bigint(20) unsigned NOT NULL DEFAULT 0, `updated_at` bigint(20) unsigned NOT NULL,\n `created_at` bigint(20) unsigned NOT NULL,\n `user_id` bigint(20) unsigned NOT NULL,\n `archive_id` int(11) unsigned NOT NULL DEFAULT 0,\n `status` tinyint(1) unsigned NOT NULL DEFAULT 0,\n `last_id` bigint(20) unsigned NOT NULL DEFAULT 0,\n `started_at` bigint(20) unsigned NOT NULL DEFAULT 0,\n `finished_at` bigint(20) unsigned NOT NULL DEFAULT 0,\n `filter` longtext COLLATE utf8mb4_unicode_ci NOT NULL,\n `filter_input` longtext COLLATE utf8mb4_unicode_ci NOT NULL,\n PRIMARY KEY (`id`),\n KEY `status` (`status`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lh_mail_continuous_event" : "CREATE TABLE `lh_mail_continuous_event` (\n `webhook_id` bigint(20) unsigned NOT NULL,\n `message_id` bigint(20) unsigned NOT NULL,\n `created_at` bigint(20) unsigned NOT NULL,\n UNIQUE KEY `webhook_id_message_id` (`webhook_id`,`message_id`),\n KEY `created_at` (`created_at`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
}
}
7 changes: 7 additions & 0 deletions lhc_web/doc/update_db/update_305.sql
@@ -0,0 +1,7 @@
CREATE TABLE `lh_mail_continuous_event` (
`webhook_id` bigint(20) unsigned NOT NULL,
`message_id` bigint(20) unsigned NOT NULL,
`created_at` bigint(20) unsigned NOT NULL,
UNIQUE KEY `webhook_id_message_id` (`webhook_id`,`message_id`),
KEY `created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2 changes: 1 addition & 1 deletion lhc_web/lib/core/lhchat/lhchatadminvalidatorhelper.php
Expand Up @@ -1445,7 +1445,7 @@ public static function validateWebhook(& $webhook )
ezcInputFormDefinitionElement::OPTIONAL, 'int',array('min_range' => 1)
),
'type' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'int',array('min_range' => 0, 'max_range' => 1)
ezcInputFormDefinitionElement::OPTIONAL, 'int',array('min_range' => 0, 'max_range' => 2)
),
'disabled' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'boolean'
Expand Down
19 changes: 0 additions & 19 deletions lhc_web/lib/core/lhchat/lhchatwebhookcontinous.php
Expand Up @@ -251,25 +251,6 @@ public static function processEvent() {
}
}

public static function processEventMail() {
try {
$continuousHooks = erLhcoreClassModelChatWebhook::getList(array('filter' => array('type' => 2, 'disabled' => 0)));
} catch (Exception $e) {
return;
}

// Continue here
/*$statusValid = array(
erLhcoreClassModelChat::STATUS_PENDING_CHAT,
erLhcoreClassModelChat::STATUS_ACTIVE_CHAT,
erLhcoreClassModelChat::STATUS_BOT_CHAT,
);
$chats = erLhcoreClassModelChat::getList(array(
'limit' => 1000,
'filterin' => array('status' => $statusValid)));*/
}

public static function dispatchEvents($chat, $params)
{
$lastMessageIdNew = $lastMessageId = $params['msg_last_id'];
Expand Down
86 changes: 84 additions & 2 deletions lhc_web/lib/core/lhcore/lhdbtrait.php
Expand Up @@ -401,6 +401,20 @@ public static function getConditions($params, $q)
}
}

if (isset($params['filterfields']) && count($params['filterfields']) > 0) {
foreach ($params['filterfields'] as $combination) {
foreach ($combination as $field => $fieldValue) {
if (is_array($fieldValue)) {
if (!empty($fieldValue)) {
$conditions[] = $q->expr->in($field, $fieldValue);
}
} else {
$conditions[] = $q->expr->eq($field, $q->bindValue($fieldValue));
}
}
}
}

if (isset($params['filterin']) && count($params['filterin']) > 0) {
foreach ($params['filterin'] as $field => $fieldValue) {
if (empty($fieldValue)) {
Expand All @@ -411,27 +425,71 @@ public static function getConditions($params, $q)
}
}

if (isset($params['filterinfields']) && count($params['filterinfields']) > 0) {
foreach ($params['filterinfields'] as $combination) {
foreach ($combination as $field => $fieldValue) {
if (empty($fieldValue)) {
break;
} else {
$conditions[] = $q->expr->in($field, $fieldValue);
}
}
}
}

if (isset($params['filterlt']) && count($params['filterlt']) > 0) {
foreach ($params['filterlt'] as $field => $fieldValue) {
$conditions[] = $q->expr->lt($field, $q->bindValue($fieldValue));
}
}

if (isset($params['filterltfields']) && count($params['filterltfields']) > 0) {
foreach ($params['filterltfields'] as $combination) {
foreach ($combination as $field => $fieldValue){
$conditions[] = $q->expr->lt($field, $q->bindValue($fieldValue));
}
}
}

if (isset($params['filtergt']) && count($params['filtergt']) > 0) {
foreach ($params['filtergt'] as $field => $fieldValue) {
$conditions[] = $q->expr->gt($field, $q->bindValue($fieldValue));
}
}

if (isset($params['filtergtfields']) && count($params['filtergtfields']) > 0) {
foreach ($params['filtergtfields'] as $combination) {
foreach ($combination as $field => $fieldValue) {
$conditions[] = $q->expr->gt($field, $q->bindValue($fieldValue));
}
}
}

if (isset($params['filtergte']) && count($params['filtergte']) > 0) {
foreach ($params['filtergte'] as $field => $fieldValue) {
$conditions[] = $q->expr->gte($field, $fieldValue);
$conditions[] = $q->expr->gte($field, $q->bindValue($fieldValue));
}
}

if (isset($params['filtergtefields']) && count($params['filtergtefields']) > 0) {
foreach ($params['filtergtefields'] as $combination) {
foreach ($combination as $field => $fieldValue) {
$conditions[] = $q->expr->gte($field, $q->bindValue($fieldValue));
}
}
}

if (isset($params['filterlte']) && count($params['filterlte']) > 0) {
foreach ($params['filterlte'] as $field => $fieldValue) {
$conditions[] = $q->expr->lte($field, $fieldValue);
$conditions[] = $q->expr->lte($field, $q->bindValue($fieldValue));
}
}

if (isset($params['filterltefields']) && count($params['filterltefields']) > 0) {
foreach ($params['filterltefields'] as $combination) {
foreach ($combination as $field => $fieldValue) {
$conditions[] = $q->expr->lte($field, $q->bindValue($fieldValue));
}
}
}

Expand All @@ -447,6 +505,14 @@ public static function getConditions($params, $q)
}
}

if (isset($params['filternotfields']) && count($params['filternotfields']) > 0) {
foreach ($params['filternotfields'] as $combination) {
foreach ($combination as $field => $fieldValue) {
$conditions[] = $q->expr->neq($field, $q->bindValue($fieldValue));
}
}
}

if (isset($params['filterall']) && count($params['filterall']) > 0) {
foreach ($params['filterall'] as $field => $fieldValue) {
$conditions[] = $q->expr->allin($field, $fieldValue);
Expand All @@ -459,6 +525,22 @@ public static function getConditions($params, $q)
}
}

if (isset($params['filterlikefields']) && count($params['filterlikefields']) > 0) {
foreach ($params['filterlikefields'] as $combination) {
foreach ($combination as $field => $fieldValue) {
$conditions[] = $q->expr->like($field, $q->bindValue('%' . $fieldValue . '%'));
}
}
}

if (isset($params['filternotlikefields']) && count($params['filternotlikefields']) > 0) {
foreach ($params['filternotlikefields'] as $combination) {
foreach ($combination as $field => $fieldValue) {
$conditions[] = $q->expr->not($q->expr->like($field, $q->bindValue('%' . $fieldValue . '%')));
}
}
}

if (isset($params['filterlikeright']) && count($params['filterlikeright']) > 0) {
foreach ($params['filterlikeright'] as $field => $fieldValue) {
$conditions[] = $q->expr->like($field, $q->bindValue($fieldValue . '%'));
Expand Down

0 comments on commit 3f9732d

Please sign in to comment.