From 2a46aab97f1ed838f1da3666ba04243074c7004e Mon Sep 17 00:00:00 2001 From: nestordavalos Date: Mon, 23 Sep 2024 22:42:53 +0000 Subject: [PATCH 1/7] Translate webphone.json to Portuguese (pt_BR) --- .../dashboard/i18n/locale/pt_BR/webphone.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/javascript/dashboard/i18n/locale/pt_BR/webphone.json b/app/javascript/dashboard/i18n/locale/pt_BR/webphone.json index 06458f059..d328e2844 100644 --- a/app/javascript/dashboard/i18n/locale/pt_BR/webphone.json +++ b/app/javascript/dashboard/i18n/locale/pt_BR/webphone.json @@ -1,9 +1,9 @@ { "WEBPHONE": { - "CALL": "Call", - "TERMINATE": "Terminated", - "ACCEPT_ELSEWHERE": "Accepted by another user", - "REJECT_ELSEWHERE": "Rejected by another user", + "CALL": "Chamada", + "TERMINATE": "Terminado", + "ACCEPT_ELSEWHERE": "Aceite por outro utilizador", + "REJECT_ELSEWHERE": "Rejeitado por outro utilizador", "CONNECT_CALLING": "Conectando", "CALLING": "Chamando", "VOICE_CALL": "Chamada de voz", @@ -28,4 +28,4 @@ "CONNECTION_FAILED": "Conexão falhou", "REJECTED": "Rejeitado" } -} \ No newline at end of file +} From 634c849b7025e5397e5f0993a1f1eb48b4db6378 Mon Sep 17 00:00:00 2001 From: nestordavalos Date: Tue, 24 Sep 2024 16:17:20 +0000 Subject: [PATCH 2/7] fix: Refactor Unoapi.vue and UnoapiWebhookSetupService.rb --- .../settings/inbox/channels/Unoapi.vue | 7 +- .../whatsapp/unoapi_webhook_setup_service.rb | 68 ++++--- db/schema.rb | 188 +++++++++--------- 3 files changed, 138 insertions(+), 125 deletions(-) diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/channels/Unoapi.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/channels/Unoapi.vue index cd6e11bfa..0740858af 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/channels/Unoapi.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/channels/Unoapi.vue @@ -69,7 +69,7 @@ style="flex: 0 0 auto; margin-right: 10px;" /> {{ $t('INBOX_MGMT.ADD.WHATSAPP.SEND_AGENT_NAME.LABEL') }} - + {{ $t('INBOX_MGMT.ADD.WHATSAPP.SEND_AGENT_NAME.ERROR') }} @@ -122,6 +122,11 @@ :loading="uiFlags.isCreating" :button-text="$t('INBOX_MGMT.ADD.WHATSAPP.SUBMIT_BUTTON')" /> + diff --git a/app/services/whatsapp/unoapi_webhook_setup_service.rb b/app/services/whatsapp/unoapi_webhook_setup_service.rb index 300f45754..f581617cc 100644 --- a/app/services/whatsapp/unoapi_webhook_setup_service.rb +++ b/app/services/whatsapp/unoapi_webhook_setup_service.rb @@ -5,11 +5,11 @@ def perform(whatsapp_channel) whatsapp_channel.provider_config.delete('disconnect') return disconnect(whatsapp_channel) end - return unless whatsapp_channel.provider_config['connect'] - - whatsapp_channel.provider_config.delete('connect') - whatsapp_channel.provider_config.delete('disconnect') - connect(whatsapp_channel) + return true unless whatsapp_channel.provider_config['connect'] + + whatsapp_channel.provider_config.delete('connect') + whatsapp_channel.provider_config.delete('disconnect') + connect(whatsapp_channel) end private @@ -28,30 +28,10 @@ def disconnect(whatsapp_channel) def connect(whatsapp_channel) phone_number = whatsapp_channel.provider_config['business_account_id'] - Rails.logger.debug { "Connecting #{phone_number} from unoapi" } - body = { - ignoreGroupMessages: whatsapp_channel.provider_config['ignore_group_messages'], - ignoreBroadcastStatuses: whatsapp_channel.provider_config['ignore_broadcast_statuses'], - ignoreBroadcastMessages: whatsapp_channel.provider_config['ignore_broadcast_messages'], - ignoreHistoryMessages: whatsapp_channel.provider_config['ignore_history_messages'], - ignoreOwnMessages: whatsapp_channel.provider_config['ignore_own_messages'], - ignoreYourselfMessages: whatsapp_channel.provider_config['ignore_yourself_messages'], - sendConnectionStatus: whatsapp_channel.provider_config['send_connection_status'], - notifyFailedMessages: whatsapp_channel.provider_config['notify_failed_messages'], - composingMessage: whatsapp_channel.provider_config['composing_message'], - rejectCalls: whatsapp_channel.provider_config['reject_calls'], - messageCallsWebhook: whatsapp_channel.provider_config['message_calls_webhook'], - webhooks: [ - sendNewMessages: whatsapp_channel.provider_config['webhook_send_new_messages'], - id: 'default', - urlAbsolute: "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/whatsapp/#{phone_number}", - token: whatsapp_channel.provider_config['webhook_verify_token'], - header: :Authorization - ], - sendReactionAsReply: whatsapp_channel.provider_config['send_reaction_as_reply'], - authToken: whatsapp_channel.provider_config['api_key'] - } - response = HTTParty.post("#{url(whatsapp_channel)}/register", headers: headers(whatsapp_channel), body: body.to_json) + url = url(whatsapp_channel) + Rails.logger.debug { "Connecting #{phone_number} from unoapi with url #{url}" } + body = params(whatsapp_channel.provider_config, phone_number) + response = HTTParty.post("#{url}/register", headers: headers(whatsapp_channel), body: body.to_json) Rails.logger.debug { "Response #{response}" } return send_message(whatsapp_channel) if response.success? @@ -85,8 +65,36 @@ def url(whatsapp_channel) def headers(whatsapp_channel) { - Authorization: GlobalConfigService.load('UNOAPI_AUTH_TOKEN', whatsapp_channel.provider_config['api_key']), + Authorization: ENV.fetch('UNOAPI_AUTH_TOKEN', whatsapp_channel.provider_config['api_key']), 'Content-Type': 'application/json' } end + + # rubocop:disable Metrics/MethodLength + def params(provider_config, phone_number) + { + ignoreGroupMessages: provider_config['ignore_group_messages'], + ignoreBroadcastStatuses: provider_config['ignore_broadcast_statuses'], + ignoreBroadcastMessages: provider_config['ignore_broadcast_messages'], + ignoreHistoryMessages: provider_config['ignore_history_messages'], + ignoreOwnMessages: provider_config['ignore_own_messages'], + ignoreYourselfMessages: provider_config['ignore_yourself_messages'], + sendConnectionStatus: provider_config['send_connection_status'], + notifyFailedMessages: provider_config['notify_failed_messages'], + composingMessage: provider_config['composing_message'], + rejectCalls: provider_config['reject_calls'], + messageCallsWebhook: provider_config['message_calls_webhook'], + webhooks: [ + sendNewMessages: provider_config['webhook_send_new_messages'], + id: 'default', + urlAbsolute: "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/whatsapp/#{phone_number}", + token: provider_config['webhook_verify_token'], + header: :Authorization + ], + sendReactionAsReply: provider_config['send_reaction_as_reply'], + sendProfilePicture: provider_config['send_profile_picture'], + authToken: provider_config['api_key'] + } + end + # rubocop:enable Metrics/MethodLength end diff --git a/db/schema.rb b/db/schema.rb index 52ac374f3..f8c27b2aa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -21,8 +21,8 @@ t.string "owner_type" t.bigint "owner_id" t.string "token" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["owner_type", "owner_id"], name: "index_access_tokens_on_owner_type_and_owner_id" t.index ["token"], name: "index_access_tokens_on_token", unique: true end @@ -32,8 +32,8 @@ t.bigint "user_id" t.integer "role", default: 0 t.bigint "inviter_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.datetime "active_at", precision: nil t.integer "availability", default: 0, null: false t.boolean "auto_offline", default: true, null: false @@ -63,8 +63,8 @@ t.integer "status", default: 0, null: false t.string "message_id", null: false t.string "message_checksum", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["message_id", "message_checksum"], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true end @@ -100,8 +100,8 @@ t.integer "inbox_id" t.integer "agent_bot_id" t.integer "status", default: 0 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "account_id" end @@ -109,8 +109,8 @@ t.string "name" t.string "description" t.string "outgoing_url" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.bigint "account_id" t.integer "bot_type", default: 0 t.jsonb "bot_config", default: {} @@ -121,8 +121,8 @@ t.bigint "account_id", null: false t.bigint "sla_policy_id", null: false t.bigint "conversation_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "sla_status", default: 0 t.index ["account_id", "sla_policy_id", "conversation_id"], name: "index_applied_slas_on_account_sla_policy_conversation", unique: true t.index ["account_id"], name: "index_applied_slas_on_account_id" @@ -140,8 +140,8 @@ t.text "content" t.integer "status" t.integer "views" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.bigint "author_id" t.bigint "associated_article_id" t.jsonb "meta", default: {} @@ -196,8 +196,8 @@ t.string "event_name", null: false t.jsonb "conditions", default: "{}", null: false t.jsonb "actions", default: "{}", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.boolean "active", default: true, null: false t.index ["account_id"], name: "index_automation_rules_on_account_id" end @@ -212,8 +212,8 @@ t.bigint "account_id", null: false t.bigint "inbox_id", null: false t.jsonb "trigger_rules", default: {} - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "campaign_type", default: 0, null: false t.integer "campaign_status", default: 0, null: false t.jsonb "audience", default: [] @@ -240,8 +240,8 @@ t.string "name" t.text "description" t.integer "position" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "locale", default: "en" t.string "slug", null: false t.bigint "parent_category_id" @@ -257,8 +257,8 @@ create_table "channel_api", force: :cascade do |t| t.integer "account_id", null: false t.string "webhook_url" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "identifier" t.string "hmac_token" t.boolean "hmac_mandatory", default: false @@ -271,8 +271,8 @@ t.integer "account_id", null: false t.string "email", null: false t.string "forward_to_email", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.boolean "imap_enabled", default: false t.string "imap_address", default: "" t.integer "imap_port", default: 0 @@ -312,8 +312,8 @@ t.string "line_channel_id", null: false t.string "line_channel_secret", null: false t.string "line_channel_token", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["line_channel_id"], name: "index_channel_line_on_line_channel_id", unique: true end @@ -322,8 +322,8 @@ t.string "phone_number", null: false t.string "provider", default: "default" t.jsonb "provider_config", default: {} - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["phone_number"], name: "index_channel_sms_on_phone_number", unique: true end @@ -331,8 +331,8 @@ t.string "bot_name" t.integer "account_id", null: false t.string "bot_token", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["bot_token"], name: "index_channel_telegram_on_bot_token", unique: true end @@ -341,8 +341,8 @@ t.string "auth_token", null: false t.string "account_sid", null: false t.integer "account_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "medium", default: 0 t.string "messaging_service_sid" t.string "api_key_sid" @@ -356,8 +356,8 @@ t.string "twitter_access_token", null: false t.string "twitter_access_token_secret", null: false t.integer "account_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.boolean "tweets_enabled", default: true t.index ["account_id", "profile_id"], name: "index_channel_twitter_profiles_on_account_id_and_profile_id", unique: true end @@ -387,8 +387,8 @@ t.string "phone_number", null: false t.string "provider", default: "default" t.jsonb "provider_config", default: {} - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.jsonb "message_templates", default: {} t.datetime "message_templates_last_updated", precision: nil t.index ["phone_number"], name: "index_channel_whatsapp_on_phone_number", unique: true @@ -398,8 +398,8 @@ t.bigint "contact_id" t.bigint "inbox_id" t.string "source_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.boolean "hmac_verified", default: false t.string "pubsub_token" t.index ["contact_id"], name: "index_contact_inboxes_on_contact_id" @@ -442,8 +442,8 @@ t.bigint "account_id", null: false t.bigint "user_id", null: false t.bigint "conversation_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_conversation_participants_on_account_id" t.index ["conversation_id"], name: "index_conversation_participants_on_conversation_id" t.index ["user_id", "conversation_id"], name: "index_conversation_participants_on_user_id_and_conversation_id", unique: true @@ -502,8 +502,8 @@ t.text "feedback_message" t.bigint "contact_id", null: false t.bigint "assigned_agent_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_csat_survey_responses_on_account_id" t.index ["assigned_agent_id"], name: "index_csat_survey_responses_on_assigned_agent_id" t.index ["contact_id"], name: "index_csat_survey_responses_on_contact_id" @@ -518,8 +518,8 @@ t.integer "default_value" t.integer "attribute_model", default: 0 t.bigint "account_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.text "attribute_description" t.jsonb "attribute_values", default: [] t.string "regex_pattern" @@ -534,8 +534,8 @@ t.jsonb "query", default: "{}", null: false t.bigint "account_id", null: false t.bigint "user_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_custom_filters_on_account_id" t.index ["user_id"], name: "index_custom_filters_on_user_id" end @@ -545,8 +545,8 @@ t.string "description" t.bigint "account_id", null: false t.text "permissions", default: [], array: true - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_custom_roles_on_account_id" end @@ -555,8 +555,8 @@ t.jsonb "content", default: [] t.bigint "account_id", null: false t.bigint "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_dashboard_apps_on_account_id" t.index ["user_id"], name: "index_dashboard_apps_on_user_id" end @@ -568,8 +568,8 @@ t.text "processing_errors" t.integer "total_records" t.integer "processed_records" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_data_imports_on_account_id" end @@ -579,8 +579,8 @@ t.integer "account_id" t.integer "template_type", default: 1 t.integer "locale", default: 0, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["name", "account_id"], name: "index_email_templates_on_name_and_account_id", unique: true end @@ -588,8 +588,8 @@ t.integer "account_id", null: false t.integer "category_id", null: false t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false end create_table "inbox_members", id: :serial, force: :cascade do |t| @@ -634,8 +634,8 @@ create_table "installation_configs", force: :cascade do |t| t.string "name", null: false t.jsonb "serialized_value", default: {}, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.boolean "locked", default: true, null: false t.index ["name", "created_at"], name: "index_installation_configs_on_name_and_created_at", unique: true t.index ["name"], name: "index_installation_configs_on_name", unique: true @@ -649,8 +649,8 @@ t.integer "hook_type", default: 0 t.string "reference_id" t.string "access_token" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.jsonb "settings", default: {} end @@ -660,8 +660,8 @@ t.string "color", default: "#1f93ff", null: false t.boolean "show_on_sidebar" t.bigint "account_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_labels_on_account_id" t.index ["title", "account_id"], name: "index_labels_on_title_and_account_id", unique: true end @@ -673,8 +673,8 @@ t.bigint "created_by_id" t.bigint "updated_by_id" t.jsonb "actions", default: {}, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_macros_on_account_id" end @@ -683,8 +683,8 @@ t.bigint "conversation_id", null: false t.bigint "account_id", null: false t.datetime "mentioned_at", precision: nil, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_mentions_on_account_id" t.index ["conversation_id"], name: "index_mentions_on_conversation_id" t.index ["user_id", "conversation_id"], name: "index_mentions_on_user_id_and_conversation_id", unique: true @@ -728,8 +728,8 @@ t.bigint "account_id", null: false t.bigint "contact_id", null: false t.bigint "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_notes_on_account_id" t.index ["contact_id"], name: "index_notes_on_contact_id" t.index ["user_id"], name: "index_notes_on_user_id" @@ -739,8 +739,8 @@ t.integer "account_id" t.integer "user_id" t.integer "email_flags", default: 0, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "push_flags", default: 0, null: false t.index ["account_id", "user_id"], name: "by_account_user", unique: true end @@ -749,8 +749,8 @@ t.bigint "user_id", null: false t.integer "subscription_type", null: false t.jsonb "subscription_attributes", default: {}, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.text "identifier" t.index ["identifier"], name: "index_notification_subscriptions_on_identifier", unique: true t.index ["user_id"], name: "index_notification_subscriptions_on_user_id" @@ -765,8 +765,8 @@ t.string "secondary_actor_type" t.bigint "secondary_actor_id" t.datetime "read_at", precision: nil - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.datetime "snoozed_until" t.datetime "last_activity_at", default: -> { "CURRENT_TIMESTAMP" } t.jsonb "meta", default: {} @@ -781,8 +781,8 @@ t.bigint "platform_app_id", null: false t.string "permissible_type", null: false t.bigint "permissible_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["permissible_type", "permissible_id"], name: "index_platform_app_permissibles_on_permissibles" t.index ["platform_app_id", "permissible_id", "permissible_type"], name: "unique_permissibles_index", unique: true t.index ["platform_app_id"], name: "index_platform_app_permissibles_on_platform_app_id" @@ -790,15 +790,15 @@ create_table "platform_apps", force: :cascade do |t| t.string "name", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false end create_table "portal_members", force: :cascade do |t| t.bigint "portal_id" t.bigint "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["portal_id", "user_id"], name: "index_portal_members_on_portal_id_and_user_id", unique: true t.index ["user_id", "portal_id"], name: "index_portal_members_on_user_id_and_portal_id", unique: true end @@ -812,8 +812,8 @@ t.string "homepage_link" t.string "page_title" t.text "header_text" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.jsonb "config", default: {"allowed_locales"=>["en"]} t.boolean "archived", default: false t.bigint "channel_web_widget_id" @@ -833,8 +833,8 @@ create_table "related_categories", force: :cascade do |t| t.bigint "category_id" t.bigint "related_category_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["category_id", "related_category_id"], name: "index_related_categories_on_category_id_and_related_category_id", unique: true t.index ["related_category_id", "category_id"], name: "index_related_categories_on_related_category_id_and_category_id", unique: true end @@ -846,8 +846,8 @@ t.integer "inbox_id" t.integer "user_id" t.integer "conversation_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.float "value_in_business_hours" t.datetime "event_start_time", precision: nil t.datetime "event_end_time", precision: nil @@ -919,8 +919,8 @@ create_table "team_members", force: :cascade do |t| t.bigint "team_id", null: false t.bigint "user_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["team_id", "user_id"], name: "index_team_members_on_team_id_and_user_id", unique: true t.index ["team_id"], name: "index_team_members_on_team_id" t.index ["user_id"], name: "index_team_members_on_user_id" @@ -931,8 +931,8 @@ t.text "description" t.boolean "allow_auto_assign", default: true t.bigint "account_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.index ["account_id"], name: "index_teams_on_account_id" t.index ["name", "account_id"], name: "index_teams_on_name_and_account_id", unique: true end @@ -983,8 +983,8 @@ t.integer "account_id" t.integer "inbox_id" t.string "url" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "webhook_type", default: 0 t.jsonb "subscriptions", default: ["conversation_status_changed", "conversation_updated", "conversation_created", "contact_created", "contact_updated", "message_created", "message_updated", "webwidget_triggered"] t.index ["account_id", "url"], name: "index_webhooks_on_account_id_and_url", unique: true @@ -999,8 +999,8 @@ t.integer "open_minutes" t.integer "close_hour" t.integer "close_minutes" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.boolean "open_all_day", default: false t.index ["account_id"], name: "index_working_hours_on_account_id" t.index ["inbox_id"], name: "index_working_hours_on_inbox_id" From f61a35f73f8c3a5a8df9ebdfc02839501df9b321 Mon Sep 17 00:00:00 2001 From: nestordavalos Date: Tue, 24 Sep 2024 13:26:59 -0400 Subject: [PATCH 3/7] feat: Add support for custom roles This commit adds support for custom roles by modifying the premium_features.yml file. The "custom_roles" feature has been added to the list of premium features. --- Gemfile.lock | 4 +- .../widgets/conversation/ConversationCard.vue | 2 +- .../components/widgets/forms/PhoneInput.vue | 8 +++- .../dashboard/i18n/locale/pt/inboxMgmt.json | 2 +- .../dashboard/i18n/locale/pt/labelsMgmt.json | 6 +-- .../dashboard/i18n/locale/pt/macros.json | 4 +- .../dashboard/i18n/locale/pt/webphone.json | 2 +- .../i18n/locale/pt_BR/labelsMgmt.json | 6 +-- .../shared/components/PhoneInput/helper.js | 13 ++++++ .../widget/components/Form/PhoneInput.vue | 9 +++- app/models/article.rb | 15 ++++++- .../20240923215335_add_locale_to_article.rb | 24 +++++++++++ db/schema.rb | 3 +- enterprise/config/premium_features.yml | 1 + package.json | 4 +- .../v1/accounts/articles_controller_spec.rb | 14 +++++++ spec/factories/articles.rb | 1 + spec/models/article_spec.rb | 19 +++++++++ yarn.lock | 41 +++++++++++-------- 19 files changed, 139 insertions(+), 39 deletions(-) create mode 100644 app/javascript/shared/components/PhoneInput/helper.js create mode 100644 db/migrate/20240923215335_add_locale_to_article.rb diff --git a/Gemfile.lock b/Gemfile.lock index c6b30458b..e962d2382 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -556,7 +556,7 @@ GEM pry-rails (0.3.9) pry (>= 0.10.4) public_suffix (6.0.0) - puma (6.4.2) + puma (6.4.3) nio4r (~> 2.0) pundit (2.3.0) activesupport (>= 3.0.0) @@ -823,7 +823,7 @@ GEM rack-proxy (>= 0.6.1) railties (>= 5.2) semantic_range (>= 2.3.0) - webrick (1.8.1) + webrick (1.8.2) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) diff --git a/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue b/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue index 16d22576b..59ffd661e 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue @@ -306,7 +306,7 @@ export default { icon="call" />

{{ $t('WEBPHONE.VOICE_CALL') }}

-

-

+

-

{{ $t('WEBPHONE.CALLING') }}

import countries from 'shared/constants/countries.js'; import parsePhoneNumber from 'libphonenumber-js'; +import { + getActiveCountryCode, + getActiveDialCode, +} from 'shared/components/PhoneInput/helper'; export default { props: { @@ -30,8 +34,8 @@ export default { selectedIndex: -1, showDropdown: false, searchCountry: '', - activeCountryCode: '', - activeDialCode: '', + activeCountryCode: getActiveCountryCode(), + activeDialCode: getActiveDialCode(), phoneNumber: this.value, }; }, diff --git a/app/javascript/dashboard/i18n/locale/pt/inboxMgmt.json b/app/javascript/dashboard/i18n/locale/pt/inboxMgmt.json index 6feb4929a..8584eca97 100644 --- a/app/javascript/dashboard/i18n/locale/pt/inboxMgmt.json +++ b/app/javascript/dashboard/i18n/locale/pt/inboxMgmt.json @@ -1,6 +1,6 @@ { "INBOX_MGMT": { - "HEADER": "Inboxes", + "HEADER": "Caixas de Entrada", "DESCRIPTION": "A channel is the mode of communication your customer chooses to interact with you. An inbox is where you manage interactions for a specific channel. It can include communications from various sources such as email, live chat, and social media.", "LEARN_MORE": "Learn more about inboxes", "RECONNECTION_REQUIRED": "Your inbox is disconnected. You won't receive new messages until you reauthorize it.", diff --git a/app/javascript/dashboard/i18n/locale/pt/labelsMgmt.json b/app/javascript/dashboard/i18n/locale/pt/labelsMgmt.json index 75b2c7f2b..047d3b0d6 100644 --- a/app/javascript/dashboard/i18n/locale/pt/labelsMgmt.json +++ b/app/javascript/dashboard/i18n/locale/pt/labelsMgmt.json @@ -1,8 +1,8 @@ { "LABEL_MGMT": { - "HEADER": "Labels", - "HEADER_BTN_TXT": "Add label", - "LOADING": "Fetching labels", + "HEADER": "Etiquetas", + "HEADER_BTN_TXT": "Adicionar Etiqueta", + "LOADING": "Buscando etiquetas", "DESCRIPTION": "As etiquetas ajudam a categorizar e priorizar conversas e leads. Pode atribuir uma etiqueta a uma conversa ou contacto usando o painel lateral.", "LEARN_MORE": "Learn more about labels", "SEARCH_404": "Não existem itens que correspondam a esta consulta", diff --git a/app/javascript/dashboard/i18n/locale/pt/macros.json b/app/javascript/dashboard/i18n/locale/pt/macros.json index 7020b6c2c..7c2a68b14 100644 --- a/app/javascript/dashboard/i18n/locale/pt/macros.json +++ b/app/javascript/dashboard/i18n/locale/pt/macros.json @@ -4,8 +4,8 @@ "DESCRIPTION": "Uma macro é um conjunto de ações guardadas que ajudam os agentes de atendimento ao cliente a completar tarefas facilmente. Os agentes podem definir um conjunto de ações como etiquetar uma conversa com um rótulo, enviar uma transcrição por e-mail, atualizar um atributo personalizado, etc., e podem executar essas ações com um único clique.", "LEARN_MORE": "Saiba mais sobre macros", "HEADER_BTN_TXT": "Adicionar uma nova macro", - "HEADER_BTN_TXT_SAVE": "Guardar macro", - "LOADING": "A buscar macros", + "HEADER_BTN_TXT_SAVE": "Salvar macro", + "LOADING": "Procurando macros", "ERROR": "Algo correu mal. Por favor, tente novamente", "ORDER_INFO": "As macros serão executadas na ordem em que adicionar as suas ações. Pode reorganizá-las arrastando-as pela alça ao lado de cada nó.", "ADD": { diff --git a/app/javascript/dashboard/i18n/locale/pt/webphone.json b/app/javascript/dashboard/i18n/locale/pt/webphone.json index 42be44ab3..d7b746b5a 100644 --- a/app/javascript/dashboard/i18n/locale/pt/webphone.json +++ b/app/javascript/dashboard/i18n/locale/pt/webphone.json @@ -1,6 +1,6 @@ { "WEBPHONE": { - "CALL": "Chamada", + "CALL": "Chamar", "TERMINATE": "Terminada", "ACCEPT_ELSEWHERE": "Aceite por outro utilizador", "REJECT_ELSEWHERE": "Rejeitado por outro utilizador", diff --git a/app/javascript/dashboard/i18n/locale/pt_BR/labelsMgmt.json b/app/javascript/dashboard/i18n/locale/pt_BR/labelsMgmt.json index f108cca25..c319caf30 100644 --- a/app/javascript/dashboard/i18n/locale/pt_BR/labelsMgmt.json +++ b/app/javascript/dashboard/i18n/locale/pt_BR/labelsMgmt.json @@ -1,8 +1,8 @@ { "LABEL_MGMT": { - "HEADER": "Labels", - "HEADER_BTN_TXT": "Add label", - "LOADING": "Fetching labels", + "HEADER": "Marcadores", + "HEADER_BTN_TXT": "Adicionar marcador", + "LOADING": "Buscando marcadores", "DESCRIPTION": "Os rótulos ajudam você a categorizar e priorizar conversas e leads. Você pode atribuir um rótulo a uma conversa ou contato usando o painel lateral.", "LEARN_MORE": "Learn more about labels", "SEARCH_404": "Não há itens correspondentes a esta consulta", diff --git a/app/javascript/shared/components/PhoneInput/helper.js b/app/javascript/shared/components/PhoneInput/helper.js new file mode 100644 index 000000000..e80f08cee --- /dev/null +++ b/app/javascript/shared/components/PhoneInput/helper.js @@ -0,0 +1,13 @@ +import { getPhoneCodeByTimezone } from 'timezone-phone-codes'; +import ct from 'countries-and-timezones'; + +const getTimezone = () => Intl.DateTimeFormat().resolvedOptions().timeZone; + +export const getActiveDialCode = () => { + return getPhoneCodeByTimezone(getTimezone()) || ''; +}; + +export const getActiveCountryCode = () => { + const country = ct.getCountryForTimezone(getTimezone()) || {}; + return country.id || ''; +}; diff --git a/app/javascript/widget/components/Form/PhoneInput.vue b/app/javascript/widget/components/Form/PhoneInput.vue index 06929322b..1b7da562d 100644 --- a/app/javascript/widget/components/Form/PhoneInput.vue +++ b/app/javascript/widget/components/Form/PhoneInput.vue @@ -3,6 +3,10 @@ import countries from 'shared/constants/countries.js'; import FluentIcon from 'shared/components/FluentIcon/Index.vue'; import FormulateInputMixin from '@braid/vue-formulate/src/FormulateInputMixin'; import { useDarkMode } from 'widget/composables/useDarkMode'; +import { + getActiveCountryCode, + getActiveDialCode, +} from 'shared/components/PhoneInput/helper'; export default { components: { @@ -28,8 +32,8 @@ export default { selectedIndex: -1, showDropdown: false, searchCountry: '', - activeCountryCode: '', - activeDialCode: '', + activeCountryCode: getActiveCountryCode(), + activeDialCode: getActiveDialCode(), phoneNumber: '', }; }, @@ -322,6 +326,7 @@ export default {