chore: Fix trigger message for response Bot (#8322)

- Fix the bug where wrong messages was used to search response sources
This commit is contained in:
Sojan Jose
2023-11-08 17:02:48 -08:00
committed by GitHub
parent af7631d9f1
commit 7b09b02737
2 changed files with 3 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ class Enterprise::MessageTemplates::ResponseBotService
def perform
ActiveRecord::Base.transaction do
@response = get_response(conversation.messages.last.content)
@response = get_response(conversation.messages.incoming.last.content)
process_response
end
rescue StandardError => e

View File

@@ -14,10 +14,11 @@ RSpec.describe Enterprise::MessageTemplates::ResponseBotService, type: :service
stub_request(:post, 'https://api.openai.com/v1/embeddings').to_return(status: 200, body: {}.to_json,
headers: { Content_Type: 'application/json' })
create(:message, message_type: :incoming, conversation: conversation, content: 'Hi')
create(:message, message_type: :outgoing, conversation: conversation, content: 'Hello')
4.times { create(:response, response_source: response_source) }
allow(ChatGpt).to receive(:new).and_return(chat_gpt_double)
allow(chat_gpt_double).to receive(:generate_response).and_return({ 'response' => 'some_response', 'context_ids' => Response.all.map(&:id) })
allow(conversation.inbox).to receive(:get_responses).and_return([response_object])
allow(conversation.inbox).to receive(:get_responses).with('Hi').and_return([response_object])
end
describe '#perform' do