From f28ec29b8c4c89a85a52ad9c454b342195219ee9 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Sat, 9 May 2020 22:02:43 +0530 Subject: [PATCH] Feature: Customise widget for bot conversations (#834) * Feature: Customise widget for bot conversations --- .env.example | 3 ++ .../api/v1/widget/conversations_controller.rb | 4 ++ app/javascript/shared/components/ChatForm.vue | 5 ++ app/javascript/widget/App.vue | 2 + app/javascript/widget/api/conversation.js | 14 +++++- .../widget/components/AgentMessage.vue | 13 +++-- app/javascript/widget/helpers/actionCable.js | 6 +++ app/javascript/widget/mixins/configMixin.js | 19 +++++++ .../widget/mixins/specs/configMixin.spec.js | 35 +++++++++++++ app/javascript/widget/store/index.js | 2 + .../widget/store/modules/conversation.js | 4 +- .../store/modules/conversationAttributes.js | 49 +++++++++++++++++++ .../conversationAttributes/actions.spec.js | 32 ++++++++++++ .../conversationAttributes/getters.spec.js | 14 ++++++ .../conversationAttributes/mutations.spec.js | 33 +++++++++++++ app/javascript/widget/store/types.js | 2 + app/javascript/widget/views/Home.vue | 32 ++++++++---- app/listeners/action_cable_listener.rb | 6 ++- app/models/agent_bot.rb | 13 ++--- .../widget/conversations/index.json.jbuilder | 5 ++ app/views/widgets/show.html.erb | 5 ++ ...44639_add_hide_input_flag_to_bot_config.rb | 5 ++ db/schema.rb | 3 +- .../widget/conversations_controller_spec.rb | 18 +++++++ 24 files changed, 298 insertions(+), 26 deletions(-) create mode 100644 app/javascript/widget/mixins/configMixin.js create mode 100644 app/javascript/widget/mixins/specs/configMixin.spec.js create mode 100644 app/javascript/widget/store/modules/conversationAttributes.js create mode 100644 app/javascript/widget/store/modules/specs/conversationAttributes/actions.spec.js create mode 100644 app/javascript/widget/store/modules/specs/conversationAttributes/getters.spec.js create mode 100644 app/javascript/widget/store/modules/specs/conversationAttributes/mutations.spec.js create mode 100644 app/views/api/v1/widget/conversations/index.json.jbuilder create mode 100644 db/migrate/20200509044639_add_hide_input_flag_to_bot_config.rb diff --git a/.env.example b/.env.example index b80e3577d..addf9b685 100644 --- a/.env.example +++ b/.env.example @@ -106,3 +106,6 @@ CHARGEBEE_WEBHOOK_PASSWORD= ## generate a new key value here : https://d3v.one/vapid-key-generator/ # VAPID_PUBLIC_KEY= # VAPID_PRIVATE_KEY= + +## Bot Customizations +USE_INBOX_AVATAR_FOR_BOT=true diff --git a/app/controllers/api/v1/widget/conversations_controller.rb b/app/controllers/api/v1/widget/conversations_controller.rb index 8f8e372fe..cdfbd9d4a 100644 --- a/app/controllers/api/v1/widget/conversations_controller.rb +++ b/app/controllers/api/v1/widget/conversations_controller.rb @@ -3,6 +3,10 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController before_action :set_web_widget before_action :set_contact + def index + @conversation = conversation + end + def toggle_typing head :ok && return if conversation.nil? diff --git a/app/javascript/shared/components/ChatForm.vue b/app/javascript/shared/components/ChatForm.vue index 68af0f053..7922595a2 100644 --- a/app/javascript/shared/components/ChatForm.vue +++ b/app/javascript/shared/components/ChatForm.vue @@ -24,6 +24,7 @@ class="button block" type="submit" :disabled="!isFormValid" + :style="{ background: widgetColor, borderColor: widgetColor }" > {{ $t('COMPONENTS.FORM_BUBBLE.SUBMIT') }} @@ -32,6 +33,7 @@ diff --git a/db/migrate/20200509044639_add_hide_input_flag_to_bot_config.rb b/db/migrate/20200509044639_add_hide_input_flag_to_bot_config.rb new file mode 100644 index 000000000..41b9cda56 --- /dev/null +++ b/db/migrate/20200509044639_add_hide_input_flag_to_bot_config.rb @@ -0,0 +1,5 @@ +class AddHideInputFlagToBotConfig < ActiveRecord::Migration[6.0] + def change + add_column :agent_bots, :hide_input_for_bot_conversations, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index fa3f134e0..39280064a 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: 2020_05_04_144712) do +ActiveRecord::Schema.define(version: 2020_05_09_044639) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -94,6 +94,7 @@ ActiveRecord::Schema.define(version: 2020_05_04_144712) do t.string "outgoing_url" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.boolean "hide_input_for_bot_conversations", default: false end create_table "attachments", id: :serial, force: :cascade do |t| diff --git a/spec/controllers/api/v1/widget/conversations_controller_spec.rb b/spec/controllers/api/v1/widget/conversations_controller_spec.rb index 43183a46b..7b3cc6538 100644 --- a/spec/controllers/api/v1/widget/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/widget/conversations_controller_spec.rb @@ -24,4 +24,22 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do end end end + + describe 'POST /api/v1/widget/conversations' do + context 'with a conversation' do + it 'returns the correct conversation params' do + allow(Rails.configuration.dispatcher).to receive(:dispatch) + get '/api/v1/widget/conversations', + headers: { 'X-Auth-Token' => token }, + params: { website_token: web_widget.website_token }, + as: :json + + expect(response).to have_http_status(:success) + json_response = JSON.parse(response.body) + + expect(json_response['id']).to eq(conversation.display_id) + expect(json_response['status']).to eq(conversation.status) + end + end + end end