Feature: Inbox greeting message (#927)
Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
@@ -10,7 +10,12 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
channel = web_widgets.create!(permitted_params[:channel].except(:type)) if permitted_params[:channel][:type] == 'web_widget'
|
||||
@inbox = Current.account.inboxes.build(name: permitted_params[:name], channel: channel)
|
||||
@inbox = Current.account.inboxes.build(
|
||||
name: permitted_params[:name],
|
||||
greeting_message: permitted_params[:greeting_message],
|
||||
greeting_enabled: permitted_params[:greeting_enabled],
|
||||
channel: channel
|
||||
)
|
||||
@inbox.avatar.attach(permitted_params[:avatar])
|
||||
@inbox.save!
|
||||
end
|
||||
@@ -56,11 +61,12 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:id, :avatar, :name, channel: [:type, :website_url, :widget_color, :welcome_title, :welcome_tagline, :agent_away_message])
|
||||
params.permit(:id, :avatar, :name, :greeting_message, :greeting_enabled, channel:
|
||||
[:type, :website_url, :widget_color, :welcome_title, :welcome_tagline])
|
||||
end
|
||||
|
||||
def inbox_update_params
|
||||
params.permit(:enable_auto_assignment, :name, :avatar, channel: [:website_url, :widget_color, :welcome_title,
|
||||
:welcome_tagline, :agent_away_message])
|
||||
params.permit(:enable_auto_assignment, :name, :avatar, :greeting_message, :greeting_enabled,
|
||||
channel: [:website_url, :widget_color, :welcome_title, :welcome_tagline])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"LABEL": "Καλώς ήλθατε (Tagline)",
|
||||
"PLACEHOLDER": "Είναι απλό να συνδεθείτε μαζί μας. Ζητήστε μας οτιδήποτε, ή μοιραστείτε την εμπειρία σας."
|
||||
},
|
||||
"CHANNEL_AGENT_AWAY_MESSAGE": {
|
||||
"CHANNEL_GREETING_MESSAGE": {
|
||||
"LABEL": "Μήνυμα όταν δεν υπάρχουν πράκτορες",
|
||||
"PLACEHOLDER": "Τυπικά απαντάμε σε μερικές ώρες."
|
||||
},
|
||||
|
||||
@@ -63,10 +63,16 @@
|
||||
"LABEL": "Welcome Tagline",
|
||||
"PLACEHOLDER": "We make it simple to connect with us. Ask us anything, or share your feedback."
|
||||
},
|
||||
"CHANNEL_AGENT_AWAY_MESSAGE": {
|
||||
"LABEL": "Agents Away Message",
|
||||
"CHANNEL_GREETING_MESSAGE": {
|
||||
"LABEL": "Channel greeting message",
|
||||
"PLACEHOLDER": "Acme Inc typically replies in a few hours."
|
||||
},
|
||||
"CHANNEL_GREETING_TOGGLE": {
|
||||
"LABEL": "Enable channel greeting",
|
||||
"HELP_TEXT": "Send a greeting message to the user when he starts the conversation.",
|
||||
"ENABLED": "Enabled",
|
||||
"DISABLED": "Disabled"
|
||||
},
|
||||
"WIDGET_COLOR": {
|
||||
"LABEL": "Widget Color",
|
||||
"PLACEHOLDER": "Update the widget color used in widget"
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
"LABEL": "Bienvenido Tagline",
|
||||
"PLACEHOLDER": "Facilitamos la conexión con nosotros. Pídanos cualquier cosa o comparte tus comentarios."
|
||||
},
|
||||
"CHANNEL_AGENT_AWAY_MESSAGE": {
|
||||
"CHANNEL_GREETING_MESSAGE": {
|
||||
"LABEL": "Mensaje de Agentes Ausentes",
|
||||
"PLACEHOLDER": "Acme Inc normalmente responde en unas pocas horas."
|
||||
},
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"LABEL": "Slogan d'accueil",
|
||||
"PLACEHOLDER": "C'est simple de rentrer en contact avec nous. Demandez-nous quoi que ce soit ou partagez vos commentaires."
|
||||
},
|
||||
"CHANNEL_AGENT_AWAY_MESSAGE": {
|
||||
"CHANNEL_GREETING_MESSAGE": {
|
||||
"LABEL": "Message lorsque les agents sont absents",
|
||||
"PLACEHOLDER": "Acme Inc répond en général en quelques heures."
|
||||
},
|
||||
|
||||
@@ -54,9 +54,15 @@
|
||||
"LABEL": "Welkom Tagline",
|
||||
"PLACEHOLDER": "We maken het eenvoudig om met ons te verbinden. Vraag ons iets of deel uw feedback."
|
||||
},
|
||||
"CHANNEL_AGENT_AWAY_MESSAGE": {
|
||||
"LABEL": "Agents Afwezig Bericht",
|
||||
"PLACEHOLDER": "Acme Inc reageert meestal binnen een paar uur."
|
||||
"CHANNEL_GREETING_MESSAGE": {
|
||||
"LABEL": "Kanaalbegroeting",
|
||||
"PLACEHOLDER": "Acme Inc antwoordt meestal binnen een paar uur."
|
||||
},
|
||||
"CHANNEL_GREETING_TOGGLE": {
|
||||
"LABEL": "Kanaalbegroeting inschakelen",
|
||||
"HELP_TEXT": "Stuur een begroetingsbericht naar de gebruiker wanneer hij het gesprek start.",
|
||||
"ENABLED": "Ingeschakeld",
|
||||
"DISABLED": "Gehandicapt"
|
||||
},
|
||||
"WIDGET_COLOR": {
|
||||
"LABEL": "Kleur van widget",
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"LABEL": "Bem-vindo Slogan",
|
||||
"PLACEHOLDER": "Nós simplificamos nos conectar com a gente. Pergunte a nós qualquer coisa ou compartilhe seus comentários."
|
||||
},
|
||||
"CHANNEL_AGENT_AWAY_MESSAGE": {
|
||||
"CHANNEL_GREETING_MESSAGE": {
|
||||
"LABEL": "Mensagem Ausente dos Agentes",
|
||||
"PLACEHOLDER": "Acme Inc normalmente responde em algumas horas."
|
||||
},
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"LABEL": "Bem-vindo, saudação",
|
||||
"PLACEHOLDER": "Nós tornamos simples a conexão conosco. Pergunte qualquer assunto ou compartilhe seus comentários."
|
||||
},
|
||||
"CHANNEL_AGENT_AWAY_MESSAGE": {
|
||||
"CHANNEL_GREETING_MESSAGE": {
|
||||
"LABEL": "Mensagem de agente ausente",
|
||||
"PLACEHOLDER": "Acme Inc tipicamente retorna em algumas horas."
|
||||
},
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"LABEL": "Tagline de Bun Venit",
|
||||
"PLACEHOLDER": "Noi facem conectarea cu noi simplă. Întreabă-ne orice, sau partajează-ți feedback-ul."
|
||||
},
|
||||
"CHANNEL_AGENT_AWAY_MESSAGE": {
|
||||
"CHANNEL_GREETING_MESSAGE": {
|
||||
"LABEL": "Mesaj Agent Indisponibil",
|
||||
"PLACEHOLDER": "De obicei, Acme Inc răspunde în câteva ore."
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<woot-input
|
||||
v-if="isAWidgetInbox"
|
||||
v-model.trim="selectedInboxName"
|
||||
class="medium-12 columns"
|
||||
class="medium-9 columns"
|
||||
:label="$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_NAME.LABEL')"
|
||||
:placeholder="
|
||||
$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_NAME.PLACEHOLDER')
|
||||
@@ -27,7 +27,7 @@
|
||||
<woot-input
|
||||
v-if="isAWidgetInbox"
|
||||
v-model.trim="channelWebsiteUrl"
|
||||
class="medium-12 columns"
|
||||
class="medium-9 columns"
|
||||
:label="$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_DOMAIN.LABEL')"
|
||||
:placeholder="
|
||||
$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_DOMAIN.PLACEHOLDER')
|
||||
@@ -36,7 +36,7 @@
|
||||
<woot-input
|
||||
v-if="isAWidgetInbox"
|
||||
v-model.trim="channelWelcomeTitle"
|
||||
class="medium-12 columns"
|
||||
class="medium-9 columns"
|
||||
:label="
|
||||
$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_WELCOME_TITLE.LABEL')
|
||||
"
|
||||
@@ -46,46 +46,61 @@
|
||||
)
|
||||
"
|
||||
/>
|
||||
<woot-input
|
||||
v-if="isAWidgetInbox"
|
||||
v-model.trim="channelWelcomeTagline"
|
||||
class="medium-12 columns"
|
||||
:label="
|
||||
$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_WELCOME_TAGLINE.LABEL')
|
||||
"
|
||||
:placeholder="
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_WELCOME_TAGLINE.PLACEHOLDER'
|
||||
)
|
||||
"
|
||||
/>
|
||||
|
||||
<woot-input
|
||||
v-if="isAWidgetInbox"
|
||||
v-model.trim="channelAgentAwayMessage"
|
||||
class="medium-12 columns"
|
||||
:label="
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_AGENT_AWAY_MESSAGE.LABEL'
|
||||
)
|
||||
"
|
||||
:placeholder="
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_AGENT_AWAY_MESSAGE.PLACEHOLDER'
|
||||
)
|
||||
"
|
||||
/>
|
||||
<label v-if="isAWidgetInbox" class="medium-12 columns">
|
||||
<label v-if="isAWidgetInbox" class="medium-9 columns">
|
||||
{{ $t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.WIDGET_COLOR.LABEL') }}
|
||||
<woot-color-picker v-model="inbox.widget_color" />
|
||||
</label>
|
||||
<label class="medium-12 columns">
|
||||
|
||||
<label class="medium-9 columns">
|
||||
{{
|
||||
$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_TOGGLE.LABEL')
|
||||
}}
|
||||
<select v-model="greetingEnabled">
|
||||
<option :value="true">
|
||||
{{
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_TOGGLE.ENABLED'
|
||||
)
|
||||
}}
|
||||
</option>
|
||||
<option :value="false">
|
||||
{{
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_TOGGLE.DISABLED'
|
||||
)
|
||||
}}
|
||||
</option>
|
||||
</select>
|
||||
<p class="help-text">
|
||||
{{
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_TOGGLE.HELP_TEXT'
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
</label>
|
||||
|
||||
<woot-input
|
||||
v-if="greetingEnabled"
|
||||
v-model.trim="greetingMessage"
|
||||
class="medium-9 columns"
|
||||
:label="
|
||||
$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_MESSAGE.LABEL')
|
||||
"
|
||||
:placeholder="
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_MESSAGE.PLACEHOLDER'
|
||||
)
|
||||
"
|
||||
/>
|
||||
<label class="medium-9 columns">
|
||||
{{ $t('INBOX_MGMT.SETTINGS_POPUP.AUTO_ASSIGNMENT') }}
|
||||
<select v-model="autoAssignment">
|
||||
<option value="true">
|
||||
<option :value="true">
|
||||
{{ $t('INBOX_MGMT.EDIT.AUTO_ASSIGNMENT.ENABLED') }}
|
||||
</option>
|
||||
<option value="false">
|
||||
<option :value="false">
|
||||
{{ $t('INBOX_MGMT.EDIT.AUTO_ASSIGNMENT.DISABLED') }}
|
||||
</option>
|
||||
</select>
|
||||
@@ -183,13 +198,14 @@ export default {
|
||||
avatarFile: null,
|
||||
avatarUrl: '',
|
||||
selectedAgents: [],
|
||||
greetingEnabled: true,
|
||||
greetingMessage: '',
|
||||
autoAssignment: false,
|
||||
isAgentListUpdating: false,
|
||||
selectedInboxName: '',
|
||||
channelWebsiteUrl: '',
|
||||
channelWelcomeTitle: '',
|
||||
channelWelcomeTagline: '',
|
||||
channelAgentAwayMessage: '',
|
||||
autoAssignmentOptions: [
|
||||
{
|
||||
value: true,
|
||||
@@ -247,11 +263,12 @@ export default {
|
||||
this.fetchAttachedAgents();
|
||||
this.avatarUrl = this.inbox.avatar_url;
|
||||
this.selectedInboxName = this.inbox.name;
|
||||
this.greetingEnabled = this.inbox.greeting_enabled;
|
||||
this.greetingMessage = this.inbox.greeting_message;
|
||||
this.autoAssignment = this.inbox.enable_auto_assignment;
|
||||
this.channelWebsiteUrl = this.inbox.website_url;
|
||||
this.channelWelcomeTitle = this.inbox.welcome_title;
|
||||
this.channelWelcomeTagline = this.inbox.welcome_tagline;
|
||||
this.channelAgentAwayMessage = this.inbox.agent_away_message;
|
||||
});
|
||||
},
|
||||
async fetchAttachedAgents() {
|
||||
@@ -294,12 +311,13 @@ export default {
|
||||
id: this.currentInboxId,
|
||||
name: this.selectedInboxName,
|
||||
enable_auto_assignment: this.autoAssignment,
|
||||
greeting_enabled: this.greetingEnabled,
|
||||
greeting_message: this.greetingMessage,
|
||||
channel: {
|
||||
widget_color: this.inbox.widget_color,
|
||||
website_url: this.channelWebsiteUrl,
|
||||
welcome_title: this.channelWelcomeTitle,
|
||||
welcome_tagline: this.channelWelcomeTagline,
|
||||
agent_away_message: this.channelAgentAwayMessage,
|
||||
},
|
||||
};
|
||||
if (this.avatarFile) {
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
/>
|
||||
<woot-loading-state
|
||||
v-if="uiFlags.isCreating"
|
||||
:message="$('INBOX_MGMT.ADD.WEBSITE_CHANNEL.LOADING_MESSAGE')"
|
||||
>
|
||||
</woot-loading-state>
|
||||
:message="$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.LOADING_MESSAGE')"
|
||||
/>
|
||||
<form
|
||||
v-if="!uiFlags.isCreating"
|
||||
class="row"
|
||||
@@ -76,19 +75,43 @@
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-12 columns">
|
||||
<label>
|
||||
<label class="medium-12 columns">
|
||||
{{ $t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_TOGGLE.LABEL') }}
|
||||
<select v-model="greetingEnabled">
|
||||
<option :value="true">
|
||||
{{
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_TOGGLE.ENABLED'
|
||||
)
|
||||
}}
|
||||
</option>
|
||||
<option :value="false">
|
||||
{{
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_TOGGLE.DISABLED'
|
||||
)
|
||||
}}
|
||||
</option>
|
||||
</select>
|
||||
<p class="help-text">
|
||||
{{
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_AGENT_AWAY_MESSAGE.LABEL'
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_TOGGLE.HELP_TEXT'
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
</label>
|
||||
<div v-if="greetingEnabled" class="medium-12 columns">
|
||||
<label>
|
||||
{{
|
||||
$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_MESSAGE.LABEL')
|
||||
}}
|
||||
<input
|
||||
v-model.trim="channelAgentAwayMessage"
|
||||
v-model.trim="greetingMessage"
|
||||
type="text"
|
||||
:placeholder="
|
||||
$t(
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_AGENT_AWAY_MESSAGE.PLACEHOLDER'
|
||||
'INBOX_MGMT.ADD.WEBSITE_CHANNEL.CHANNEL_GREETING_MESSAGE.PLACEHOLDER'
|
||||
)
|
||||
"
|
||||
/>
|
||||
@@ -124,7 +147,8 @@ export default {
|
||||
channelWidgetColor: '#009CE0',
|
||||
channelWelcomeTitle: '',
|
||||
channelWelcomeTagline: '',
|
||||
channelAgentAwayMessage: '',
|
||||
greetingEnabled: false,
|
||||
greetingMessage: '',
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -138,13 +162,14 @@ export default {
|
||||
'inboxes/createWebsiteChannel',
|
||||
{
|
||||
name: this.inboxName,
|
||||
greeting_enabled: this.greetingEnabled,
|
||||
greeting_message: this.greetingMessage,
|
||||
channel: {
|
||||
type: 'web_widget',
|
||||
website_url: this.channelWebsiteUrl,
|
||||
widget_color: this.channelWidgetColor,
|
||||
welcome_title: this.channelWelcomeTitle,
|
||||
welcome_tagline: this.channelWelcomeTagline,
|
||||
agent_away_message: this.channelAgentAwayMessage,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
# id :integer not null, primary key
|
||||
# channel_type :string
|
||||
# enable_auto_assignment :boolean default(TRUE)
|
||||
# greeting_enabled :boolean default(FALSE)
|
||||
# greeting_message :string
|
||||
# name :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
|
||||
@@ -71,11 +71,9 @@ class Message < ApplicationRecord
|
||||
has_many :attachments, dependent: :destroy, autosave: true, before_add: :validate_attachments_limit
|
||||
|
||||
after_create :reopen_conversation,
|
||||
:execute_message_template_hooks,
|
||||
:notify_via_mail
|
||||
|
||||
# we need to wait for the active storage attachments to be available
|
||||
after_create_commit :dispatch_create_events, :send_reply
|
||||
after_create_commit :execute_after_create_commit_callbacks
|
||||
|
||||
after_update :dispatch_update_event
|
||||
|
||||
@@ -117,6 +115,14 @@ class Message < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def execute_after_create_commit_callbacks
|
||||
# rails issue with order of active record callbacks being executed
|
||||
# https://github.com/rails/rails/issues/20911
|
||||
dispatch_create_events
|
||||
send_reply
|
||||
execute_message_template_hooks
|
||||
end
|
||||
|
||||
def dispatch_create_events
|
||||
Rails.configuration.dispatcher.dispatch(MESSAGE_CREATED, Time.zone.now, message: self)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class Facebook::SendReplyService
|
||||
|
||||
def outgoing_message_from_chatwoot?
|
||||
# messages sent directly from chatwoot won't have source_id.
|
||||
message.outgoing? && !message.source_id
|
||||
(message.outgoing? || message.template?) && !message.source_id
|
||||
end
|
||||
|
||||
# def reopen_lock
|
||||
|
||||
@@ -4,6 +4,8 @@ class MessageTemplates::HookExecutionService
|
||||
def perform
|
||||
return if inbox.agent_bot_inbox&.active?
|
||||
|
||||
::MessageTemplates::Template::Greeting.new(conversation: conversation).perform if should_send_greeting?
|
||||
|
||||
::MessageTemplates::Template::EmailCollect.new(conversation: conversation).perform if should_send_email_collect?
|
||||
end
|
||||
|
||||
@@ -16,8 +18,16 @@ class MessageTemplates::HookExecutionService
|
||||
conversation.messages.outgoing.count.zero? && conversation.messages.template.count.zero?
|
||||
end
|
||||
|
||||
def should_send_greeting?
|
||||
first_message_from_contact? && conversation.inbox.greeting_enabled?
|
||||
end
|
||||
|
||||
def email_collect_was_sent?
|
||||
conversation.messages.where(content_type: 'input_email').present?
|
||||
end
|
||||
|
||||
def should_send_email_collect?
|
||||
!contact_has_email? && conversation.inbox.web_widget? && first_message_from_contact?
|
||||
!contact_has_email? && conversation.inbox.web_widget? && !email_collect_was_sent?
|
||||
end
|
||||
|
||||
def contact_has_email?
|
||||
|
||||
@@ -3,7 +3,6 @@ class MessageTemplates::Template::EmailCollect
|
||||
|
||||
def perform
|
||||
ActiveRecord::Base.transaction do
|
||||
conversation.messages.create!(typical_reply_message_params)
|
||||
conversation.messages.create!(ways_to_reach_you_message_params)
|
||||
conversation.messages.create!(email_input_box_template_message_params)
|
||||
end
|
||||
@@ -17,21 +16,6 @@ class MessageTemplates::Template::EmailCollect
|
||||
delegate :contact, :account, to: :conversation
|
||||
delegate :inbox, to: :message
|
||||
|
||||
def typical_reply_message_params
|
||||
content = @conversation.inbox&.channel&.agent_away_message
|
||||
if content.blank?
|
||||
content = I18n.t('conversations.templates.typical_reply_message_body',
|
||||
account_name: account.name)
|
||||
end
|
||||
|
||||
{
|
||||
account_id: @conversation.account_id,
|
||||
inbox_id: @conversation.inbox_id,
|
||||
message_type: :template,
|
||||
content: content
|
||||
}
|
||||
end
|
||||
|
||||
def ways_to_reach_you_message_params
|
||||
content = I18n.t('conversations.templates.ways_to_reach_you_message_body',
|
||||
account_name: account.name)
|
||||
|
||||
32
app/services/message_templates/template/greeting.rb
Normal file
32
app/services/message_templates/template/greeting.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class MessageTemplates::Template::Greeting
|
||||
pattr_initialize [:conversation!]
|
||||
|
||||
def perform
|
||||
ActiveRecord::Base.transaction do
|
||||
conversation.messages.create!(greeting_message_params)
|
||||
end
|
||||
rescue StandardError => e
|
||||
Raven.capture_exception(e)
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
delegate :contact, :account, to: :conversation
|
||||
delegate :inbox, to: :message
|
||||
|
||||
def greeting_message_params
|
||||
content = @conversation.inbox&.greeting_message
|
||||
if content.blank?
|
||||
content = I18n.t('conversations.templates.greeting_message_body',
|
||||
account_name: account.name)
|
||||
end
|
||||
|
||||
{
|
||||
account_id: @conversation.account_id,
|
||||
inbox_id: @conversation.inbox_id,
|
||||
message_type: :template,
|
||||
content: content
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,7 @@ class Twilio::OutgoingMessageService
|
||||
return if message.private
|
||||
return if message.source_id
|
||||
return if inbox.channel.class.to_s != 'Channel::TwilioSms'
|
||||
return unless message.outgoing?
|
||||
return unless outgoing_message?
|
||||
|
||||
twilio_message = client.messages.create(message_params)
|
||||
message.update!(source_id: twilio_message.sid)
|
||||
@@ -39,6 +39,10 @@ class Twilio::OutgoingMessageService
|
||||
@channel ||= inbox.channel
|
||||
end
|
||||
|
||||
def outgoing_message?
|
||||
message.outgoing? || message.template?
|
||||
end
|
||||
|
||||
def client
|
||||
::Twilio::REST::Client.new(channel.account_sid, channel.auth_token)
|
||||
end
|
||||
|
||||
@@ -64,7 +64,7 @@ class Twitter::DirectMessageParserService < Twitter::WebhooksBaseService
|
||||
end
|
||||
|
||||
def set_conversation
|
||||
@conversation = @contact_inbox.conversations.first
|
||||
@conversation = @contact_inbox.conversations.where("additional_attributes ->> 'type' = 'direct_message'").first
|
||||
return if @conversation
|
||||
|
||||
@conversation = ::Conversation.create!(conversation_params)
|
||||
|
||||
@@ -56,7 +56,7 @@ class Twitter::SendReplyService
|
||||
end
|
||||
|
||||
def outgoing_message_from_chatwoot?
|
||||
message.outgoing?
|
||||
(message.outgoing? || message.template?)
|
||||
end
|
||||
|
||||
delegate :additional_attributes, to: :contact
|
||||
|
||||
@@ -2,12 +2,13 @@ json.id @inbox.id
|
||||
json.channel_id @inbox.channel_id
|
||||
json.name @inbox.name
|
||||
json.channel_type @inbox.channel_type
|
||||
json.greeting_enabled @inbox.greeting_enabled
|
||||
json.greeting_message @inbox.greeting_message
|
||||
json.avatar_url @inbox.try(:avatar_url)
|
||||
json.website_token @inbox.channel.try(:website_token)
|
||||
json.widget_color @inbox.channel.try(:widget_color)
|
||||
json.website_url @inbox.channel.try(:website_url)
|
||||
json.welcome_title @inbox.channel.try(:welcome_title)
|
||||
json.welcome_tagline @inbox.channel.try(:welcome_tagline)
|
||||
json.agent_away_message @inbox.channel.try(:agent_away_message)
|
||||
json.web_widget_script @inbox.channel.try(:web_widget_script)
|
||||
json.enable_auto_assignment @inbox.enable_auto_assignment
|
||||
|
||||
@@ -4,13 +4,14 @@ json.payload do
|
||||
json.channel_id inbox.channel_id
|
||||
json.name inbox.name
|
||||
json.channel_type inbox.channel_type
|
||||
json.greeting_enabled inbox.greeting_enabled
|
||||
json.greeting_message inbox.greeting_message
|
||||
json.avatar_url inbox.try(:avatar_url)
|
||||
json.page_id inbox.channel.try(:page_id)
|
||||
json.widget_color inbox.channel.try(:widget_color)
|
||||
json.website_url inbox.channel.try(:website_url)
|
||||
json.welcome_title inbox.channel.try(:welcome_title)
|
||||
json.welcome_tagline inbox.channel.try(:welcome_tagline)
|
||||
json.agent_away_message inbox.channel.try(:agent_away_message)
|
||||
json.enable_auto_assignment inbox.enable_auto_assignment
|
||||
json.web_widget_script inbox.channel.try(:web_widget_script)
|
||||
json.phone_number inbox.channel.try(:phone_number)
|
||||
|
||||
@@ -2,12 +2,13 @@ json.id @inbox.id
|
||||
json.channel_id @inbox.channel_id
|
||||
json.name @inbox.name
|
||||
json.channel_type @inbox.channel_type
|
||||
json.greeting_enabled @inbox.greeting_enabled
|
||||
json.greeting_message @inbox.greeting_message
|
||||
json.avatar_url @inbox.try(:avatar_url)
|
||||
json.website_token @inbox.channel.try(:website_token)
|
||||
json.widget_color @inbox.channel.try(:widget_color)
|
||||
json.website_url @inbox.channel.try(:website_url)
|
||||
json.welcome_title @inbox.channel.try(:welcome_title)
|
||||
json.welcome_tagline @inbox.channel.try(:welcome_tagline)
|
||||
json.agent_away_message @inbox.channel.try(:agent_away_message)
|
||||
json.web_widget_script @inbox.channel.try(:web_widget_script)
|
||||
json.enable_auto_assignment @inbox.enable_auto_assignment
|
||||
|
||||
Reference in New Issue
Block a user