From eb4da33cdc82260ec76ffe157c505323d4ab4589 Mon Sep 17 00:00:00 2001 From: Clairton Rodrigo Heinzen Date: Wed, 8 Mar 2023 09:53:25 -0300 Subject: [PATCH] feat: Ability to customize the base url for Whatsapp Cloud Service (#6622) Configure a custom endpoint for Whatsapp Cloud Service via `WHATSAPP_CLOUD_BASE_URL`. refs: #5142 --- .../whatsapp/providers/whatsapp_cloud_service.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/services/whatsapp/providers/whatsapp_cloud_service.rb b/app/services/whatsapp/providers/whatsapp_cloud_service.rb index 8ca1a9672..04ddc8f02 100644 --- a/app/services/whatsapp/providers/whatsapp_cloud_service.rb +++ b/app/services/whatsapp/providers/whatsapp_cloud_service.rb @@ -37,18 +37,22 @@ class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseServi end def media_url(media_id) - "https://graph.facebook.com/v13.0/#{media_id}" + "#{api_base_path}/v13.0/#{media_id}" end private + def api_base_path + ENV.fetch('WHATSAPP_CLOUD_BASE_URL', 'https://graph.facebook.com') + end + # TODO: See if we can unify the API versions and for both paths and make it consistent with out facebook app API versions def phone_id_path - "https://graph.facebook.com/v13.0/#{whatsapp_channel.provider_config['phone_number_id']}" + "#{api_base_path}/v13.0/#{whatsapp_channel.provider_config['phone_number_id']}" end def business_account_path - "https://graph.facebook.com/v14.0/#{whatsapp_channel.provider_config['business_account_id']}" + "#{api_base_path}/v14.0/#{whatsapp_channel.provider_config['business_account_id']}" end def send_text_message(phone_number, message)