Skip to content

Commit 16a3d28

Browse files
committed
✨ Add "Trigger on bot skip" option and fix missing last_msg_id update
- Add `trigger_on_bot_skip` field definition to proactive invitation attributes - Add `trigger_on_bot_skip` checkbox UI to bot settings template - Reorder `append_intro_bot` and `keep_after_close` fields in template for logical grouping - Extend trigger execution logic in `submitonline.php` to also run triggers when `trigger_on_bot_skip` is enabled - Fix missing `$chat->last_msg_id` assignment after saving invitation message to ensure correct last message tracking
1 parent db2cb43 commit 16a3d28

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

lhc_web/design/defaulttheme/tpl/lhabstract/custom/events/bot.tpl.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<label><?php echo erLhcoreClassAbstract::renderInput('ignore_bot', $fields['ignore_bot'], $object)?> <?php echo $fields['ignore_bot']['trans'];?></label>
33
</div>
44

5+
<div class="form-group ps-3">
6+
<label><?php echo erLhcoreClassAbstract::renderInput('trigger_on_bot_skip', $fields['trigger_on_bot_skip'], $object)?> <?php echo $fields['trigger_on_bot_skip']['trans'];?></label>
7+
</div>
8+
59
<div class="form-group">
610
<label><?php echo erLhcoreClassAbstract::renderInput('bot_offline', $fields['bot_offline'], $object)?> <?php echo $fields['bot_offline']['trans'];?></label>
711
</div>
@@ -11,11 +15,12 @@
1115
</div>
1216

1317
<div class="form-group">
14-
<label><?php echo erLhcoreClassAbstract::renderInput('keep_after_close', $fields['keep_after_close'], $object)?> <?php echo $fields['keep_after_close']['trans'];?></label>
18+
<label><?php echo erLhcoreClassAbstract::renderInput('append_intro_bot', $fields['append_intro_bot'], $object)?> <?php echo $fields['append_intro_bot']['trans'];?></label>
1519
</div>
1620

21+
1722
<div class="form-group">
18-
<label><?php echo erLhcoreClassAbstract::renderInput('append_intro_bot', $fields['append_intro_bot'], $object)?> <?php echo $fields['append_intro_bot']['trans'];?></label>
23+
<label><?php echo erLhcoreClassAbstract::renderInput('keep_after_close', $fields['keep_after_close'], $object)?> <?php echo $fields['keep_after_close']['trans'];?></label>
1924
</div>
2025

2126
<div class="form-group">

lhc_web/lib/core/lhabstract/fields/erlhabstractmodeleproactivechatinvitation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,14 @@
541541
'hidden' => true,
542542
'validation_definition' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int')
543543
),
544+
'trigger_on_bot_skip' => array(
545+
'type' => 'checkbox',
546+
'main_attr' => 'design_data_array',
547+
'trans' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/proactivechatinvitation', 'Run trigger if bot is skipped'),
548+
'required' => false,
549+
'hidden' => true,
550+
'validation_definition' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int')
551+
),
544552
'append_bot' => array(
545553
'type' => 'checkbox',
546554
'main_attr' => 'design_data_array',

lhc_web/modules/lhwidgetrestapi/submitonline.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@
295295
// Happens with invitations where there is no message itself
296296
if ($msg->msg != '') {
297297
erLhcoreClassChat::getSession()->save($msg);
298+
$chat->last_msg_id = $msg->id;
298299
}
299300

300301
if ($ignoreResponder == false && $userInstance->invitation !== false && (!isset($userInstance->invitation->design_data_array['use_default_autoresponder']) || $userInstance->invitation->design_data_array['use_default_autoresponder'] == false)) {
@@ -314,7 +315,10 @@
314315
$paramsExecution['trigger_id'] = $invitation->trigger_id;
315316

316317
// If bot is appended to a widget we should always execute it first.
317-
if (isset($invitation->design_data_array['append_bot']) && $invitation->design_data_array['append_bot'] == 1 && !isset($requestPayload['bpayload']['payload'])) {
318+
if ((
319+
(isset($invitation->design_data_array['append_bot']) && $invitation->design_data_array['append_bot'] == 1) ||
320+
(isset($invitation->design_data_array['trigger_on_bot_skip']) && $invitation->design_data_array['trigger_on_bot_skip'] == 1)
321+
) && !isset($requestPayload['bpayload']['payload'])) {
318322
$trigger = erLhcoreClassModelGenericBotTrigger::fetch($paramsExecution['trigger_id']);
319323
$paramsExecution['trigger_id_executed'] = $paramsExecution['trigger_id'];
320324
if (is_object($trigger)) {

0 commit comments

Comments
 (0)