@@ -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 ,
0 commit comments