From 9dabaaa505ee501051163a719fcc09043c337f4b Mon Sep 17 00:00:00 2001 From: Rodribm10 Date: Tue, 14 Apr 2026 10:01:50 -0300 Subject: [PATCH] fix: usa phone digits como source_id (whatsapp inbox exige E.164 sem +) Smoke test revelou que o inbox do tipo whatsapp valida source_id com regex ^\d{1,15}\z. Trocar UUID por telefone em digitos (phone_digits) e normalizar phone_number pra +phone_digits antes de criar o contato. --- .../api/v1/captain/public_reservations_controller.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/public/api/v1/captain/public_reservations_controller.rb b/app/controllers/public/api/v1/captain/public_reservations_controller.rb index a93eda6e5..e4528863f 100644 --- a/app/controllers/public/api/v1/captain/public_reservations_controller.rb +++ b/app/controllers/public/api/v1/captain/public_reservations_controller.rb @@ -13,16 +13,23 @@ class Public::Api::V1::Captain::PublicReservationsController < ActionController: customer = params[:customer] || {} return render(json: { error: 'customer_required' }, status: :unprocessable_entity) if customer[:name].blank? + return render(json: { error: 'customer_phone_required' }, status: :unprocessable_entity) if customer[:phone].blank? account = unit.account inbox = Inbox.find(unit.inbox_id) + # WhatsApp inbox exige source_id com apenas digitos (padrao E.164 sem o +) + phone_digits = customer[:phone].to_s.gsub(/\D/, '') + return render(json: { error: 'customer_phone_invalid' }, status: :unprocessable_entity) if phone_digits.empty? || phone_digits.length > 15 + + normalized_phone = "+#{phone_digits}" + contact_inbox = ::ContactInboxWithContactBuilder.new( - source_id: "reserva1001-#{SecureRandom.uuid}", + source_id: phone_digits, inbox: inbox, contact_attributes: { name: customer[:name], - phone_number: customer[:phone].presence, + phone_number: normalized_phone, email: customer[:email].presence, additional_attributes: { cpf: customer[:cpf].presence,