feat: Add an option to enable/disable email collect box (#2399)
* add email collect enabled migration * migrations * expose enable_email_collect field * add select for email collect * add enable_email condition on new conversation * add default value true for enable_email_collect * add specs for email collect enabled * rereun migration * code cleanup * update token life span to 2 months * revert uuid column
This commit is contained in:
parent
8ca63f0b79
commit
b9e40d1452
10 changed files with 56 additions and 7 deletions
|
@ -87,12 +87,12 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
|||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:id, :avatar, :name, :greeting_message, :greeting_enabled, channel:
|
||||
params.permit(:id, :avatar, :name, :greeting_message, :greeting_enabled, :enable_email_collect, channel:
|
||||
[:type, :website_url, :widget_color, :welcome_title, :welcome_tagline, :webhook_url, :email, :reply_time])
|
||||
end
|
||||
|
||||
def inbox_update_params
|
||||
params.permit(:enable_auto_assignment, :name, :avatar, :greeting_message, :greeting_enabled,
|
||||
params.permit(:enable_auto_assignment, :enable_email_collect, :name, :avatar, :greeting_message, :greeting_enabled,
|
||||
:working_hours_enabled, :out_of_office_message, :timezone,
|
||||
channel: [
|
||||
:website_url,
|
||||
|
|
|
@ -212,6 +212,10 @@
|
|||
"AUTO_ASSIGNMENT": {
|
||||
"ENABLED": "Enabled",
|
||||
"DISABLED": "Disabled"
|
||||
},
|
||||
"EMAIL_COLLECT_BOX": {
|
||||
"ENABLED": "Enabled",
|
||||
"DISABLED": "Disabled"
|
||||
}
|
||||
},
|
||||
"DELETE": {
|
||||
|
@ -248,6 +252,8 @@
|
|||
"INBOX_AGENTS": "Agents",
|
||||
"INBOX_AGENTS_SUB_TEXT": "Add or remove agents from this inbox",
|
||||
"UPDATE": "Update",
|
||||
"ENABLE_EMAIL_COLLECT_BOX": "Enable email collect box",
|
||||
"ENABLE_EMAIL_COLLECT_BOX_SUB_TEXT": "Enable or disable email collect box on new conversation",
|
||||
"AUTO_ASSIGNMENT": "Enable auto assignment",
|
||||
"INBOX_UPDATE_TITLE": "Inbox Settings",
|
||||
"INBOX_UPDATE_SUB_TEXT": "Update your inbox settings",
|
||||
|
|
|
@ -138,6 +138,23 @@
|
|||
</p>
|
||||
</label>
|
||||
|
||||
<label v-if="isAWebWidgetInbox" class="medium-9 columns">
|
||||
{{ $t('INBOX_MGMT.SETTINGS_POPUP.ENABLE_EMAIL_COLLECT_BOX') }}
|
||||
<select v-model="emailCollectEnabled">
|
||||
<option :value="true">
|
||||
{{ $t('INBOX_MGMT.EDIT.EMAIL_COLLECT_BOX.ENABLED') }}
|
||||
</option>
|
||||
<option :value="false">
|
||||
{{ $t('INBOX_MGMT.EDIT.EMAIL_COLLECT_BOX.DISABLED') }}
|
||||
</option>
|
||||
</select>
|
||||
<p class="help-text">
|
||||
{{
|
||||
$t('INBOX_MGMT.SETTINGS_POPUP.ENABLE_EMAIL_COLLECT_BOX_SUB_TEXT')
|
||||
}}
|
||||
</p>
|
||||
</label>
|
||||
|
||||
<label class="medium-9 columns">
|
||||
{{ $t('INBOX_MGMT.SETTINGS_POPUP.AUTO_ASSIGNMENT') }}
|
||||
<select v-model="autoAssignment">
|
||||
|
@ -291,6 +308,7 @@ export default {
|
|||
greetingEnabled: true,
|
||||
greetingMessage: '',
|
||||
autoAssignment: false,
|
||||
emailCollectEnabled: false,
|
||||
isAgentListUpdating: false,
|
||||
selectedInboxName: '',
|
||||
channelWebsiteUrl: '',
|
||||
|
@ -432,6 +450,7 @@ export default {
|
|||
this.greetingEnabled = this.inbox.greeting_enabled;
|
||||
this.greetingMessage = this.inbox.greeting_message;
|
||||
this.autoAssignment = this.inbox.enable_auto_assignment;
|
||||
this.emailCollectEnabled = this.inbox.enable_email_collect;
|
||||
this.channelWebsiteUrl = this.inbox.website_url;
|
||||
this.channelWelcomeTitle = this.inbox.welcome_title;
|
||||
this.channelWelcomeTagline = this.inbox.welcome_tagline;
|
||||
|
@ -472,6 +491,7 @@ export default {
|
|||
id: this.currentInboxId,
|
||||
name: this.selectedInboxName,
|
||||
enable_auto_assignment: this.autoAssignment,
|
||||
enable_email_collect: this.emailCollectEnabled,
|
||||
greeting_enabled: this.greetingEnabled,
|
||||
greeting_message: this.greetingMessage || '',
|
||||
channel: {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
# channel_type :string
|
||||
# email_address :string
|
||||
# enable_auto_assignment :boolean default(TRUE)
|
||||
# enable_email_collect :boolean default(TRUE)
|
||||
# greeting_enabled :boolean default(FALSE)
|
||||
# greeting_message :string
|
||||
# name :string not null
|
||||
|
|
|
@ -9,7 +9,7 @@ class MessageTemplates::HookExecutionService
|
|||
# ::MessageTemplates::Template::OutOfOffice.new(conversation: conversation).perform if should_send_out_of_office_message?
|
||||
|
||||
::MessageTemplates::Template::Greeting.new(conversation: conversation).perform if should_send_greeting?
|
||||
::MessageTemplates::Template::EmailCollect.new(conversation: conversation).perform if should_send_email_collect?
|
||||
::MessageTemplates::Template::EmailCollect.new(conversation: conversation).perform if inbox.enable_email_collect && should_send_email_collect?
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -5,6 +5,7 @@ json.channel_type resource.channel_type
|
|||
json.greeting_enabled resource.greeting_enabled
|
||||
json.greeting_message resource.greeting_message
|
||||
json.working_hours_enabled resource.working_hours_enabled
|
||||
json.enable_email_collect resource.enable_email_collect
|
||||
json.out_of_office_message resource.out_of_office_message
|
||||
json.working_hours resource.weekly_schedule
|
||||
json.timezone resource.timezone
|
||||
|
|
|
@ -7,7 +7,7 @@ DeviseTokenAuth.setup do |config|
|
|||
|
||||
# By default, users will need to re-authenticate after 2 weeks. This setting
|
||||
# determines how long tokens will remain valid after they are issued.
|
||||
# config.token_lifespan = 2.weeks
|
||||
config.token_lifespan = 2.months
|
||||
|
||||
# Sets the max number of concurrent devices per user, which is 10 by default.
|
||||
# After this limit is reached, the oldest tokens will be removed.
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddEmailCollectToInboxes < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :inboxes, :enable_email_collect, :boolean, default: true
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_05_27_173755) do
|
||||
ActiveRecord::Schema.define(version: 2021_06_09_133433) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
|
@ -322,6 +322,7 @@ ActiveRecord::Schema.define(version: 2021_05_27_173755) do
|
|||
t.boolean "working_hours_enabled", default: false
|
||||
t.string "out_of_office_message"
|
||||
t.string "timezone", default: "UTC"
|
||||
t.boolean "enable_email_collect", default: true
|
||||
t.index ["account_id"], name: "index_inboxes_on_account_id"
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ describe ::MessageTemplates::HookExecutionService do
|
|||
conversation = create(:conversation, contact: contact)
|
||||
|
||||
# ensure greeting hook is enabled and greeting_message is present
|
||||
conversation.inbox.update(greeting_enabled: true, greeting_message: 'Hi, this is a greeting message')
|
||||
conversation.inbox.update(greeting_enabled: true, enable_email_collect: true, greeting_message: 'Hi, this is a greeting message')
|
||||
|
||||
email_collect_service = double
|
||||
greeting_service = double
|
||||
|
@ -55,7 +55,7 @@ describe ::MessageTemplates::HookExecutionService do
|
|||
contact = create(:contact, email: nil)
|
||||
conversation = create(:conversation, contact: contact)
|
||||
# ensure greeting hook is enabled
|
||||
conversation.inbox.update(greeting_enabled: true)
|
||||
conversation.inbox.update(greeting_enabled: true, enable_email_collect: true)
|
||||
|
||||
email_collect_service = double
|
||||
|
||||
|
@ -70,6 +70,21 @@ describe ::MessageTemplates::HookExecutionService do
|
|||
expect(::MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation)
|
||||
expect(email_collect_service).to have_received(:perform)
|
||||
end
|
||||
|
||||
it 'doesnot calls ::MessageTemplates::Template::EmailCollect when enable_email_collect form is disabled' do
|
||||
contact = create(:contact, email: nil)
|
||||
conversation = create(:conversation, contact: contact)
|
||||
|
||||
conversation.inbox.update(enable_email_collect: false)
|
||||
# ensure prechat form is enabled
|
||||
conversation.inbox.channel.update(pre_chat_form_enabled: true)
|
||||
allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true)
|
||||
|
||||
# described class gets called in message after commit
|
||||
message = create(:message, conversation: conversation)
|
||||
|
||||
expect(::MessageTemplates::Template::EmailCollect).not_to have_received(:new).with(conversation: message.conversation)
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: remove this if this hook is removed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue