From 4c43330b15daede342859873baac1468c4e7c4df Mon Sep 17 00:00:00 2001 From: CristianDuta Date: Thu, 3 Nov 2022 03:05:03 +0100 Subject: [PATCH] feat: Add inbox details endpoint (#5549) This change targets the public API and is related to the Inbox with channel type API. Exposes public inbox details under /public/api/v1/inboxes/{inbox_identifier}. This allows access to feature flags and business hours configured for the inbox. ref: #5514 --- .../public/api/v1/inboxes_controller.rb | 6 ++ .../public/api/v1/inboxes/show.json.jbuilder | 3 + .../public/api/v1/models/_inbox.json.jbuilder | 6 ++ .../api/v1/inbox/inboxes_controller_spec.rb | 18 ++++ swagger/definitions/index.yml | 2 + swagger/definitions/resource/public/inbox.yml | 50 +++++++++ swagger/paths/index.yml | 8 ++ swagger/paths/public/inboxes/show.yml | 15 +++ swagger/swagger.json | 102 ++++++++++++++++++ 9 files changed, 210 insertions(+) create mode 100644 app/views/public/api/v1/inboxes/show.json.jbuilder create mode 100644 app/views/public/api/v1/models/_inbox.json.jbuilder create mode 100644 spec/controllers/public/api/v1/inbox/inboxes_controller_spec.rb create mode 100644 swagger/definitions/resource/public/inbox.yml create mode 100644 swagger/paths/public/inboxes/show.yml diff --git a/app/controllers/public/api/v1/inboxes_controller.rb b/app/controllers/public/api/v1/inboxes_controller.rb index a57e72e40..65fad57b1 100644 --- a/app/controllers/public/api/v1/inboxes_controller.rb +++ b/app/controllers/public/api/v1/inboxes_controller.rb @@ -3,9 +3,15 @@ class Public::Api::V1::InboxesController < PublicController before_action :set_contact_inbox before_action :set_conversation + def show + @inbox_channel = ::Channel::Api.find_by!(identifier: params[:id]) + end + private def set_inbox_channel + return if params[:inbox_id].blank? + @inbox_channel = ::Channel::Api.find_by!(identifier: params[:inbox_id]) end diff --git a/app/views/public/api/v1/inboxes/show.json.jbuilder b/app/views/public/api/v1/inboxes/show.json.jbuilder new file mode 100644 index 000000000..e85fcf215 --- /dev/null +++ b/app/views/public/api/v1/inboxes/show.json.jbuilder @@ -0,0 +1,3 @@ +json.identifier @inbox_channel.identifier +json.identity_validation_enabled @inbox_channel.hmac_mandatory +json.partial! 'public/api/v1/models/inbox.json.jbuilder', resource: @inbox_channel.inbox diff --git a/app/views/public/api/v1/models/_inbox.json.jbuilder b/app/views/public/api/v1/models/_inbox.json.jbuilder new file mode 100644 index 000000000..4865976a8 --- /dev/null +++ b/app/views/public/api/v1/models/_inbox.json.jbuilder @@ -0,0 +1,6 @@ +json.name resource.name +json.timezone resource.timezone +json.working_hours resource.weekly_schedule +json.working_hours_enabled resource.working_hours_enabled +json.csat_survey_enabled resource.csat_survey_enabled +json.greeting_enabled resource.greeting_enabled diff --git a/spec/controllers/public/api/v1/inbox/inboxes_controller_spec.rb b/spec/controllers/public/api/v1/inbox/inboxes_controller_spec.rb new file mode 100644 index 000000000..7df7eeb88 --- /dev/null +++ b/spec/controllers/public/api/v1/inbox/inboxes_controller_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe 'Public Inbox API', type: :request do + let!(:api_channel) { create(:channel_api) } + + describe 'GET /public/api/v1/inboxes/{identifier}' do + it 'is able to fetch the details of an inbox' do + get "/public/api/v1/inboxes/#{api_channel.identifier}" + + expect(response).to have_http_status(:success) + data = response.parsed_body + + expect(data.keys).to include('name', 'timezone', 'working_hours', 'working_hours_enabled') + expect(data.keys).to include('csat_survey_enabled', 'greeting_enabled', 'identity_validation_enabled') + expect(data['identifier']).to eq api_channel.identifier + end + end +end diff --git a/swagger/definitions/index.yml b/swagger/definitions/index.yml index 5e4e50b04..ee452ceb6 100644 --- a/swagger/definitions/index.yml +++ b/swagger/definitions/index.yml @@ -58,6 +58,8 @@ public_conversation: $ref: ./resource/public/conversation.yml public_message: $ref: ./resource/public/message.yml +public_inbox: + $ref: ./resource/public/inbox.yml ## ---------- REQUEST------------- ## diff --git a/swagger/definitions/resource/public/inbox.yml b/swagger/definitions/resource/public/inbox.yml new file mode 100644 index 000000000..f94802eae --- /dev/null +++ b/swagger/definitions/resource/public/inbox.yml @@ -0,0 +1,50 @@ +type: object +properties: + identifier: + type: string + description: Inbox identifier + name: + type: string + description: Name of the inbox + timezone: + type: string + description: The timezone defined on the inbox + working_hours: + type: array + description: The working hours defined on the inbox + items: + type: object + properties: + day_of_week: + type: integer + description: Day of the week as a number. Sunday -> 0, Saturday -> 6 + open_all_day: + type: boolean + description: Whether or not the business is open the whole day + closed_all_day: + type: boolean + description: Whether or not the business is closed the whole day + open_hour: + type: integer + description: Opening hour. Can be null if closed all day + open_minutes: + type: integer + description: Opening minute. Can be null if closed all day + close_hour: + type: integer + description: Closing hour. Can be null if closed all day + close_minutes: + type: integer + description: Closing minute. Can be null if closed all day + working_hours_enabled: + type: boolean + description: Whether of not the working hours are enabled on the inbox + csat_survey_enabled: + type: boolean + description: Whether of not the Customer Satisfaction survey is enabled on the inbox + greeting_enabled: + type: boolean + description: Whether of not the Greeting Message is enabled on the inbox + identity_validation_enabled: + type: boolean + description: Whether of not the User Identity Validation is enforced on the inbox diff --git a/swagger/paths/index.yml b/swagger/paths/index.yml index 50b95b5df..56416e1be 100644 --- a/swagger/paths/index.yml +++ b/swagger/paths/index.yml @@ -70,6 +70,14 @@ # ------------ Public API routes ------------# +# Inbox + +/public/api/v1/inboxes/{inbox_identifier}: + parameters: + - $ref: '#/parameters/public_inbox_identifier' + get: + $ref: './public/inboxes/show.yml' + # Contacts /public/api/v1/inboxes/{inbox_identifier}/contacts: diff --git a/swagger/paths/public/inboxes/show.yml b/swagger/paths/public/inboxes/show.yml new file mode 100644 index 000000000..094caabbf --- /dev/null +++ b/swagger/paths/public/inboxes/show.yml @@ -0,0 +1,15 @@ +tags: + - Inbox API +operationId: get-details-of-a-inbox +summary: Inbox details +description: Get the details of an inbox +security: [] +responses: + 200: + description: Success + schema: + $ref: '#/definitions/public_inbox' + 401: + description: Unauthorized + 404: + description: The given inbox does not exist diff --git a/swagger/swagger.json b/swagger/swagger.json index 877fe352d..7a31a56d1 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -691,6 +691,38 @@ } } }, + "/public/api/v1/inboxes/{inbox_identifier}": { + "parameters": [ + { + "$ref": "#/parameters/public_inbox_identifier" + } + ], + "get": { + "tags": [ + "Inbox API" + ], + "operationId": "get-details-of-a-inbox", + "summary": "Inbox details", + "description": "Get the details of an inbox", + "security": [ + + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/public_inbox" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "The given inbox does not exist" + } + } + } + }, "/public/api/v1/inboxes/{inbox_identifier}/contacts": { "parameters": [ { @@ -5470,6 +5502,76 @@ } } }, + "public_inbox": { + "type": "object", + "properties": { + "identifier": { + "type": "string", + "description": "Inbox identifier" + }, + "name": { + "type": "string", + "description": "Name of the inbox" + }, + "timezone": { + "type": "string", + "description": "The timezone defined on the inbox" + }, + "working_hours": { + "type": "array", + "description": "The working hours defined on the inbox", + "items": { + "type": "object", + "properties": { + "day_of_week": { + "type": "integer", + "description": "Day of the week as a number. Sunday -> 0, Saturday -> 6" + }, + "open_all_day": { + "type": "boolean", + "description": "Whether or not the business is open the whole day" + }, + "closed_all_day": { + "type": "boolean", + "description": "Whether or not the business is closed the whole day" + }, + "open_hour": { + "type": "integer", + "description": "Opening hour. Can be null if closed all day" + }, + "open_minutes": { + "type": "integer", + "description": "Opening minute. Can be null if closed all day" + }, + "close_hour": { + "type": "integer", + "description": "Closing hour. Can be null if closed all day" + }, + "close_minutes": { + "type": "integer", + "description": "Closing minute. Can be null if closed all day" + } + } + } + }, + "working_hours_enabled": { + "type": "boolean", + "description": "Whether of not the working hours are enabled on the inbox" + }, + "csat_survey_enabled": { + "type": "boolean", + "description": "Whether of not the Customer Satisfaction survey is enabled on the inbox" + }, + "greeting_enabled": { + "type": "boolean", + "description": "Whether of not the Greeting Message is enabled on the inbox" + }, + "identity_validation_enabled": { + "type": "boolean", + "description": "Whether of not the User Identity Validation is enforced on the inbox" + } + } + }, "account_create_update_payload": { "type": "object", "properties": {