chore: Add status param in conversation APIs (#2394)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -98,13 +98,14 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
|||||||
|
|
||||||
def conversation_params
|
def conversation_params
|
||||||
additional_attributes = params[:additional_attributes]&.permit! || {}
|
additional_attributes = params[:additional_attributes]&.permit! || {}
|
||||||
|
status = params[:status].present? ? { status: params[:status] } : {}
|
||||||
{
|
{
|
||||||
account_id: Current.account.id,
|
account_id: Current.account.id,
|
||||||
inbox_id: @contact_inbox.inbox_id,
|
inbox_id: @contact_inbox.inbox_id,
|
||||||
contact_id: @contact_inbox.contact_id,
|
contact_id: @contact_inbox.contact_id,
|
||||||
contact_inbox_id: @contact_inbox.id,
|
contact_inbox_id: @contact_inbox.id,
|
||||||
additional_attributes: additional_attributes
|
additional_attributes: additional_attributes
|
||||||
}
|
}.merge(status)
|
||||||
end
|
end
|
||||||
|
|
||||||
def conversation_finder
|
def conversation_finder
|
||||||
|
|||||||
@@ -162,6 +162,18 @@ RSpec.describe 'Conversations API', type: :request do
|
|||||||
expect(response_data[:additional_attributes]).to eq(additional_attributes)
|
expect(response_data[:additional_attributes]).to eq(additional_attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates a conversation in specificed status' do
|
||||||
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
||||||
|
post "/api/v1/accounts/#{account.id}/conversations",
|
||||||
|
headers: agent.create_new_auth_token,
|
||||||
|
params: { source_id: contact_inbox.source_id, status: 'bot' },
|
||||||
|
as: :json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
response_data = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
expect(response_data[:status]).to eq('bot')
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates a new conversation with message when message is passed' do
|
it 'creates a new conversation with message when message is passed' do
|
||||||
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
||||||
post "/api/v1/accounts/#{account.id}/conversations",
|
post "/api/v1/accounts/#{account.id}/conversations",
|
||||||
|
|||||||
@@ -58,12 +58,12 @@ RSpec.describe 'Profile API', type: :request do
|
|||||||
|
|
||||||
it 'updates the password when current password is provided' do
|
it 'updates the password when current password is provided' do
|
||||||
put '/api/v1/profile',
|
put '/api/v1/profile',
|
||||||
params: { profile: { current_password: 'Test123!', password: 'test123', password_confirmation: 'test123' } },
|
params: { profile: { current_password: 'Test123!', password: 'Test1234!', password_confirmation: 'Test1234!' } },
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(agent.reload.valid_password?('test123')).to eq true
|
expect(agent.reload.valid_password?('Test1234!')).to eq true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'throws error when current password provided is invalid' do
|
it 'throws error when current password provided is invalid' do
|
||||||
|
|||||||
@@ -111,6 +111,10 @@ post:
|
|||||||
additional_attributes:
|
additional_attributes:
|
||||||
type: object
|
type: object
|
||||||
description: Lets you specify attributes like browser information
|
description: Lets you specify attributes like browser information
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
enum: ['open', 'resolved', 'bot']
|
||||||
|
description: Specify the conversation whether it's bot, open, closed
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
|
|||||||
@@ -1224,6 +1224,15 @@
|
|||||||
"additional_attributes": {
|
"additional_attributes": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Lets you specify attributes like browser information"
|
"description": "Lets you specify attributes like browser information"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"open",
|
||||||
|
"resolved",
|
||||||
|
"bot"
|
||||||
|
],
|
||||||
|
"description": "Specify the conversation whether it's bot, open, closed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user