From d1cbc56d67a8250496fa994de57183181859997f Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Mon, 6 Nov 2023 15:27:29 -0800 Subject: [PATCH] chore: Update widget config API to migrate the widget (#8303) - Update the keys in the widget config API to support loading the widget separately from the Rails App. --- .../v1/widget/configs/create.json.jbuilder | 40 +++++++++++-------- .../api/v1/widget/configs_controller_spec.rb | 2 +- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/views/api/v1/widget/configs/create.json.jbuilder b/app/views/api/v1/widget/configs/create.json.jbuilder index 273a3f975..574ff0e06 100644 --- a/app/views/api/v1/widget/configs/create.json.jbuilder +++ b/app/views/api/v1/widget/configs/create.json.jbuilder @@ -1,29 +1,37 @@ -json.chatwoot_website_channel do +json.website_channel_config do + json.allow_messages_after_resolved @web_widget.inbox.allow_messages_after_resolved + json.allow_reply_to @web_widget.inbox.account.feature_enabled?('message_reply_to') + json.api_host ENV.fetch('FRONTEND_URL', nil) + json.auth_token @token json.avatar_url @web_widget.inbox.avatar_url - json.has_a_connected_agent_bot @web_widget.inbox.agent_bot&.name + json.csat_survey_enabled @web_widget.inbox.csat_survey_enabled + json.disable_branding @web_widget.inbox.account.feature_enabled?('disable_branding') + json.enabled_features @web_widget.selected_feature_flags + json.enabled_languages available_locales_with_name json.locale @web_widget.account.locale + json.out_of_office_message @web_widget.inbox.out_of_office_message + json.portal @web_widget.inbox.portal + json.pre_chat_form_enabled @web_widget.pre_chat_form_enabled + json.pre_chat_form_options @web_widget.pre_chat_form_options + json.reply_time @web_widget.reply_time + json.timezone @web_widget.inbox.timezone + json.utc_off_set ActiveSupport::TimeZone[@web_widget.inbox.timezone].now.formatted_offset json.website_name @web_widget.inbox.name json.website_token @web_widget.website_token json.welcome_tagline @web_widget.welcome_tagline json.welcome_title @web_widget.welcome_title json.widget_color @web_widget.widget_color - json.enabled_features @web_widget.selected_feature_flags - json.enabled_languages available_locales_with_name - json.reply_time @web_widget.reply_time - json.pre_chat_form_enabled @web_widget.pre_chat_form_enabled - json.pre_chat_form_options @web_widget.pre_chat_form_options - json.working_hours_enabled @web_widget.inbox.working_hours_enabled - json.csat_survey_enabled @web_widget.inbox.csat_survey_enabled json.working_hours @web_widget.inbox.working_hours - 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 @web_widget.use_inbox_avatar_for_bot + json.working_hours_enabled @web_widget.inbox.working_hours_enabled end + json.contact do + json.email @contact.email + json.id @contact.id + json.identifier @contact.identifier + json.name @contact.name + json.phone_number @contact.phone_number json.pubsub_token @contact_inbox.pubsub_token end -json.auth_token @token + json.global_config @global_config diff --git a/spec/controllers/api/v1/widget/configs_controller_spec.rb b/spec/controllers/api/v1/widget/configs_controller_spec.rb index 6946af3f1..cea2e55fa 100644 --- a/spec/controllers/api/v1/widget/configs_controller_spec.rb +++ b/spec/controllers/api/v1/widget/configs_controller_spec.rb @@ -10,7 +10,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do describe 'POST /api/v1/widget/config' do let(:params) { { website_token: web_widget.website_token } } - let(:response_keys) { %w[chatwoot_website_channel chatwoot_widget_defaults contact auth_token global_config] } + let(:response_keys) { %w[website_channel_config contact global_config] } context 'with invalid website token' do it 'returns not found' do