fix: validate template_params for WhatsApp (#6881)

- Add JsonSchemaValidator, which takes a declarative schema and validates it for a given property.
- Add specs for JsonSchemaValidator
- Enable the validator for template_params
This commit is contained in:
Shivam Mishra
2023-04-25 16:50:36 +05:30
committed by GitHub
parent 0bbb28c432
commit 5600b518ac
5 changed files with 221 additions and 1 deletions

View File

@@ -28,13 +28,14 @@ class Whatsapp::SendOnWhatsappService < Base::SendOnChannelService
message.update!(source_id: message_id) if message_id.present?
end
# rubocop:disable Metrics/CyclomaticComplexity
def processable_channel_message_template
if template_params.present?
return [
template_params['name'],
template_params['namespace'],
template_params['language'],
template_params['processed_params'].map { |_, value| { type: 'text', text: value } }
template_params['processed_params']&.map { |_, value| { type: 'text', text: value } }
]
end
@@ -55,6 +56,7 @@ class Whatsapp::SendOnWhatsappService < Base::SendOnChannelService
end
[nil, nil, nil, nil]
end
# rubocop:enable Metrics/CyclomaticComplexity
def template_match_object(template)
body_object = validated_body_object(template)