chore: Refactor Response Bot Data Schema (#8011)

This PR refactors the schema we introduced in #7518 based on the feedback from production tests. Here is the change log

- Decouple Inbox association to a new table inbox_response_sources -> this lets us share the same response source between multiple inboxes
- Add a status field to responses. This ensures that, by default, responses are created in pending status. You can do quality assurance before making them active. In future, this status can be leveraged by the bot to auto-generate response questions from conversations which require a handoff
- Add response_source association to responses and remove hard dependency from response_documents. This lets users write free-form question answers based on conversations, which doesn't necessarily need a response source.
This commit is contained in:
Sojan Jose
2023-10-01 19:31:38 -07:00
committed by GitHub
parent d8b53f5d2f
commit 826d9ec5a7
18 changed files with 138 additions and 36 deletions

View File

@@ -3,7 +3,6 @@ require 'rails_helper'
RSpec.describe 'Response Sources API', type: :request do
let!(:account) { create(:account) }
let!(:admin) { create(:user, account: account, role: :administrator) }
let!(:inbox) { create(:inbox, account: account) }
before do
skip('Skipping since vector is not enabled in this environment') unless Features::ResponseBotService.new.vector_extension_enabled?
@@ -44,7 +43,6 @@ RSpec.describe 'Response Sources API', type: :request do
response_source: {
name: 'Test',
source_link: 'http://test.test',
inbox_id: inbox.id,
response_documents_attributes: [
{ document_link: 'http://test1.test' },
{ document_link: 'http://test2.test' }
@@ -75,7 +73,7 @@ RSpec.describe 'Response Sources API', type: :request do
end
describe 'POST /api/v1/accounts/{account.id}/response_sources/{response_source.id}/add_document' do
let!(:response_source) { create(:response_source, account: account, inbox: inbox) }
let!(:response_source) { create(:response_source, account: account) }
let(:valid_params) do
{ document_link: 'http://test.test' }
end
@@ -103,7 +101,7 @@ RSpec.describe 'Response Sources API', type: :request do
end
describe 'POST /api/v1/accounts/{account.id}/response_sources/{response_source.id}/remove_document' do
let!(:response_source) { create(:response_source, account: account, inbox: inbox) }
let!(:response_source) { create(:response_source, account: account) }
let!(:response_document) { response_source.response_documents.create!(document_link: 'http://test.test') }
let(:valid_params) do
{ document_id: response_document.id }

View File

@@ -71,7 +71,9 @@ RSpec.describe 'Enterprise Inboxes API', type: :request do
end
it 'returns all response_sources belonging to the inbox to administrators' do
response_source = create(:response_source, account: account, inbox: inbox)
response_source = create(:response_source, account: account)
inbox.response_sources << response_source
inbox.save!
get "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/response_sources",
headers: administrator.create_new_auth_token,
as: :json