refactor(voice): address review feedback on WhatsApp Cloud Calling provider methods

This commit is contained in:
Tanmay Deep Sharma
2026-04-30 14:43:44 +07:00
parent e2b3965a08
commit 48022833ea
3 changed files with 12 additions and 6 deletions
+1
View File
@@ -243,6 +243,7 @@ en:
deleted: This message was deleted
whatsapp:
list_button_label: 'Choose an item'
call_permission_request_body: 'We would like to call you regarding your conversation.'
delivery_status:
error_code: 'Error code: %{error_code}'
activity:
@@ -15,9 +15,9 @@ module Enterprise::Whatsapp::Providers::WhatsappCloudService
call_api('terminate_call', call_action_body(call_id, 'terminate'))
end
def send_call_permission_request(to_phone_number, body_text = 'We would like to call you regarding your conversation.')
def send_call_permission_request(to_phone_number, body_text = I18n.t('conversations.messages.whatsapp.call_permission_request_body'))
response = HTTParty.post(
"#{phone_id_path}/messages", headers: api_headers, body: permission_request_body(to_phone_number, body_text).to_json
"#{phone_id_path}/messages", headers: api_headers, body: permission_request_body(to_phone_number, body_text)
)
unless response.success?
@@ -30,7 +30,7 @@ module Enterprise::Whatsapp::Providers::WhatsappCloudService
def initiate_call(to_phone_number, sdp_offer)
response = HTTParty.post(
"#{phone_id_path}/calls", headers: api_headers, body: initiate_call_body(to_phone_number, sdp_offer).to_json
"#{phone_id_path}/calls", headers: api_headers, body: initiate_call_body(to_phone_number, sdp_offer)
)
process_initiate_call_response(response)
end
@@ -60,14 +60,14 @@ module Enterprise::Whatsapp::Providers::WhatsappCloudService
action: { name: 'call_permission_request' },
body: { text: body_text }
}
}
}.to_json
end
def initiate_call_body(to_phone_number, sdp_offer)
{
messaging_product: 'whatsapp', to: to_phone_number, type: 'audio',
session: { sdp: sdp_offer, sdp_type: 'offer' }
}
}.to_json
end
def process_initiate_call_response(response)
@@ -78,7 +78,7 @@ module Enterprise::Whatsapp::Providers::WhatsappCloudService
error_code = parsed.dig('error', 'code')
error_msg = parsed.dig('error', 'error_user_msg') || 'Failed to initiate call'
raise Voice::CallErrors::NoCallPermission, error_msg if error_code == 138_006
raise Voice::CallErrors::NoCallPermission, error_msg if error_code == Voice::CallErrors::NO_CALL_PERMISSION_CODE
raise Voice::CallErrors::CallFailed, error_msg
end
+5
View File
@@ -1,4 +1,9 @@
module Voice::CallErrors
# Meta WhatsApp Cloud Calling error code returned when the contact has not
# granted call permission yet. See `initiate_call` in
# Enterprise::Whatsapp::Providers::WhatsappCloudService.
NO_CALL_PERMISSION_CODE = 138_006
class NoCallPermission < StandardError; end
class CallFailed < StandardError; end
class NotRinging < StandardError; end