Skip to content

Commit f736f20

Browse files
committed
CV2-6430: Stop retrieving WhatsApp conversation data (#2330)
* CV2-6430: stop retrieving WhatsApp conversation data * CV2-6430: fix tests
1 parent 78c61a8 commit f736f20

2 files changed

Lines changed: 37 additions & 35 deletions

File tree

‎lib/check_statistics.rb‎

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,41 +66,43 @@ def number_of_whatsapp_conversations(team_id, start_date, end_date, type = 'all'
6666

6767
# Only available for tiplines using WhatsApp Cloud API
6868
unless tbi&.get_capi_whatsapp_business_account_id.blank?
69-
uri = URI(URI.join('https://graph.facebook.com/v17.0/', tbi.get_capi_whatsapp_business_account_id.to_s))
69+
# Based on CV2-6430, we should stop retrieving WhatsApp conversation data, so I stopped calling the API and instead return '-'
70+
# So I'll comment the code for calling API and just use `-`
71+
# uri = URI(URI.join('https://graph.facebook.com/v17.0/', tbi.get_capi_whatsapp_business_account_id.to_s))
7072
# Account for changes in WhatsApp pricing model
7173
# Until May 2023: User-initiated conversations and business-initiated conversations are defined by the dimension CONVERSATION_DIRECTION, values BUSINESS_INITIATED or USER_INITIATED
7274
# Starting June 2023: The dimension is CONVERSATION_CATEGORY, where SERVICE is user-initiated and business-initiated is defined by UTILITY, MARKETING or AUTHENTICATION
7375
# https://developers.facebook.com/docs/whatsapp/business-management-api/analytics/#conversation-analytics-parameters
74-
dimension_field = ''
75-
unless type == 'all'
76-
dimension = ''
77-
if to < Time.parse('2023-06-01').beginning_of_day.to_i
78-
dimension = 'CONVERSATION_DIRECTION'
79-
else
80-
dimension = 'CONVERSATION_CATEGORY'
81-
end
82-
dimension_field = ".dimensions(#{dimension})"
83-
end
84-
params = {
85-
fields: "conversation_analytics.start(#{from}).end(#{to}).granularity(DAILY)#{dimension_field}.phone_numbers(#{tbi.get_capi_phone_number})",
86-
access_token: tbi.get_capi_permanent_token
87-
}
88-
uri.query = Rack::Utils.build_query(params)
89-
http = Net::HTTP.new(uri.host, uri.port)
90-
http.use_ssl = true
91-
request = Net::HTTP::Get.new(uri.request_uri, 'Content-Type' => 'application/json')
92-
response = http.request(request)
93-
raise 'Unexpected response' if response.code.to_i >= 300
94-
data = JSON.parse(response.body)
95-
all = 0
96-
user = 0
97-
business = 0
98-
data['conversation_analytics']['data'][0]['data_points'].each do |data_point|
99-
count = data_point['conversation']
100-
all += count
101-
user += count if data_point['conversation_direction'] == 'USER_INITIATED' || data_point['conversation_category'] == 'SERVICE'
102-
business += count if data_point['conversation_direction'] == 'BUSINESS_INITIATED' || ['UTILITY', 'MARKETING', 'AUTHENTICATION'].include?(data_point['conversation_category'])
103-
end
76+
# dimension_field = ''
77+
# unless type == 'all'
78+
# dimension = ''
79+
# if to < Time.parse('2023-06-01').beginning_of_day.to_i
80+
# dimension = 'CONVERSATION_DIRECTION'
81+
# else
82+
# dimension = 'CONVERSATION_CATEGORY'
83+
# end
84+
# dimension_field = ".dimensions(#{dimension})"
85+
# end
86+
# params = {
87+
# fields: "conversation_analytics.start(#{from}).end(#{to}).granularity(DAILY)#{dimension_field}.phone_numbers(#{tbi.get_capi_phone_number})",
88+
# access_token: tbi.get_capi_permanent_token
89+
# }
90+
# uri.query = Rack::Utils.build_query(params)
91+
# http = Net::HTTP.new(uri.host, uri.port)
92+
# http.use_ssl = true
93+
# request = Net::HTTP::Get.new(uri.request_uri, 'Content-Type' => 'application/json')
94+
# response = http.request(request)
95+
# raise 'Unexpected response' if response.code.to_i >= 300
96+
# data = JSON.parse(response.body)
97+
all = '-'
98+
user = '-'
99+
business = '-'
100+
# data['conversation_analytics']['data'][0]['data_points'].each do |data_point|
101+
# count = data_point['conversation']
102+
# all += count
103+
# user += count if data_point['conversation_direction'] == 'USER_INITIATED' || data_point['conversation_category'] == 'SERVICE'
104+
# business += count if data_point['conversation_direction'] == 'BUSINESS_INITIATED' || ['UTILITY', 'MARKETING', 'AUTHENTICATION'].include?(data_point['conversation_category'])
105+
# end
104106
{
105107
all: all,
106108
user: user,

‎test/lib/check_statistics_test.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ def teardown
6262
},
6363
id: '123456'
6464
}.to_json)
65-
assert_equal 2300, CheckStatistics.number_of_whatsapp_conversations(@team.id, @from, @to, 'all')
65+
assert_equal '-', CheckStatistics.number_of_whatsapp_conversations(@team.id, @from, @to, 'all')
6666
end
6767

6868
test 'should not calculate number of WhatsApp conversations if WhatsApp Insights API returns an error' do
6969
WebMock.stub_request(:get, @url).to_return(status: 400, body: { error: 'Error' }.to_json)
70-
assert_nil CheckStatistics.number_of_whatsapp_conversations(@team.id, @from, @to)
70+
assert_equal '-', CheckStatistics.number_of_whatsapp_conversations(@team.id, @from, @to)
7171
end
7272

7373
test 'should not calculate number of WhatsApp conversations if there is no tipline' do
@@ -110,7 +110,7 @@ def teardown
110110
},
111111
id: '123456'
112112
}.to_json)
113-
assert_equal 40, CheckStatistics.number_of_whatsapp_conversations(@team.id, @from, @to, 'user')
114-
assert_equal 10, CheckStatistics.number_of_whatsapp_conversations(@team.id, @from, @to, 'business')
113+
assert_equal '-', CheckStatistics.number_of_whatsapp_conversations(@team.id, @from, @to, 'user')
114+
assert_equal '-', CheckStatistics.number_of_whatsapp_conversations(@team.id, @from, @to, 'business')
115115
end
116116
end

0 commit comments

Comments
 (0)