chore: Create client API conversations with custom attributes (#8040)
- Update client API create conversations endpoint to accept custom attributes as well.
This commit is contained in:
@@ -33,7 +33,7 @@ class Public::Api::V1::Inboxes::ConversationsController < Public::Api::V1::Inbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_conversation
|
def create_conversation
|
||||||
::Conversation.create!(conversation_params)
|
ConversationBuilder.new(params: conversation_params, contact_inbox: @contact_inbox).perform
|
||||||
end
|
end
|
||||||
|
|
||||||
def trigger_typing_event(event)
|
def trigger_typing_event(event)
|
||||||
@@ -41,11 +41,6 @@ class Public::Api::V1::Inboxes::ConversationsController < Public::Api::V1::Inbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
def conversation_params
|
def conversation_params
|
||||||
{
|
params.permit(custom_attributes: {})
|
||||||
account_id: @contact_inbox.contact.account_id,
|
|
||||||
inbox_id: @contact_inbox.inbox_id,
|
|
||||||
contact_id: @contact_inbox.contact_id,
|
|
||||||
contact_inbox_id: @contact_inbox.id
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -44,6 +44,17 @@ RSpec.describe 'Public Inbox Contact Conversations API', type: :request do
|
|||||||
data = response.parsed_body
|
data = response.parsed_body
|
||||||
expect(data['id']).not_to be_nil
|
expect(data['id']).not_to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates a conversation with custom attributes but prevents other attributes' do
|
||||||
|
post "/public/api/v1/inboxes/#{api_channel.identifier}/contacts/#{contact_inbox.source_id}/conversations",
|
||||||
|
params: { custom_attributes: { 'test' => 'test' }, additional_attributes: { 'test' => 'test' } }
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
data = response.parsed_body
|
||||||
|
conversation = api_channel.inbox.conversations.find_by(display_id: data['id'])
|
||||||
|
expect(conversation.custom_attributes).to eq('test' => 'test')
|
||||||
|
expect(conversation.additional_attributes).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /public/api/v1/inboxes/{identifier}/contact/{source_id}/conversations/{conversation_id}/toggle_typing' do
|
describe 'POST /public/api/v1/inboxes/{identifier}/contact/{source_id}/conversations/{conversation_id}/toggle_typing' do
|
||||||
|
|||||||
@@ -138,6 +138,9 @@ public_message_create_payload:
|
|||||||
public_message_update_payload:
|
public_message_update_payload:
|
||||||
$ref: ./request/public/message/update_payload.yml
|
$ref: ./request/public/message/update_payload.yml
|
||||||
|
|
||||||
|
public_conversation_create_payload:
|
||||||
|
$ref: ./request/public/conversation/create_payload.yml
|
||||||
|
|
||||||
## ---------- RESPONSE ------------- ##
|
## ---------- RESPONSE ------------- ##
|
||||||
## -------------------------------- ##
|
## -------------------------------- ##
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
custom_attributes:
|
||||||
|
type: object
|
||||||
|
description: Custom attributes of the conversation
|
||||||
@@ -4,6 +4,12 @@ operationId: create-a-conversation
|
|||||||
summary: Create a conversation
|
summary: Create a conversation
|
||||||
description: Create a conversation
|
description: Create a conversation
|
||||||
security: []
|
security: []
|
||||||
|
parameters:
|
||||||
|
- name: data
|
||||||
|
in: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/public_conversation_create_payload'
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Success
|
description: Success
|
||||||
|
|||||||
@@ -847,6 +847,16 @@
|
|||||||
"description": "Create a conversation",
|
"description": "Create a conversation",
|
||||||
"security": [
|
"security": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/public_conversation_create_payload"
|
||||||
|
}
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -6617,6 +6627,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"public_conversation_create_payload": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"custom_attributes": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Custom attributes of the conversation"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"extended_contact": {
|
"extended_contact": {
|
||||||
"allOf": [
|
"allOf": [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user