chore: API fixes (#3014)

- Minor API fixes
- Configuration screen for LINE inbox
This commit is contained in:
Sojan Jose 2021-09-14 22:44:53 +05:30 committed by GitHub
parent 946a09928e
commit 2396b59f11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 76 additions and 16 deletions

View file

@ -100,6 +100,7 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
end
def update_channel_feature_flags
return unless @inbox.web_widget?
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]

View file

@ -195,6 +195,10 @@
"SUBMIT_BUTTON": "Create LINE Channel",
"API": {
"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": {

View file

@ -88,7 +88,7 @@ export default {
const selectedAgents = this.selectedAgents.map(x => x.id);
try {
await InboxMembersAPI.create({ inboxId, agentList: selectedAgents });
await InboxMembersAPI.update({ inboxId, agentList: selectedAgents });
router.replace({
name: 'settings_inbox_finish',
params: {

View file

@ -17,7 +17,7 @@
<woot-code
v-if="isATwilioInbox"
lang="html"
:script="currentInbox.webhook_url"
:script="currentInbox.callback_webhook_url"
>
</woot-code>
</div>
@ -25,7 +25,7 @@
<woot-code
v-if="isALineInbox"
lang="html"
:script="currentInbox.webhook_url"
:script="currentInbox.callback_webhook_url"
>
</woot-code>
</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) {
return this.$t('INBOX_MGMT.ADD.EMAIL_CHANNEL.FINISH_MESSAGE');
}

View file

@ -51,6 +51,9 @@
<span v-if="item.channel_type === 'Channel::Telegram'">
Telegram
</span>
<span v-if="item.channel_type === 'Channel::Line'">
Line
</span>
<span v-if="item.channel_type === 'Channel::Api'">
{{ globalConfig.apiChannelName || 'API' }}
</span>

View file

@ -259,7 +259,21 @@
:title="$t('INBOX_MGMT.ADD.TWILIO.API_CALLBACK.TITLE')"
: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>
</div>
<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 [
...visibleToAllChannelTabs,
{

View file

@ -5,6 +5,7 @@ export const INBOX_TYPES = {
TWILIO: 'Channel::TwilioSms',
API: 'Channel::Api',
EMAIL: 'Channel::Email',
LINE: 'Channel::Line',
};
export default {
@ -27,6 +28,9 @@ export default {
isATwilioChannel() {
return this.channelType === INBOX_TYPES.TWILIO;
},
isALineChannel() {
return this.channelType === INBOX_TYPES.LINE;
},
isAnEmailChannel() {
return this.channelType === INBOX_TYPES.EMAIL;
},

View file

@ -31,6 +31,7 @@ class Inbox < ApplicationRecord
include Avatarable
include OutOfOffisable
validates :name, presence: true
validates :account_id, presence: true
validates :timezone, inclusion: { in: TZInfo::Timezone.all_identifiers }
@ -93,9 +94,9 @@ class Inbox < ApplicationRecord
}
end
def webhook_url
def callback_webhook_url
case channel_type
when 'Channel::TwilioSMS'
when 'Channel::TwilioSms'
"#{ENV['FRONTEND_URL']}/twilio/callback"
when 'Channel::Line'
"#{ENV['FRONTEND_URL']}/webhooks/line/#{channel.line_channel_id}"

View file

@ -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
include ::FileTypeHelper
pattr_initialize [:inbox!, :params!]
def perform
# probably test events
return if params[:events].blank?
line_contact_info
return if line_contact_info['userId'].blank?
set_contact
set_conversation
# TODO: iterate over the events and handle the attachments in future

View file

@ -1,4 +1,5 @@
json.id resource.id
json.avatar_url resource.try(:avatar_url)
json.channel_id resource.channel_id
json.name resource.name
json.channel_type resource.channel_type
@ -6,30 +7,42 @@ 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.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.timezone resource.timezone
json.webhook_url resource.webhook_url
json.avatar_url resource.try(:avatar_url)
json.page_id resource.channel.try(:page_id)
json.callback_webhook_url resource.callback_webhook_url
## 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.website_url resource.channel.try(:website_url)
json.welcome_title resource.channel.try(:welcome_title)
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.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.reply_time resource.channel.try(:reply_time)
json.reauthorization_required resource.channel.try(:reauthorization_required?) if resource.facebook?
if resource.web_widget?
json.hmac_token resource.channel.try(:hmac_token)
json.pre_chat_form_enabled resource.channel.try(:pre_chat_form_enabled)
json.pre_chat_form_options resource.channel.try(:pre_chat_form_options)
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?
## API Channel Attributes
json.webhook_url resource.channel.try(:webhook_url) if resource.api?
json.inbox_identifier resource.channel.try(:identifier) if resource.api?

View file

@ -306,6 +306,7 @@ RSpec.describe 'Inboxes API', type: :request do
expect(response).to have_http_status(:success)
expect(response.body).to include('Line Inbox')
expect(response.body).to include('callback_webhook_url')
end
end
end
@ -352,7 +353,7 @@ RSpec.describe 'Inboxes API', type: :request do
patch "/api/v1/accounts/#{account.id}/inboxes/#{api_inbox.id}",
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
expect(response).to have_http_status(:success)