iachat/spec/enterprise/services/voice/inbound_call_builder_spec.rb
Sojan Jose 6bdd4f0670
feat(voice): Incoming voice calls [EE] (#12361)
This PR delivers the first slice of the voice channel: inbound call
handling. When a customer calls a configured voice
number, Chatwoot now creates a new conversation and shows a dedicated
call bubble in the UI. As the call progresses
(ringing, answered, completed), its status updates in real time in both
the conversation list and the call bubble, so
agents can instantly see what’s happening. This focuses on the inbound
flow and is part of breaking the larger voice
feature into smaller, functional, and testable units; further
enhancements will follow in subsequent PRs.

references: #11602 , #11481  

## Testing

- Configure a Voice inbox in Chatwoot with your Twilio number.
- Place a call to that number.
- Verify a new conversation appears in the Voice inbox for the call.
- Open it and confirm a dedicated voice call message bubble is shown.
- Watch status update live (ringing/answered); hang up and see it change
to completed in both the bubble and conversation
list.
- to test missed call status, make sure to hangup the call before the
please wait while we connect you to an agent message plays


## Screens

<img width="400" alt="Screenshot 2025-09-03 at 3 11 25 PM"
src="https://github.com/user-attachments/assets/d6a1d2ff-2ded-47b7-9144-a9d898beb380"
/>

<img width="700" alt="Screenshot 2025-09-03 at 3 11 33 PM"
src="https://github.com/user-attachments/assets/c25e6a1e-a885-47f7-b3d7-c3e15eef18c7"
/>

<img width="700" alt="Screenshot 2025-09-03 at 3 11 57 PM"
src="https://github.com/user-attachments/assets/29e7366d-b1d4-4add-a062-4646d2bff435"
/>



<img width="442" height="255" alt="Screenshot 2025-09-04 at 11 55 01 PM"
src="https://github.com/user-attachments/assets/703126f6-a448-49d9-9c02-daf3092cc7f9"
/>

---------

Co-authored-by: Muhsin <muhsinkeramam@gmail.com>
2025-09-08 22:35:23 +05:30

58 lines
1.9 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Voice::InboundCallBuilder do
let(:account) { create(:account) }
let(:channel) { create(:channel_voice, account: account, phone_number: '+15551230001') }
let(:inbox) { channel.inbox }
let(:from_number) { '+15550001111' }
let(:to_number) { channel.phone_number }
let(:call_sid) { 'CA1234567890abcdef' }
before do
allow(Twilio::VoiceWebhookSetupService).to receive(:new)
.and_return(instance_double(Twilio::VoiceWebhookSetupService, perform: "AP#{SecureRandom.hex(16)}"))
end
def build_and_perform
described_class.new(
account: account,
inbox: inbox,
from_number: from_number,
to_number: to_number,
call_sid: call_sid
).perform
end
it 'creates a new conversation with inbound ringing attributes' do
builder = build_and_perform
conversation = builder.conversation
expect(conversation).to be_present
expect(conversation.account_id).to eq(account.id)
expect(conversation.inbox_id).to eq(inbox.id)
expect(conversation.identifier).to eq(call_sid)
expect(conversation.additional_attributes['call_direction']).to eq('inbound')
expect(conversation.additional_attributes['call_status']).to eq('ringing')
end
it 'creates a voice_call message with ringing status' do
builder = build_and_perform
conversation = builder.conversation
msg = conversation.messages.voice_calls.last
expect(msg).to be_present
expect(msg.message_type).to eq('incoming')
expect(msg.content_type).to eq('voice_call')
expect(msg.content_attributes.dig('data', 'call_sid')).to eq(call_sid)
expect(msg.content_attributes.dig('data', 'status')).to eq('ringing')
end
it 'returns TwiML that informs the caller we are connecting' do
builder = build_and_perform
xml = builder.twiml_response
expect(xml).to include('Please wait while we connect you to an agent')
expect(xml).to include('<Say')
end
end