chore: API fixes (#3014)
- Minor API fixes - Configuration screen for LINE inbox
This commit is contained in:
parent
946a09928e
commit
2396b59f11
11 changed files with 76 additions and 16 deletions
|
@ -100,6 +100,7 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_channel_feature_flags
|
def update_channel_feature_flags
|
||||||
|
return unless @inbox.web_widget?
|
||||||
return unless permitted_params(Channel::WebWidget::EDITABLE_ATTRS)[:channel].key? :selected_feature_flags
|
return unless permitted_params(Channel::WebWidget::EDITABLE_ATTRS)[:channel].key? :selected_feature_flags
|
||||||
|
|
||||||
@inbox.channel.selected_feature_flags = permitted_params(Channel::WebWidget::EDITABLE_ATTRS)[:channel][:selected_feature_flags]
|
@inbox.channel.selected_feature_flags = permitted_params(Channel::WebWidget::EDITABLE_ATTRS)[:channel][:selected_feature_flags]
|
||||||
|
|
|
@ -195,6 +195,10 @@
|
||||||
"SUBMIT_BUTTON": "Create LINE Channel",
|
"SUBMIT_BUTTON": "Create LINE Channel",
|
||||||
"API": {
|
"API": {
|
||||||
"ERROR_MESSAGE": "We were not able to save the LINE channel"
|
"ERROR_MESSAGE": "We were not able to save the LINE channel"
|
||||||
|
},
|
||||||
|
"API_CALLBACK": {
|
||||||
|
"TITLE": "Callback URL",
|
||||||
|
"SUBTITLE": "You have to configure the webhook URL in LINE application with the URL mentioned here."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"TELEGRAM_CHANNEL": {
|
"TELEGRAM_CHANNEL": {
|
||||||
|
|
|
@ -88,7 +88,7 @@ export default {
|
||||||
const selectedAgents = this.selectedAgents.map(x => x.id);
|
const selectedAgents = this.selectedAgents.map(x => x.id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await InboxMembersAPI.create({ inboxId, agentList: selectedAgents });
|
await InboxMembersAPI.update({ inboxId, agentList: selectedAgents });
|
||||||
router.replace({
|
router.replace({
|
||||||
name: 'settings_inbox_finish',
|
name: 'settings_inbox_finish',
|
||||||
params: {
|
params: {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<woot-code
|
<woot-code
|
||||||
v-if="isATwilioInbox"
|
v-if="isATwilioInbox"
|
||||||
lang="html"
|
lang="html"
|
||||||
:script="currentInbox.webhook_url"
|
:script="currentInbox.callback_webhook_url"
|
||||||
>
|
>
|
||||||
</woot-code>
|
</woot-code>
|
||||||
</div>
|
</div>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
<woot-code
|
<woot-code
|
||||||
v-if="isALineInbox"
|
v-if="isALineInbox"
|
||||||
lang="html"
|
lang="html"
|
||||||
:script="currentInbox.webhook_url"
|
:script="currentInbox.callback_webhook_url"
|
||||||
>
|
>
|
||||||
</woot-code>
|
</woot-code>
|
||||||
</div>
|
</div>
|
||||||
|
@ -93,6 +93,12 @@ export default {
|
||||||
)}`;
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isALineInbox) {
|
||||||
|
return `${this.$t('INBOX_MGMT.FINISH.MESSAGE')}. ${this.$t(
|
||||||
|
'INBOX_MGMT.ADD.LINE_CHANNEL.API_CALLBACK.SUBTITLE'
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isAEmailInbox) {
|
if (this.isAEmailInbox) {
|
||||||
return this.$t('INBOX_MGMT.ADD.EMAIL_CHANNEL.FINISH_MESSAGE');
|
return this.$t('INBOX_MGMT.ADD.EMAIL_CHANNEL.FINISH_MESSAGE');
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,9 @@
|
||||||
<span v-if="item.channel_type === 'Channel::Telegram'">
|
<span v-if="item.channel_type === 'Channel::Telegram'">
|
||||||
Telegram
|
Telegram
|
||||||
</span>
|
</span>
|
||||||
|
<span v-if="item.channel_type === 'Channel::Line'">
|
||||||
|
Line
|
||||||
|
</span>
|
||||||
<span v-if="item.channel_type === 'Channel::Api'">
|
<span v-if="item.channel_type === 'Channel::Api'">
|
||||||
{{ globalConfig.apiChannelName || 'API' }}
|
{{ globalConfig.apiChannelName || 'API' }}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -259,7 +259,21 @@
|
||||||
:title="$t('INBOX_MGMT.ADD.TWILIO.API_CALLBACK.TITLE')"
|
:title="$t('INBOX_MGMT.ADD.TWILIO.API_CALLBACK.TITLE')"
|
||||||
:sub-title="$t('INBOX_MGMT.ADD.TWILIO.API_CALLBACK.SUBTITLE')"
|
:sub-title="$t('INBOX_MGMT.ADD.TWILIO.API_CALLBACK.SUBTITLE')"
|
||||||
>
|
>
|
||||||
<woot-code :script="twilioCallbackURL" lang="html"></woot-code>
|
<woot-code
|
||||||
|
:script="inbox.callback_webhook_url"
|
||||||
|
lang="html"
|
||||||
|
></woot-code>
|
||||||
|
</settings-section>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="isALineChannel" class="settings--content">
|
||||||
|
<settings-section
|
||||||
|
:title="$t('INBOX_MGMT.ADD.LINE_CHANNEL.API_CALLBACK.TITLE')"
|
||||||
|
:sub-title="$t('INBOX_MGMT.ADD.LINE_CHANNEL.API_CALLBACK.SUBTITLE')"
|
||||||
|
>
|
||||||
|
<woot-code
|
||||||
|
:script="inbox.callback_webhook_url"
|
||||||
|
lang="html"
|
||||||
|
></woot-code>
|
||||||
</settings-section>
|
</settings-section>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="isAWebWidgetInbox">
|
<div v-else-if="isAWebWidgetInbox">
|
||||||
|
@ -398,7 +412,12 @@ export default {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isATwilioChannel || this.isAPIInbox || this.isAnEmailChannel) {
|
if (
|
||||||
|
this.isATwilioChannel ||
|
||||||
|
this.isALineChannel ||
|
||||||
|
this.isAPIInbox ||
|
||||||
|
this.isAnEmailChannel
|
||||||
|
) {
|
||||||
return [
|
return [
|
||||||
...visibleToAllChannelTabs,
|
...visibleToAllChannelTabs,
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,7 @@ export const INBOX_TYPES = {
|
||||||
TWILIO: 'Channel::TwilioSms',
|
TWILIO: 'Channel::TwilioSms',
|
||||||
API: 'Channel::Api',
|
API: 'Channel::Api',
|
||||||
EMAIL: 'Channel::Email',
|
EMAIL: 'Channel::Email',
|
||||||
|
LINE: 'Channel::Line',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -27,6 +28,9 @@ export default {
|
||||||
isATwilioChannel() {
|
isATwilioChannel() {
|
||||||
return this.channelType === INBOX_TYPES.TWILIO;
|
return this.channelType === INBOX_TYPES.TWILIO;
|
||||||
},
|
},
|
||||||
|
isALineChannel() {
|
||||||
|
return this.channelType === INBOX_TYPES.LINE;
|
||||||
|
},
|
||||||
isAnEmailChannel() {
|
isAnEmailChannel() {
|
||||||
return this.channelType === INBOX_TYPES.EMAIL;
|
return this.channelType === INBOX_TYPES.EMAIL;
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,6 +31,7 @@ class Inbox < ApplicationRecord
|
||||||
include Avatarable
|
include Avatarable
|
||||||
include OutOfOffisable
|
include OutOfOffisable
|
||||||
|
|
||||||
|
validates :name, presence: true
|
||||||
validates :account_id, presence: true
|
validates :account_id, presence: true
|
||||||
validates :timezone, inclusion: { in: TZInfo::Timezone.all_identifiers }
|
validates :timezone, inclusion: { in: TZInfo::Timezone.all_identifiers }
|
||||||
|
|
||||||
|
@ -93,9 +94,9 @@ class Inbox < ApplicationRecord
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def webhook_url
|
def callback_webhook_url
|
||||||
case channel_type
|
case channel_type
|
||||||
when 'Channel::TwilioSMS'
|
when 'Channel::TwilioSms'
|
||||||
"#{ENV['FRONTEND_URL']}/twilio/callback"
|
"#{ENV['FRONTEND_URL']}/twilio/callback"
|
||||||
when 'Channel::Line'
|
when 'Channel::Line'
|
||||||
"#{ENV['FRONTEND_URL']}/webhooks/line/#{channel.line_channel_id}"
|
"#{ENV['FRONTEND_URL']}/webhooks/line/#{channel.line_channel_id}"
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
|
# ref : https://developers.line.biz/en/docs/messaging-api/receiving-messages/#webhook-event-types
|
||||||
|
# https://developers.line.biz/en/reference/messaging-api/#message-event
|
||||||
|
|
||||||
class Line::IncomingMessageService
|
class Line::IncomingMessageService
|
||||||
include ::FileTypeHelper
|
include ::FileTypeHelper
|
||||||
pattr_initialize [:inbox!, :params!]
|
pattr_initialize [:inbox!, :params!]
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
|
# probably test events
|
||||||
|
return if params[:events].blank?
|
||||||
|
|
||||||
line_contact_info
|
line_contact_info
|
||||||
|
return if line_contact_info['userId'].blank?
|
||||||
|
|
||||||
set_contact
|
set_contact
|
||||||
set_conversation
|
set_conversation
|
||||||
# TODO: iterate over the events and handle the attachments in future
|
# TODO: iterate over the events and handle the attachments in future
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
json.id resource.id
|
json.id resource.id
|
||||||
|
json.avatar_url resource.try(:avatar_url)
|
||||||
json.channel_id resource.channel_id
|
json.channel_id resource.channel_id
|
||||||
json.name resource.name
|
json.name resource.name
|
||||||
json.channel_type resource.channel_type
|
json.channel_type resource.channel_type
|
||||||
|
@ -6,30 +7,42 @@ json.greeting_enabled resource.greeting_enabled
|
||||||
json.greeting_message resource.greeting_message
|
json.greeting_message resource.greeting_message
|
||||||
json.working_hours_enabled resource.working_hours_enabled
|
json.working_hours_enabled resource.working_hours_enabled
|
||||||
json.enable_email_collect resource.enable_email_collect
|
json.enable_email_collect resource.enable_email_collect
|
||||||
json.out_of_office_message resource.out_of_office_message
|
|
||||||
json.csat_survey_enabled resource.csat_survey_enabled
|
json.csat_survey_enabled resource.csat_survey_enabled
|
||||||
|
json.enable_auto_assignment resource.enable_auto_assignment
|
||||||
|
json.out_of_office_message resource.out_of_office_message
|
||||||
json.working_hours resource.weekly_schedule
|
json.working_hours resource.weekly_schedule
|
||||||
json.timezone resource.timezone
|
json.timezone resource.timezone
|
||||||
json.webhook_url resource.webhook_url
|
json.callback_webhook_url resource.callback_webhook_url
|
||||||
json.avatar_url resource.try(:avatar_url)
|
|
||||||
json.page_id resource.channel.try(:page_id)
|
## Channel specific settings
|
||||||
|
## TODO : Clean up and move the attributes into channel sub section
|
||||||
|
|
||||||
|
## WebWidget Attributes
|
||||||
json.widget_color resource.channel.try(:widget_color)
|
json.widget_color resource.channel.try(:widget_color)
|
||||||
json.website_url resource.channel.try(:website_url)
|
json.website_url resource.channel.try(:website_url)
|
||||||
json.welcome_title resource.channel.try(:welcome_title)
|
json.welcome_title resource.channel.try(:welcome_title)
|
||||||
json.welcome_tagline resource.channel.try(:welcome_tagline)
|
json.welcome_tagline resource.channel.try(:welcome_tagline)
|
||||||
json.enable_auto_assignment resource.enable_auto_assignment
|
|
||||||
json.web_widget_script resource.channel.try(:web_widget_script)
|
json.web_widget_script resource.channel.try(:web_widget_script)
|
||||||
json.website_token resource.channel.try(:website_token)
|
json.website_token resource.channel.try(:website_token)
|
||||||
json.forward_to_email resource.channel.try(:forward_to_email)
|
|
||||||
json.phone_number resource.channel.try(:phone_number)
|
|
||||||
json.selected_feature_flags resource.channel.try(:selected_feature_flags)
|
json.selected_feature_flags resource.channel.try(:selected_feature_flags)
|
||||||
json.reply_time resource.channel.try(:reply_time)
|
json.reply_time resource.channel.try(:reply_time)
|
||||||
json.reauthorization_required resource.channel.try(:reauthorization_required?) if resource.facebook?
|
|
||||||
if resource.web_widget?
|
if resource.web_widget?
|
||||||
json.hmac_token resource.channel.try(:hmac_token)
|
json.hmac_token resource.channel.try(:hmac_token)
|
||||||
json.pre_chat_form_enabled resource.channel.try(:pre_chat_form_enabled)
|
json.pre_chat_form_enabled resource.channel.try(:pre_chat_form_enabled)
|
||||||
json.pre_chat_form_options resource.channel.try(:pre_chat_form_options)
|
json.pre_chat_form_options resource.channel.try(:pre_chat_form_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## Facebook Attributes
|
||||||
|
json.page_id resource.channel.try(:page_id)
|
||||||
|
json.reauthorization_required resource.channel.try(:reauthorization_required?) if resource.facebook?
|
||||||
|
|
||||||
|
## Twilio Attributes
|
||||||
|
json.phone_number resource.channel.try(:phone_number)
|
||||||
|
|
||||||
|
## Email Channel Attributes
|
||||||
|
json.forward_to_email resource.channel.try(:forward_to_email)
|
||||||
json.email resource.channel.try(:email) if resource.email?
|
json.email resource.channel.try(:email) if resource.email?
|
||||||
|
|
||||||
|
## API Channel Attributes
|
||||||
json.webhook_url resource.channel.try(:webhook_url) if resource.api?
|
json.webhook_url resource.channel.try(:webhook_url) if resource.api?
|
||||||
json.inbox_identifier resource.channel.try(:identifier) if resource.api?
|
json.inbox_identifier resource.channel.try(:identifier) if resource.api?
|
||||||
|
|
|
@ -306,6 +306,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response.body).to include('Line Inbox')
|
expect(response.body).to include('Line Inbox')
|
||||||
|
expect(response.body).to include('callback_webhook_url')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -352,7 +353,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
|
|
||||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{api_inbox.id}",
|
patch "/api/v1/accounts/#{account.id}/inboxes/#{api_inbox.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: { enable_auto_assignment: false, channel: { webhook_url: 'webhook.test' } },
|
params: { enable_auto_assignment: false, channel: { webhook_url: 'webhook.test', selected_feature_flags: [] } },
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
|
|
Loading…
Reference in a new issue