Feat: Support MMS in SMS Channel ( Bandwidth ) (#4046)

Ability to send and receive MMS to bandwidth channel

fixes: #3961
This commit is contained in:
Sojan Jose
2022-03-02 15:09:56 +05:30
committed by GitHub
parent 4d458c2184
commit 7b9e4982cf
9 changed files with 133 additions and 26 deletions

View File

@@ -33,35 +33,38 @@ class Channel::Sms < ApplicationRecord
'https://messaging.bandwidth.com/api/v2'
end
# Extract later into provider Service
def send_message(phone_number, message)
if message.attachments.present?
send_attachment_message(phone_number, message)
else
send_text_message(phone_number, message.content)
end
def send_message(contact_number, message)
body = message_body(contact_number, message.content)
body['media'] = message.attachments.map(&:download_url) if message.attachments.present?
send_to_bandwidth(body)
end
def send_text_message(contact_number, message)
response = HTTParty.post(
"#{api_base_path}/users/#{provider_config['account_id']}/messages",
basic_auth: bandwidth_auth,
headers: { 'Content-Type' => 'application/json' },
body: {
'to' => contact_number,
'from' => phone_number,
'text' => message,
'applicationId' => provider_config['application_id']
}.to_json
)
response.success? ? response.parsed_response['id'] : nil
def send_text_message(contact_number, message_content)
body = message_body(contact_number, message_content)
send_to_bandwidth(body)
end
private
def send_attachment_message(phone_number, message)
# fix me
def message_body(contact_number, message_content)
{
'to' => contact_number,
'from' => phone_number,
'text' => message_content,
'applicationId' => provider_config['application_id']
}
end
def send_to_bandwidth(body)
response = HTTParty.post(
"#{api_base_path}/users/#{provider_config['account_id']}/messages",
basic_auth: bandwidth_auth,
headers: { 'Content-Type' => 'application/json' },
body: body.to_json
)
response.success? ? response.parsed_response['id'] : nil
end
def bandwidth_auth