Skip to content

Commit 6746eff

Browse files
committed
✨ Add support for unread-message flow in webhook conditions πŸ“©πŸ””
- Introduced checkboxes for enabling unread-message flow for admin messages in form inputs. - Updated backend logic to handle unread-message conditions for various message types. - Enhanced chat update logic to reflect unread message states for operators. fix #2398
1 parent 7fb1221 commit 6746eff

2 files changed

Lines changed: 77 additions & 4 deletions

File tree

β€Žlhc_web/design/defaulttheme/tpl/lhwebhooks/form_incoming.tpl.phpβ€Ž

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@
316316
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
317317
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_op" value="" />
318318
</div>
319+
<div class="form-group">
320+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_op_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
321+
</div>
319322
</div>
320323

321324
<div role="tabpanel" class="tab-pane form-group" id="text_messages_2">
@@ -331,6 +334,9 @@
331334
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
332335
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_op_2" value="" />
333336
</div>
337+
<div class="form-group">
338+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_op_2_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
339+
</div>
334340
</div>
335341

336342
<div role="tabpanel" class="tab-pane form-group" id="text_messages_3">
@@ -346,6 +352,9 @@
346352
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
347353
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_op_3" value="" />
348354
</div>
355+
<div class="form-group">
356+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_op_3_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
357+
</div>
349358
</div>
350359

351360
<div role="tabpanel" class="tab-pane form-group" id="text_messages_4">
@@ -361,6 +370,9 @@
361370
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
362371
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_op_4" value="" />
363372
</div>
373+
<div class="form-group">
374+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_op_4_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
375+
</div>
364376
</div>
365377

366378
<div role="tabpanel" class="tab-pane form-group" id="attachments">
@@ -438,6 +450,9 @@
438450
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
439451
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_attachments_op" value="" />
440452
</div>
453+
<div class="form-group">
454+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_attachments_op_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
455+
</div>
441456
</div>
442457

443458
<div role="tabpanel" class="tab-pane form-group" id="button_payload_1">
@@ -575,6 +590,9 @@
575590
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
576591
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_img_op" value="" />
577592
</div>
593+
<div class="form-group">
594+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_img_op_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
595+
</div>
578596

579597
</div>
580598

@@ -655,6 +673,9 @@
655673
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
656674
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_img_2_op" value="" />
657675
</div>
676+
<div class="form-group">
677+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_img_2_op_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
678+
</div>
658679

659680
</div>
660681
<div role="tabpanel" class="tab-pane form-group" id="img-attachments_3">
@@ -734,6 +755,9 @@
734755
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
735756
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_img_3_op" value="" />
736757
</div>
758+
<div class="form-group">
759+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_img_3_op_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
760+
</div>
737761

738762
</div>
739763

@@ -814,6 +838,9 @@
814838
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
815839
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_img_4_op" value="" />
816840
</div>
841+
<div class="form-group">
842+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_img_4_op_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
843+
</div>
817844

818845
</div>
819846

@@ -894,6 +921,9 @@
894921
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
895922
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_img_5_op" value="" />
896923
</div>
924+
<div class="form-group">
925+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_img_5_op_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
926+
</div>
897927

898928
</div>
899929

@@ -974,6 +1004,9 @@
9741004
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','For message being considered bot/operator messages should have attribute value equal to');?></label>
9751005
<input type="text" class="form-control form-control-sm" placeholder="message_attribute=value expected||message_attribute=value expected" ng-model="webhookincomingsctl.conditions.msg_cond_img_6_op" value="" />
9761006
</div>
1007+
<div class="form-group">
1008+
<label><input type="checkbox" ng-model="webhookincomingsctl.conditions.msg_cond_img_6_op_unread" value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/webhooks','Enable unread-message flow for admin messages');?></label>
1009+
</div>
9771010

9781011
</div>
9791012

β€Žlhc_web/lib/core/lhchat/lhchatwebhookincomming.phpβ€Ž

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
328328
$typeMessage = 'unknown';
329329
$sender = 0;
330330
$conditionsOperator = '';
331+
$operatorConditionKey = '';
331332

332333
if (isset($conditions['msg_cond_attachments']) && $conditions['msg_cond_attachments'] != "") {
333334
$typeMessage = 'attachments';
@@ -362,6 +363,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
362363
if ($typeMessage == 'attachments') {
363364
$msgBody = $conditions['msg_attachments'];
364365
$conditionsOperator = isset($conditions['msg_cond_attachments_op']) ? $conditions['msg_cond_attachments_op'] : "";
366+
$operatorConditionKey = 'msg_cond_attachments_op';
365367
}
366368
}
367369

@@ -400,6 +402,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
400402
if ($typeMessage == 'img') {
401403
$msgBody = $conditions['msg_img'];
402404
$conditionsOperator = isset($conditions['msg_cond_img_op']) ? $conditions['msg_cond_img_op'] : "";
405+
$operatorConditionKey = 'msg_cond_img_op';
403406
}
404407
}
405408
}
@@ -439,6 +442,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
439442
if ($typeMessage == 'img_2') {
440443
$msgBody = $conditions['msg_img_2'];
441444
$conditionsOperator = isset($conditions['msg_cond_img_2_op']) ? $conditions['msg_cond_img_2_op'] : "";
445+
$operatorConditionKey = 'msg_cond_img_2_op';
442446
}
443447
}
444448
}
@@ -478,6 +482,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
478482
if ($typeMessage == 'img_3') {
479483
$msgBody = $conditions['msg_img_3'];
480484
$conditionsOperator = isset($conditions['msg_cond_img_3_op']) ? $conditions['msg_cond_img_3_op'] : "";
485+
$operatorConditionKey = 'msg_cond_img_3_op';
481486
}
482487
}
483488
}
@@ -517,6 +522,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
517522
if ($typeMessage == 'img_4') {
518523
$msgBody = $conditions['msg_img_4'];
519524
$conditionsOperator = isset($conditions['msg_cond_img_4_op']) ? $conditions['msg_cond_img_4_op'] : "";
525+
$operatorConditionKey = 'msg_cond_img_4_op';
520526
}
521527
}
522528
}
@@ -556,6 +562,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
556562
if ($typeMessage == 'img_5') {
557563
$msgBody = $conditions['msg_img_5'];
558564
$conditionsOperator = isset($conditions['msg_cond_img_5_op']) ? $conditions['msg_cond_img_5_op'] : "";
565+
$operatorConditionKey = 'msg_cond_img_5_op';
559566
}
560567
}
561568
}
@@ -595,6 +602,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
595602
if ($typeMessage == 'img_6') {
596603
$msgBody = $conditions['msg_img_6'];
597604
$conditionsOperator = isset($conditions['msg_cond_img_6_op']) ? $conditions['msg_cond_img_6_op'] : "";
605+
$operatorConditionKey = 'msg_cond_img_6_op';
598606
}
599607
}
600608
}
@@ -636,6 +644,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
636644

637645
if ($typeMessage == 'text') {
638646
$conditionsOperator = isset($conditions['msg_cond_op_2']) ? $conditions['msg_cond_op_2'] : "";
647+
$operatorConditionKey = 'msg_cond_op_2';
639648
}
640649
}
641650
}
@@ -668,6 +677,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
668677

669678
if ($typeMessage == 'text') {
670679
$conditionsOperator = isset($conditions['msg_cond_op_3']) ? $conditions['msg_cond_op_3'] : "";
680+
$operatorConditionKey = 'msg_cond_op_3';
671681
}
672682
}
673683
}
@@ -700,6 +710,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
700710

701711
if ($typeMessage == 'text') {
702712
$conditionsOperator = isset($conditions['msg_cond_op_4']) ? $conditions['msg_cond_op_4'] : "";
713+
$operatorConditionKey = 'msg_cond_op_4';
703714
}
704715
}
705716
}
@@ -931,6 +942,7 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
931942

932943
if ($typeMessage == 'text') {
933944
$conditionsOperator = isset($conditions['msg_cond_op']) ? $conditions['msg_cond_op'] : "";
945+
$operatorConditionKey = 'msg_cond_op';
934946
}
935947
}
936948

@@ -974,6 +986,8 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
974986
}
975987
}
976988

989+
$enableUnreadOpFlow = ($sender == -2 && $operatorConditionKey != '' && isset($conditions[$operatorConditionKey . '_unread']) && $conditions[$operatorConditionKey . '_unread'] == true);
990+
977991
$chatIdSwitch = self::isValidCondition('chat_id_switch', $conditions, $payloadMessage);
978992

979993
$chatIdFirst = $chatIdSwitch === true ? 'chat_id_2' : 'chat_id';
@@ -1480,7 +1494,13 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
14801494
// Store online visitor record so previous chat workflow works
14811495
self::assignOnlineVisitor($chat, $eChat);
14821496

1483-
$chat->updateThis(array('update' => array(
1497+
if ($enableUnreadOpFlow) {
1498+
$chat->has_unread_op_messages = 1;
1499+
$chat->unread_op_messages_informed = 0;
1500+
$chat->last_op_msg_time = time();
1501+
}
1502+
1503+
$chatUpdateFields = array(
14841504
'country_code',
14851505
'country_name',
14861506
'dep_id',
@@ -1503,7 +1523,11 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
15031523
'transfer_timeout_ac',
15041524
'priority',
15051525
'auto_responder_id'
1506-
)));
1526+
);
1527+
if ($enableUnreadOpFlow) {
1528+
$chatUpdateFields = array_merge($chatUpdateFields, ['has_unread_op_messages', 'unread_op_messages_informed', 'last_op_msg_time']);
1529+
}
1530+
$chat->updateThis(array('update' => $chatUpdateFields));
15071531

15081532
if (empty($eChat->payload)) {
15091533
$eChat->payload = json_encode($payloadAll);
@@ -1992,15 +2016,25 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
19922016
'echat' => $eChat
19932017
));
19942018

1995-
$chat->updateThis(['update' => [
2019+
if ($enableUnreadOpFlow) {
2020+
$chat->has_unread_op_messages = 1;
2021+
$chat->unread_op_messages_informed = 0;
2022+
$chat->last_op_msg_time = time();
2023+
}
2024+
2025+
$chatUpdateFields = [
19962026
'last_msg_id',
19972027
'last_user_msg_time',
19982028
'dep_id',
19992029
'priority',
20002030
'transfer_if_na',
20012031
'transfer_timeout_ts',
20022032
'transfer_timeout_ac'
2003-
]]);
2033+
];
2034+
if ($enableUnreadOpFlow) {
2035+
$chatUpdateFields = array_merge($chatUpdateFields, ['has_unread_op_messages', 'unread_op_messages_informed', 'last_op_msg_time']);
2036+
}
2037+
$chat->updateThis(['update' => $chatUpdateFields]);
20042038

20052039
// Check that payload context message exists
20062040
$ignore_default = false;
@@ -2193,6 +2227,12 @@ public static function processMessage($incomingWebhook, $payloadMessage, $payloa
21932227
}
21942228
}
21952229

2230+
if ($enableUnreadOpFlow) {
2231+
$chat->has_unread_op_messages = 1;
2232+
$chat->unread_op_messages_informed = 0;
2233+
$chat->last_op_msg_time = time();
2234+
}
2235+
21962236
// Save chat
21972237
$chat->updateThis();
21982238

0 commit comments

Comments
Β (0)