Skip to content

Commit

Permalink
A couple of small fixes for the conversation history
Browse files Browse the repository at this point in the history
* Return `media_url` for Smooch WhatsApp template
* Set tipline messages with event `status_change`

Reference: CV2-3853.
  • Loading branch information
caiosba committed Oct 18, 2023
1 parent f227fcd commit 47a3403
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/smooch_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def send_message_on_status_change(pm_id, status, request_actor_session_id = nil)
self.get_installation(self.installation_setting_id_keys, data['app_id']) if self.config.blank?
message = parent.team.get_status_message_for_language(status, data['language'])
unless message.blank?
response = self.send_message_to_user(data['authorId'], message)
response = self.send_message_to_user(data['authorId'], message, {}, false, true, 'status_change')
self.save_smooch_response(response, parent, data['received'].to_i, 'fact_check_status', data['language'], { message: message })
requestors_count += 1
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/tipline_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def media_url
if self.direction == 'incoming'
media_url = payload.dig('messages', 0, 'mediaUrl')
elsif self.direction == 'outgoing'
# WhatsApp Cloud API template
header = payload.dig('override', 'whatsapp', 'payload', 'interactive', 'header')
media_url = header[header['type']]['link'] unless header.nil?
# WhatsApp template on Smooch
media_url ||= payload.dig('text').to_s.match(/header_image=\[\[([^\]]+)\]\]/).to_a.last
end
media_url || payload['mediaUrl']
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/bot/smooch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def teardown
}.to_json
assert Bot::Smooch.run(payload)
pm = ProjectMedia.last
Bot::Smooch.stubs(:send_message_to_user).with(uid, 'Custom').once
Bot::Smooch.stubs(:send_message_to_user).with(uid, 'Custom', {}, false, true, 'status_change').once
s = pm.annotations.where(annotation_type: 'verification_status').last.load
s.status = '2'
s.save!
Expand Down

0 comments on commit 47a3403

Please sign in to comment.