diff --git a/app/app/Jobs/Bot/ProcessJivoMessageJob.php b/app/app/Jobs/Bot/ProcessJivoMessageJob.php index bd776ea2..5a7c960a 100644 --- a/app/app/Jobs/Bot/ProcessJivoMessageJob.php +++ b/app/app/Jobs/Bot/ProcessJivoMessageJob.php @@ -56,7 +56,7 @@ class ProcessJivoMessageJob implements ShouldQueue // Память разговора — ДО записи текущего сообщения (иначе оно попадёт в историю). // Служебные хвосты «👉 Показать на портале: …» из прошлых ответов LLM не нужны. $history = BotDialog::query() - ->where('jivo_chat_id', $this->chatId) + ->where('chat_id', $this->chatId) ->orderByDesc('id') ->limit(self::HISTORY_LIMIT) ->get(['direction', 'message']) @@ -69,7 +69,7 @@ class ProcessJivoMessageJob implements ShouldQueue ->all(); BotDialog::create([ - 'jivo_chat_id' => $this->chatId, + 'chat_id' => $this->chatId, 'direction' => 'in', 'message' => $this->text, 'created_at' => now(), @@ -85,7 +85,7 @@ class ProcessJivoMessageJob implements ShouldQueue app(JivoBotClient::class)->sendMessage($this->chatId, $this->clientId, $answer->text); BotDialog::create([ - 'jivo_chat_id' => $this->chatId, + 'chat_id' => $this->chatId, 'direction' => 'out', 'message' => $answer->text, 'matched_chunks' => $answer->matchedChunkIds, @@ -99,7 +99,7 @@ class ProcessJivoMessageJob implements ShouldQueue private function awaitsContact(): bool { $lastOut = BotDialog::query() - ->where('jivo_chat_id', $this->chatId) + ->where('chat_id', $this->chatId) ->where('direction', 'out') ->latest('id') ->value('message'); @@ -124,7 +124,7 @@ class ProcessJivoMessageJob implements ShouldQueue } $rows = BotDialog::query() - ->where('jivo_chat_id', $this->chatId) + ->where('chat_id', $this->chatId) ->orderByDesc('id') ->limit(8) ->get(['direction', 'message']) diff --git a/app/database/migrations/2026_07_13_100000_chat_widget_columns.php b/app/database/migrations/2026_07_13_100000_chat_widget_columns.php new file mode 100644 index 00000000..74b51b2d --- /dev/null +++ b/app/database/migrations/2026_07_13_100000_chat_widget_columns.php @@ -0,0 +1,34 @@ +insert([ - 'jivo_chat_id' => 'chat-1', + 'chat_id' => 'chat-1', 'direction' => 'in', 'message' => 'что такое проект?', 'created_at' => now(), ]); DB::table('bot_dialogs')->insert([ - 'jivo_chat_id' => 'chat-1', + 'chat_id' => 'chat-1', 'direction' => 'out', 'message' => 'Проект — это…', 'matched_chunks' => json_encode([1, 2]), @@ -24,5 +24,19 @@ it('bot_dialogs принимает запись входа и выхода', fun 'created_at' => now(), ]); - expect(DB::table('bot_dialogs')->where('jivo_chat_id', 'chat-1')->count())->toBe(2); + expect(DB::table('bot_dialogs')->where('chat_id', 'chat-1')->count())->toBe(2); +}); + +it('журнал разговоров хранит номер разговора, откуда пришёл и кто клиент', function () { + $columns = DB::select(" + SELECT column_name FROM information_schema.columns + WHERE table_name = 'bot_dialogs' + "); + $names = array_map(fn ($c) => $c->column_name, $columns); + + expect($names)->toContain('chat_id') + ->and($names)->toContain('source') + ->and($names)->toContain('user_id') + ->and($names)->toContain('ip') + ->and($names)->not->toContain('jivo_chat_id'); }); diff --git a/app/tests/Feature/Bot/BotSpeedBudgetTest.php b/app/tests/Feature/Bot/BotSpeedBudgetTest.php index 6b320e16..dee3f1a2 100644 --- a/app/tests/Feature/Bot/BotSpeedBudgetTest.php +++ b/app/tests/Feature/Bot/BotSpeedBudgetTest.php @@ -33,7 +33,7 @@ it('наша часть тракта (без сети) укладывается $latencies = []; for ($i = 0; $i < 10; $i++) { (new ProcessJivoMessageJob("chat-{$i}", 'c', 'что такое проект?'))->handle(); - $latencies[] = (int) BotDialog::where('jivo_chat_id', "chat-{$i}") + $latencies[] = (int) BotDialog::where('chat_id', "chat-{$i}") ->where('direction', 'out')->value('latency_ms'); }