Compare commits

...
Author SHA1 Message Date
Shivam Mishra d5935100e5 Revert "Feat: Fetch whatsapp templates till next cursor (#6835)"
This reverts commit 138afd9af6.
2023-04-11 11:06:37 +05:30
Shivam Mishra 2a8c547aeb Revert "chore: Specs for Whatsapp template pagination (#6870)"
This reverts commit d49989ace1.
2023-04-11 11:06:24 +05:30
2 changed files with 3 additions and 36 deletions
@@ -24,12 +24,7 @@ class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseServi
def sync_templates
response = HTTParty.get("#{business_account_path}/message_templates?access_token=#{whatsapp_channel.provider_config['api_key']}")
return unless response.success?
@templates = response['data']
fetch_next_templates(response)
save_templates
whatsapp_channel.update(message_templates: response['data'], message_templates_last_updated: Time.now.utc) if response.success?
end
def validate_provider_config?
@@ -45,25 +40,8 @@ class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseServi
"#{api_base_path}/v13.0/#{media_id}"
end
def fetch_next_templates(response)
loop do
break unless response['paging'] && response['paging']['next']
response = HTTParty.get(response['paging']['next'])
push_templates(response)
end
end
private
def push_templates(response)
@templates << response['data'] if response.success? && response['data'].any?
end
def save_templates
whatsapp_channel.update(message_templates: @templates, message_templates_last_updated: Time.now.utc)
end
def api_base_path
ENV.fetch('WHATSAPP_CLOUD_BASE_URL', 'https://graph.facebook.com')
end
@@ -112,20 +112,9 @@ describe Whatsapp::Providers::WhatsappCloudService do
context 'when called' do
it 'updated the message templates' do
stub_request(:get, 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key')
.to_return(
{ status: 200, headers: response_headers,
body: { data: [
{ id: '123456789', name: 'test_template' }
], paging: { next: 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key' } }.to_json },
{ status: 200, headers: response_headers,
body: { data: [
{ id: '123456789', name: 'next_template' }
], paging: { prev: 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key' } }.to_json }
)
.to_return(status: 200, headers: response_headers, body: { data: [{ id: '123456789', name: 'test_template' }] }.to_json)
expect(subject.sync_templates).to be(true)
expect(whatsapp_channel.reload.message_templates.first).to eq({ id: '123456789', name: 'test_template' }.stringify_keys)
expect(whatsapp_channel.reload.message_templates.last).to eq([{ id: '123456789', name: 'next_template' }.stringify_keys])
expect(whatsapp_channel.reload.message_templates).to eq([{ id: '123456789', name: 'test_template' }.stringify_keys])
end
end
end