diff --git a/app/services/whatsapp/providers/base_service.rb b/app/services/whatsapp/providers/base_service.rb index b60c02369..97665f7ef 100644 --- a/app/services/whatsapp/providers/base_service.rb +++ b/app/services/whatsapp/providers/base_service.rb @@ -100,7 +100,7 @@ class Whatsapp::Providers::BaseService rows = create_rows(message.content_attributes['items']) section1 = { 'rows' => rows } sections = [section1] - json_hash = { :button => 'Choose an item', 'sections' => sections } + json_hash = { :button => I18n.t('conversations.messages.whatsapp.list_button_label'), 'sections' => sections } create_payload('list', message.outgoing_content, JSON.generate(json_hash)) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 59d7b8850..463aa713e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -152,6 +152,8 @@ en: instagram_story_content: '%{story_sender} mentioned you in the story: ' instagram_deleted_story_content: This story is no longer available. deleted: This message was deleted + whatsapp: + list_button_label: 'Choose an item' delivery_status: error_code: 'Error code: %{error_code}' activity: diff --git a/config/locales/pt_BR.yml b/config/locales/pt_BR.yml index a46e5b9c4..19570ab07 100644 --- a/config/locales/pt_BR.yml +++ b/config/locales/pt_BR.yml @@ -138,6 +138,8 @@ pt_BR: instagram_story_content: '%{story_sender} mencionou você na conversa: ' instagram_deleted_story_content: Este Story não está mais disponível. deleted: Esta mensagem foi excluída + whatsapp: + list_button_label: 'Escolha um item' delivery_status: error_code: 'Código de erro: %{error_code}' activity: @@ -213,7 +215,7 @@ pt_BR: slack: name: 'Slack' short_description: 'Receba notificações e responda as conversas diretamente no Slack.' - description: "Integre Chatwoot com Slack para manter seu time em sincronia. Essa integração permite que você receba notificações de novas conversas e as responda diretamente na interface do Slack." + description: 'Integre Chatwoot com Slack para manter seu time em sincronia. Essa integração permite que você receba notificações de novas conversas e as responda diretamente na interface do Slack.' webhooks: name: 'Webhooks' description: 'Eventos webhook fornecem atualizações sobre atividades em tempo real na sua conta Chatwoot. Você pode se inscrever em seus eventos preferidos, e o Chatwoot enviará as chamadas HTTP com as atualizações.' @@ -224,7 +226,7 @@ pt_BR: google_translate: name: 'Tradutor do Google' short_description: 'Traduzir automaticamente mensagens de clientes para agentes.' - description: "Integre o Google Tradutor para ajudar os agentes a traduzir facilmente as mensagens dos clientes. Esta integração detecta automaticamente o idioma e o converte para o idioma preferido do agente ou do administrador." + description: 'Integre o Google Tradutor para ajudar os agentes a traduzir facilmente as mensagens dos clientes. Esta integração detecta automaticamente o idioma e o converte para o idioma preferido do agente ou do administrador.' openai: name: 'OpenAI' short_description: 'Sugestões, resumos e aprimoramento de mensagem e resposta com IA.' diff --git a/spec/services/whatsapp/providers/whatsapp360_dialog_service_spec.rb b/spec/services/whatsapp/providers/whatsapp360_dialog_service_spec.rb index bba3f5914..572e96685 100644 --- a/spec/services/whatsapp/providers/whatsapp360_dialog_service_spec.rb +++ b/spec/services/whatsapp/providers/whatsapp360_dialog_service_spec.rb @@ -51,16 +51,15 @@ describe Whatsapp::Providers::Whatsapp360DialogService do end it 'calls message endpoints with list payload when number of items is greater than 3' do + items = %w[Burito Pasta Sushi Salad].map { |i| { title: i, value: i } } message = create(:message, message_type: :outgoing, content: 'test', inbox: whatsapp_channel.inbox, - content_type: 'input_select', - content_attributes: { - items: [ - { title: 'Burito', value: 'Burito' }, - { title: 'Pasta', value: 'Pasta' }, - { title: 'Sushi', value: 'Sushi' }, - { title: 'Salad', value: 'Salad' } - ] - }) + content_type: 'input_select', content_attributes: { items: items }) + + expected_action = { + button: I18n.t('conversations.messages.whatsapp.list_button_label'), + sections: [{ rows: %w[Burito Pasta Sushi Salad].map { |i| { id: i, title: i } } }] + }.to_json + stub_request(:post, 'https://waba.360dialog.io/v1/messages') .with( body: { @@ -70,9 +69,9 @@ describe Whatsapp::Providers::Whatsapp360DialogService do body: { text: 'test' }, - action: '{"button":"Choose an item","sections":[{"rows":[{"id":"Burito","title":"Burito"},' \ - '{"id":"Pasta","title":"Pasta"},{"id":"Sushi","title":"Sushi"},{"id":"Salad","title":"Salad"}]}]}' - }, type: 'interactive' + action: expected_action + }, + type: 'interactive' }.to_json ).to_return(status: 200, body: whatsapp_response.to_json, headers: response_headers) expect(service.send_message('+123456789', message)).to eq 'message_id' diff --git a/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb b/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb index 134d69fee..1bef635b3 100644 --- a/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb +++ b/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb @@ -124,16 +124,15 @@ describe Whatsapp::Providers::WhatsappCloudService do end it 'calls message endpoints with list payload when number of items is greater than 3' do + items = %w[Burito Pasta Sushi Salad].map { |i| { title: i, value: i } } message = create(:message, message_type: :outgoing, content: 'test', inbox: whatsapp_channel.inbox, - content_type: 'input_select', - content_attributes: { - items: [ - { title: 'Burito', value: 'Burito' }, - { title: 'Pasta', value: 'Pasta' }, - { title: 'Sushi', value: 'Sushi' }, - { title: 'Salad', value: 'Salad' } - ] - }) + content_type: 'input_select', content_attributes: { items: items }) + + expected_action = { + button: I18n.t('conversations.messages.whatsapp.list_button_label'), + sections: [{ rows: %w[Burito Pasta Sushi Salad].map { |i| { id: i, title: i } } }] + }.to_json + stub_request(:post, 'https://graph.facebook.com/v13.0/123456789/messages') .with( body: { @@ -143,9 +142,9 @@ describe Whatsapp::Providers::WhatsappCloudService do body: { text: 'test' }, - action: '{"button":"Choose an item","sections":[{"rows":[{"id":"Burito","title":"Burito"},' \ - '{"id":"Pasta","title":"Pasta"},{"id":"Sushi","title":"Sushi"},{"id":"Salad","title":"Salad"}]}]}' - }, type: 'interactive' + action: expected_action + }, + type: 'interactive' }.to_json ).to_return(status: 200, body: whatsapp_response.to_json, headers: response_headers) expect(service.send_message('+123456789', message)).to eq 'message_id'