diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue index 4b0472f9e..b9c9688fd 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue @@ -229,7 +229,8 @@ export default { this.isAFacebookInbox || this.isATwilioWhatsappChannel || this.isAPIInbox || - this.isAnEmailChannel + this.isAnEmailChannel || + this.isATwilioSMSChannel ); }, replyButtonLabel() { diff --git a/app/services/twilio/send_on_twilio_service.rb b/app/services/twilio/send_on_twilio_service.rb index a440740e4..1133bbf70 100644 --- a/app/services/twilio/send_on_twilio_service.rb +++ b/app/services/twilio/send_on_twilio_service.rb @@ -6,7 +6,11 @@ class Twilio::SendOnTwilioService < Base::SendOnChannelService end def perform_reply - twilio_message = client.messages.create(**message_params) + begin + twilio_message = client.messages.create(**message_params) + rescue Twilio::REST::TwilioError => e + Rails.logger.info "Twilio Error: #{e.message}" + end message.update!(source_id: twilio_message.sid) end @@ -16,7 +20,7 @@ class Twilio::SendOnTwilioService < Base::SendOnChannelService from: channel.phone_number, to: contact_inbox.source_id } - params[:media_url] = attachments if channel.whatsapp? && message.attachments.present? + params[:media_url] = attachments if message.attachments.present? params end diff --git a/spec/services/twilio/send_on_twilio_service_spec.rb b/spec/services/twilio/send_on_twilio_service_spec.rb index 3f114a00b..9fc6e2d57 100644 --- a/spec/services/twilio/send_on_twilio_service_spec.rb +++ b/spec/services/twilio/send_on_twilio_service_spec.rb @@ -77,5 +77,20 @@ describe Twilio::SendOnTwilioService do ::Twilio::SendOnTwilioService.new(message: message).perform end + + it 'if outgoing message has attachment and is for sms' do + # check for message attachment url + allow(messages_double).to receive(:create).with(hash_including(media_url: [anything])).and_return(message_record_double) + allow(message_record_double).to receive(:sid).and_return('1234') + + message = build( + :message, message_type: 'outgoing', inbox: twilio_inbox, account: account, conversation: conversation + ) + attachment = message.attachments.new(account_id: message.account_id, file_type: :image) + attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png') + message.save! + + ::Twilio::SendOnTwilioService.new(message: message).perform + end end end