From 3a517b277753e61256a5183a042a8609f4b96175 Mon Sep 17 00:00:00 2001 From: Remigijus Kiminas Date: Mon, 22 May 2023 04:26:12 -0400 Subject: [PATCH] Save message only if chat was not started --- bootstrap/bootstrap.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bootstrap/bootstrap.php b/bootstrap/bootstrap.php index 452a171..8cf26f3 100644 --- a/bootstrap/bootstrap.php +++ b/bootstrap/bootstrap.php @@ -34,13 +34,16 @@ public static function incommingChatStarted($params) $params['chat']->dep_id = $messageBird->dep_id; $params['chat']->updateThis(['update' => ['dep_id']]); - // Save template message first before saving initial response in the lhc core - $msg = new erLhcoreClassModelmsg(); - $msg->msg = $messageBird->message; - $msg->chat_id = $params['chat']->id; - $msg->user_id = $messageBird->user_id; - $msg->time = $messageBird->created_at; - erLhcoreClassChat::getSession()->save($msg); + // Save template only if it was not assigned to any chat yet + if ($messageBird->chat_id == 0) { + // Save template message first before saving initial response in the lhc core + $msg = new erLhcoreClassModelmsg(); + $msg->msg = $messageBird->message; + $msg->chat_id = $params['chat']->id; + $msg->user_id = $messageBird->user_id; + $msg->time = $messageBird->created_at; + erLhcoreClassChat::getSession()->save($msg); + } // Update message bird $messageBird->chat_id = $params['chat']->id;