Skip to content

Commit

Permalink
Send out the text of a message that has an image
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 committed Nov 7, 2024
1 parent 085921a commit a37caf6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
20 changes: 9 additions & 11 deletions app/adapters/whats_app_adapter/three_sixty_dialog_outbound.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,15 @@ def send_message_template(recipient, message)
def send_message(recipient, message)
files = message.files

if files.blank?
WhatsAppAdapter::ThreeSixtyDialogOutbound::Text.perform_later(organization_id: message.organization.id,
payload: text_payload(
recipient, message.text
),
message_id: message.id)
else
files.each do |_file|
WhatsAppAdapter::ThreeSixtyDialog::UploadFileJob.perform_later(message_id: message.id)
end
end
WhatsAppAdapter::ThreeSixtyDialog::UploadFileJob.perform_later(message_id: message.id) if files.present?

return if message.text.blank?

WhatsAppAdapter::ThreeSixtyDialogOutbound::Text.perform_later(organization_id: message.organization.id,
payload: text_payload(
recipient, message.text
),
message_id: message.id)
end

# rubocop:disable Metrics/MethodLength
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,47 @@
text_payload.merge({ message_id: latest_message.id })
)
end

context 'message with file, no text' do
let(:message_file) do
[create(:file, message: latest_message,
attachment: Rack::Test::UploadedFile.new(Rails.root.join('spec/fixtures/files/matt.jpeg'), 'image/jpeg'))]
end

before do
latest_message.update!(text: '', files: message_file)
end

it 'enqueues a job to upload the file' do
expect do
subject.call
end.to have_enqueued_job(WhatsAppAdapter::ThreeSixtyDialog::UploadFileJob).on_queue('default').with(
message_id: latest_message.id
)
end

context 'message with file and text' do
before do
latest_message.update!(text: 'Some text')
end

it 'enqueues a job to upload the file' do
expect do
subject.call
end.to have_enqueued_job(WhatsAppAdapter::ThreeSixtyDialog::UploadFileJob).on_queue('default').with(
message_id: latest_message.id
)
end

it 'enqueues a job to send out the text' do
expect do
subject.call
end.to have_enqueued_job(WhatsAppAdapter::ThreeSixtyDialogOutbound::Text).on_queue('default').with(
text_payload.merge({ message_id: latest_message.id })
)
end
end
end
end

describe 'with an external id' do
Expand Down

0 comments on commit a37caf6

Please sign in to comment.