chore: Add Additional Contact APIs (#1130)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-08-10 12:15:29 +05:30
committed by GitHub
parent ec3c2ed4bb
commit a6a62d92bf
11 changed files with 129 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
class Api::V1::Accounts::Contacts::ContactInboxesController < Api::V1::Accounts::BaseController
before_action :ensure_contact
before_action :ensure_inbox, only: [:create]
before_action :validate_channel_type
def create
source_id = params[:source_id] || SecureRandom.uuid
@contact_inbox = ContactInbox.create(contact: @contact, inbox: @inbox, source_id: source_id)
end
private
def validate_channel_type
return if @inbox.channel_type == 'Channel::Api'
render json: { error: 'Contact Inbox creation is only allowed in API inboxes' }, status: :unprocessable_entity
end
def ensure_inbox
@inbox = Current.account.inboxes.find(params[:inbox_id])
end
def ensure_contact
@contact = Current.account.contacts.find(params[:contact_id])
end
end