From 91dc7733b0147c1cb0ebee7b7f28f56617592b8a Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Fri, 7 Apr 2023 13:25:18 -0700 Subject: [PATCH] feat: Use inbox image as avatar for the bot (#6859) --- .env.example | 3 --- .../dashboard/i18n/locale/en/inboxMgmt.json | 3 ++- .../dashboard/settings/inbox/Settings.vue | 11 +++++++++++ .../widget/components/AgentMessage.vue | 10 ++++++---- .../widget/components/UnreadMessage.vue | 3 +++ app/javascript/widget/mixins/configMixin.js | 4 +++- .../widget/mixins/specs/configMixin.spec.js | 18 ++++++++++++------ app/models/channel/web_widget.rb | 1 + .../api/v1/widget/configs/create.json.jbuilder | 3 ++- app/views/widgets/show.html.erb | 3 --- ...91457_migrate_env_var_to_channel_feature.rb | 12 ++++++++++++ db/schema.rb | 2 +- 12 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 db/migrate/20230407191457_migrate_env_var_to_channel_feature.rb diff --git a/.env.example b/.env.example index f098e1a5b..70bf5d588 100644 --- a/.env.example +++ b/.env.example @@ -161,9 +161,6 @@ ANDROID_SHA256_CERT_FINGERPRINT=AC:73:8E:DE:EB:56:EA:CC:10:87:02:A7:65:37:7B:38: # for mobile apps # FCM_SERVER_KEY= -## Bot Customizations -USE_INBOX_AVATAR_FOR_BOT=true - ### APM and Error Monitoring configurations ## Elastic APM ## https://www.elastic.co/guide/en/apm/agent/ruby/current/getting-started-rails.html diff --git a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json index 87ec7a845..8b28d2a3f 100644 --- a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json +++ b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json @@ -439,7 +439,8 @@ "LABEL": "Features", "DISPLAY_FILE_PICKER": "Display file picker on the widget", "DISPLAY_EMOJI_PICKER": "Display emoji picker on the widget", - "ALLOW_END_CONVERSATION": "Allow users to end conversation from the widget" + "ALLOW_END_CONVERSATION": "Allow users to end conversation from the widget", + "USE_INBOX_AVATAR_FOR_BOT": "Use inbox name and avatar for the bot" }, "SETTINGS_POPUP": { "MESSENGER_HEADING": "Messenger Script", diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue index 8011bc5a4..ebee9474d 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue @@ -320,6 +320,17 @@ {{ $t('INBOX_MGMT.FEATURES.ALLOW_END_CONVERSATION') }} +
+ + +
{ test('returns config', () => { const Component = { @@ -51,7 +52,12 @@ describe('configMixin', () => { expect(wrapper.vm.channelConfig).toEqual({ avatarUrl: 'https://test.url', hasAConnectedAgentBot: 'AgentBot', - enabledFeatures: ['emoji_picker', 'attachments', 'end_conversation'], + enabledFeatures: [ + 'emoji_picker', + 'attachments', + 'end_conversation', + 'use_inbox_avatar_for_bot', + ], preChatFormOptions: { pre_chat_message: '', pre_chat_fields: preChatFields, diff --git a/app/models/channel/web_widget.rb b/app/models/channel/web_widget.rb index 59d392892..a75e979b9 100644 --- a/app/models/channel/web_widget.rb +++ b/app/models/channel/web_widget.rb @@ -48,6 +48,7 @@ class Channel::WebWidget < ApplicationRecord has_flags 1 => :attachments, 2 => :emoji_picker, 3 => :end_conversation, + 4 => :use_inbox_avatar_for_bot, :column => 'feature_flags', :check_for_column => false diff --git a/app/views/api/v1/widget/configs/create.json.jbuilder b/app/views/api/v1/widget/configs/create.json.jbuilder index 2a7cf30b1..273a3f975 100644 --- a/app/views/api/v1/widget/configs/create.json.jbuilder +++ b/app/views/api/v1/widget/configs/create.json.jbuilder @@ -18,8 +18,9 @@ json.chatwoot_website_channel do json.out_of_office_message @web_widget.inbox.out_of_office_message json.utc_off_set ActiveSupport::TimeZone[@web_widget.inbox.timezone].now.formatted_offset end +# Remove the following defaults by June 2023 as it would be covered by the feature flags json.chatwoot_widget_defaults do - json.use_inbox_avatar_for_bot ActiveModel::Type::Boolean.new.cast(ENV.fetch('USE_INBOX_AVATAR_FOR_BOT', false)) + json.use_inbox_avatar_for_bot @web_widget.use_inbox_avatar_for_bot end json.contact do json.pubsub_token @contact_inbox.pubsub_token diff --git a/app/views/widgets/show.html.erb b/app/views/widgets/show.html.erb index 70d94bcfc..baa7c6ac1 100644 --- a/app/views/widgets/show.html.erb +++ b/app/views/widgets/show.html.erb @@ -27,9 +27,6 @@ allowMessagesAfterResolved: <%= @web_widget.inbox.allow_messages_after_resolved %>, disableBranding: <%= @web_widget.inbox.account.feature_enabled?('disable_branding') %> } - window.chatwootWidgetDefaults = { - useInboxAvatarForBot: <%= ActiveModel::Type::Boolean.new.cast(ENV.fetch('USE_INBOX_AVATAR_FOR_BOT', false)) %>, - } window.chatwootPubsubToken = '<%= @contact_inbox.pubsub_token %>' window.authToken = '<%= @token %>' window.globalConfig = <%= raw @global_config.to_json %> diff --git a/db/migrate/20230407191457_migrate_env_var_to_channel_feature.rb b/db/migrate/20230407191457_migrate_env_var_to_channel_feature.rb new file mode 100644 index 000000000..3bb9800a3 --- /dev/null +++ b/db/migrate/20230407191457_migrate_env_var_to_channel_feature.rb @@ -0,0 +1,12 @@ +class MigrateEnvVarToChannelFeature < ActiveRecord::Migration[6.1] + def change + return unless ActiveModel::Type::Boolean.new.cast(ENV.fetch('USE_INBOX_AVATAR_FOR_BOT', false)) + + Channel::WebWidget.find_in_batches do |widget_batch| + widget_batch.each do |widget| + widget.use_inbox_avatar_for_bot = true + widget.save! + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index abe45a78c..85938fc68 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_04_04_030719) do +ActiveRecord::Schema.define(version: 2023_04_07_191457) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements"