* feat: baileys provider and placeholder for link device modal * chore: drop qrcode.vue in favor of just img tag * chore: update modal props * feat: setup channel provider connection * chore: update .env.example with Baileys API default configuration * feat: add support for Baileys provider in WhatsApp events processing * chore: rename Baileys API default host variable to DEFAULT_BAILEYS_URL * feat: add setup and disconnect methods for Baileys channel provider in inboxes controller that will be implemented * feat: add CHANNEL_CONNECTION_UPDATE event and include it in broadcast data preparation * refactor: simplify channel retrieval logic in WhatsappEventsJob * refactor: revert CHANNEL_UPDATE_EVENTS constant from ActionCableBroadcastJob * feat: add 'baileys' as a provider option in Whatsapp channel model * feat: add provider_connection field to Whatsapp channel model and migration * refactor: remove unnecessary CHANNEL_CONNECTION_UPDATE event type * feat: implement channel provider connection with baileys API * feat: add inbox association to Whatsapp channel model and update webhook URL handling * feat: enhance Baileys service to handle webhook multiple event types * refactor: simplify webhook verification logic in Baileys service * feat: add setup channel provider call, and refactor some logic * chore: adapt logic to new API * refactor: fix typo * refactor: fix import * refactor: fix typo * chore: add fixme comment about race condition * fix: remove double disconnect call * feat: implement message processing for incoming WhatsApp messages * refactor: streamline message type determination and improve readability * chore: increase cache key granularity provider connection info might be updated multiple times within 1 second, so updates might be lost due to cache key not being updated. changing cache key to milliseconds solves this * feat: add `is-loading` to buttons * feat: update send_message method to use 'to' parameter and improve error handling * refactor: simplify test setup and update API key in specs * chore: add setup and disconnect channel provider specs * test: fix spec after increase cache key granularity * feat: handle reconnecting state on modal * style: centered error text * feat: advanced options on create inbox * feat: handle new reconnecting on backend * refactor: update inbox controller specs and leave a FIXME note * test: add specs for Whatsapp::IncomingMessageBaileysService * feat: add baileys configuration page * feat: link device button when disconnected on conversation * chore: refactor .env.example * feat: add TODO for unimplemented methods in IncomingMessageBaileysService * fix: correct method name and update environment variable references in WhatsappBaileysService * refactor: simplify channel lookup by removing redundant method and handling phone number check directly * chore: add TODO for unimplemented event processing methods in IncomingMessageBaileysService * fix: update environment variable references in WhatsappBaileysService tests * chore(webhook): add pt-BR translations * chore: add pt-br translations * chore: inboxname component margin * refactor: inboxname computed prop * feat: enhance WhatsApp provider connection handling and message processing * test: inbox controller * chore: improve baileys connection and messages handling * test: incoming message service baileys * refactor: update provider config validation and improve test setup for WhatsApp Baileys service * fix: ensure only text messages are sent and update message source ID * fix: create message * fix: only update message on success * test: fix broken specs * chore: raise error on unsupported message content type * feat: hide provider connection data from non-admins * fix: update advanced options * chore: move class definition * fix: issue with send_message not returning id --------- Co-authored-by: gabrieljablonski <contact@gabrieljablonski.com>
92 lines
4.4 KiB
Ruby
92 lines
4.4 KiB
Ruby
FactoryBot.define do
|
|
factory :channel_whatsapp, class: 'Channel::Whatsapp' do
|
|
sequence(:phone_number) { |n| "+123456789#{n}1" }
|
|
account
|
|
provider_config { { 'api_key' => 'test_key', 'phone_number_id' => 'random_id' } }
|
|
message_templates do
|
|
[{ 'name' => 'sample_shipping_confirmation',
|
|
'status' => 'approved',
|
|
'category' => 'SHIPPING_UPDATE',
|
|
'language' => 'id',
|
|
'namespace' => '2342384942_32423423_23423fdsdaf',
|
|
'components' =>
|
|
[{ 'text' => 'Paket Anda sudah dikirim. Paket akan sampai dalam {{1}} hari kerja.', 'type' => 'BODY' },
|
|
{ 'text' => 'Pesan ini berasal dari bisnis yang tidak terverifikasi.', 'type' => 'FOOTER' }],
|
|
'rejected_reason' => 'NONE' },
|
|
{ 'name' => 'customer_yes_no',
|
|
'status' => 'approved',
|
|
'category' => 'SHIPPING_UPDATE',
|
|
'language' => 'ar',
|
|
'namespace' => '2342384942_32423423_23423fdsdaf23',
|
|
'components' =>
|
|
[{ 'text' => 'عميلنا العزيز الرجاء الرد على هذه الرسالة بكلمة *نعم* للرد على إستفساركم من قبل خدمة العملاء.',
|
|
'type' => 'BODY' }],
|
|
'rejected_reason' => 'NONE' },
|
|
{ 'name' => 'sample_shipping_confirmation',
|
|
'status' => 'approved',
|
|
'category' => 'SHIPPING_UPDATE',
|
|
'language' => 'en_US',
|
|
'namespace' => '23423423_2342423_324234234_2343224',
|
|
'components' =>
|
|
[{ 'text' => 'Your package has been shipped. It will be delivered in {{1}} business days.', 'type' => 'BODY' },
|
|
{ 'text' => 'This message is from an unverified business.', 'type' => 'FOOTER' }],
|
|
'rejected_reason' => 'NONE' },
|
|
{
|
|
'name' => 'ticket_status_updated',
|
|
'status' => 'APPROVED',
|
|
'category' => 'UTILITY',
|
|
'language' => 'en',
|
|
'components' => [
|
|
{ 'text' => "Hello {{name}}, Your support ticket with ID: \#{{ticket_id}} has been updated by the support agent.",
|
|
'type' => 'BODY',
|
|
'example' => { 'body_text_named_params' => [
|
|
{ 'example' => 'John', 'param_name' => 'name' },
|
|
{ 'example' => '2332', 'param_name' => 'ticket_id' }
|
|
] } }
|
|
],
|
|
'sub_category' => 'CUSTOM',
|
|
'parameter_format' => 'NAMED'
|
|
},
|
|
{
|
|
'name' => 'ticket_status_updated',
|
|
'status' => 'APPROVED',
|
|
'category' => 'UTILITY',
|
|
'language' => 'en_US',
|
|
'components' => [
|
|
{ 'text' => "Hello {{last_name}}, Your support ticket with ID: \#{{ticket_id}} has been updated by the support agent.",
|
|
'type' => 'BODY',
|
|
'example' => { 'body_text_named_params' => [
|
|
{ 'example' => 'Dale', 'param_name' => 'last_name' },
|
|
{ 'example' => '2332', 'param_name' => 'ticket_id' }
|
|
] } }
|
|
],
|
|
'sub_category' => 'CUSTOM',
|
|
'parameter_format' => 'NAMED'
|
|
}]
|
|
end
|
|
message_templates_last_updated { Time.now.utc }
|
|
|
|
transient do
|
|
sync_templates { true }
|
|
validate_provider_config { true }
|
|
end
|
|
|
|
before(:create) do |channel_whatsapp, options|
|
|
# since factory already has the required message templates, we just need to bypass it getting updated
|
|
channel_whatsapp.define_singleton_method(:sync_templates) { nil } unless options.sync_templates
|
|
channel_whatsapp.define_singleton_method(:validate_provider_config) { nil } unless options.validate_provider_config
|
|
if channel_whatsapp.provider == 'baileys'
|
|
channel_whatsapp.provider_config = channel_whatsapp.provider_config.merge({ 'api_key' => 'test_key', 'provider_url' => 'https://baileys.api',
|
|
'phone_number_id' => '123456789' })
|
|
elsif channel_whatsapp.provider == 'whatsapp_cloud'
|
|
channel_whatsapp.provider_config = channel_whatsapp.provider_config.merge({ 'api_key' => 'test_key', 'phone_number_id' => '123456789',
|
|
'business_account_id' => '123456789' })
|
|
end
|
|
end
|
|
|
|
after(:create) do |channel_whatsapp|
|
|
create(:inbox, channel: channel_whatsapp, account: channel_whatsapp.account)
|
|
end
|
|
end
|
|
end
|