Merge branch 'feat/whatsapp-call-meta-bridge' into feat/whatsapp-call-ui
This commit is contained in:
@@ -10,7 +10,8 @@ class Api::V1::Accounts::Contacts::CallsController < Api::V1::Accounts::BaseCont
|
||||
account: Current.account,
|
||||
inbox: voice_inbox,
|
||||
user: Current.user,
|
||||
contact: contact
|
||||
contact: contact,
|
||||
conversation: existing_conversation
|
||||
)
|
||||
|
||||
render json: {
|
||||
@@ -38,4 +39,13 @@ class Api::V1::Accounts::Contacts::CallsController < Api::V1::Accounts::BaseCont
|
||||
inbox
|
||||
end
|
||||
end
|
||||
|
||||
# Reuse the open conversation when the caller is already inside it; ignore
|
||||
# the hint if it doesn't belong to the picked voice inbox.
|
||||
def existing_conversation
|
||||
return nil if params[:conversation_id].blank?
|
||||
|
||||
conversation = Current.account.conversations.find_by(display_id: params[:conversation_id])
|
||||
conversation if conversation && conversation.inbox_id == voice_inbox.id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
class Voice::OutboundCallBuilder
|
||||
attr_reader :account, :inbox, :user, :contact
|
||||
|
||||
def self.perform!(account:, inbox:, user:, contact:)
|
||||
new(account: account, inbox: inbox, user: user, contact: contact).perform!
|
||||
def self.perform!(account:, inbox:, user:, contact:, conversation: nil)
|
||||
new(account: account, inbox: inbox, user: user, contact: contact, conversation: conversation).perform!
|
||||
end
|
||||
|
||||
def initialize(account:, inbox:, user:, contact:)
|
||||
def initialize(account:, inbox:, user:, contact:, conversation: nil)
|
||||
@account = account
|
||||
@inbox = inbox
|
||||
@user = user
|
||||
@contact = contact
|
||||
@existing_conversation = conversation
|
||||
end
|
||||
|
||||
def perform!
|
||||
@@ -18,7 +19,7 @@ class Voice::OutboundCallBuilder
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
contact_inbox = ensure_contact_inbox!
|
||||
conversation = create_conversation!(contact_inbox)
|
||||
conversation = @existing_conversation || create_conversation!(contact_inbox)
|
||||
call_sid = initiate_call!
|
||||
call = create_call!(conversation, call_sid)
|
||||
message = Voice::CallMessageBuilder.new(call).perform!
|
||||
|
||||
Reference in New Issue
Block a user