Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
101 lines
2.8 KiB
Ruby
101 lines
2.8 KiB
Ruby
class Twilio::SendOnTwilioService < Base::SendOnChannelService
|
|
def send_csat_template_message(phone_number:, content_sid:, content_variables: {})
|
|
send_params = {
|
|
to: phone_number,
|
|
content_sid: content_sid
|
|
}
|
|
|
|
send_params[:content_variables] = content_variables.to_json if content_variables.present?
|
|
send_params[:status_callback] = channel.send(:twilio_delivery_status_index_url) if channel.respond_to?(:twilio_delivery_status_index_url, true)
|
|
|
|
# Add messaging service or from number
|
|
send_params = send_params.merge(channel.send(:send_message_from))
|
|
|
|
twilio_message = channel.send(:client).messages.create(**send_params)
|
|
|
|
{ success: true, message_id: twilio_message.sid }
|
|
rescue Twilio::REST::TwilioError, Twilio::REST::RestError => e
|
|
Rails.logger.error "Failed to send Twilio template message: #{e.message}"
|
|
{ success: false, error: e.message }
|
|
end
|
|
|
|
private
|
|
|
|
def channel_class
|
|
Channel::TwilioSms
|
|
end
|
|
|
|
def perform_reply
|
|
begin
|
|
twilio_message = if template_params.present?
|
|
send_template_message
|
|
else
|
|
channel.send_message(**message_params)
|
|
end
|
|
rescue Twilio::REST::TwilioError, Twilio::REST::RestError => e
|
|
Messages::StatusUpdateService.new(message, 'failed', e.message).perform
|
|
end
|
|
message.update!(source_id: twilio_message.sid) if twilio_message
|
|
end
|
|
|
|
def send_template_message
|
|
content_sid, content_variables = process_template_params
|
|
|
|
if content_sid.blank?
|
|
message.update!(status: :failed, external_error: 'Template not found')
|
|
return nil
|
|
end
|
|
|
|
send_params = {
|
|
to: contact_inbox.source_id,
|
|
content_sid: content_sid
|
|
}
|
|
|
|
send_params[:content_variables] = content_variables.to_json if content_variables.present?
|
|
send_params[:status_callback] = channel.send(:twilio_delivery_status_index_url) if channel.respond_to?(:twilio_delivery_status_index_url, true)
|
|
|
|
# Add messaging service or from number
|
|
send_params = send_params.merge(channel.send(:send_message_from))
|
|
|
|
channel.send(:client).messages.create(**send_params)
|
|
end
|
|
|
|
def template_params
|
|
message.additional_attributes && message.additional_attributes['template_params']
|
|
end
|
|
|
|
def process_template_params
|
|
return [nil, nil] if template_params.blank?
|
|
|
|
Twilio::TemplateProcessorService.new(
|
|
channel: channel,
|
|
template_params: template_params,
|
|
message: message
|
|
).call
|
|
end
|
|
|
|
def message_params
|
|
{
|
|
body: message.outgoing_content,
|
|
to: contact_inbox.source_id,
|
|
media_url: attachments
|
|
}
|
|
end
|
|
|
|
def attachments
|
|
message.attachments.map(&:download_url)
|
|
end
|
|
|
|
def inbox
|
|
@inbox ||= message.inbox
|
|
end
|
|
|
|
def channel
|
|
@channel ||= inbox.channel
|
|
end
|
|
|
|
def outgoing_message?
|
|
message.outgoing? || message.template?
|
|
end
|
|
end
|