feat: Add article messages along with bot responses (#7993)
ref: https://linear.app/chatwoot/issue/CW-2464/bot-should-also-return-links-to-the-information
This commit is contained in:
@@ -4,27 +4,32 @@ RSpec.describe Enterprise::MessageTemplates::ResponseBotService, type: :service
|
||||
let!(:conversation) { create(:conversation, status: :pending) }
|
||||
let(:service) { described_class.new(conversation: conversation) }
|
||||
let(:chat_gpt_double) { instance_double(ChatGpt) }
|
||||
let(:response_source) { create(:response_source, account: conversation.account) }
|
||||
let(:response_object) { instance_double(Response, id: 1, question: 'Q1', answer: 'A1') }
|
||||
|
||||
before do
|
||||
# Uncomment if you want to run the spec in your local machine
|
||||
# Features::ResponseBotService.new.enable_in_installation
|
||||
skip('Skipping since vector is not enabled in this environment') unless Features::ResponseBotService.new.vector_extension_enabled?
|
||||
|
||||
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')
|
||||
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 => [1, 2] })
|
||||
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])
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
context 'when successful' do
|
||||
it 'creates an outgoing message' do
|
||||
it 'creates an outgoing message along with article references' do
|
||||
expect do
|
||||
service.perform
|
||||
end.to change { conversation.messages.where(message_type: :outgoing).count }.by(1)
|
||||
|
||||
expect(conversation.messages.last.content).to eq('some_response')
|
||||
last_message = conversation.messages.last
|
||||
expect(last_message.content).to include('some_response')
|
||||
expect(last_message.content).to include(Response.first.question)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user