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
This commit is contained in:
parent
8b659de73d
commit
4c43330b15
9 changed files with 210 additions and 0 deletions
|
@ -3,9 +3,15 @@ class Public::Api::V1::InboxesController < PublicController
|
||||||
before_action :set_contact_inbox
|
before_action :set_contact_inbox
|
||||||
before_action :set_conversation
|
before_action :set_conversation
|
||||||
|
|
||||||
|
def show
|
||||||
|
@inbox_channel = ::Channel::Api.find_by!(identifier: params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_inbox_channel
|
def set_inbox_channel
|
||||||
|
return if params[:inbox_id].blank?
|
||||||
|
|
||||||
@inbox_channel = ::Channel::Api.find_by!(identifier: params[:inbox_id])
|
@inbox_channel = ::Channel::Api.find_by!(identifier: params[:inbox_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
3
app/views/public/api/v1/inboxes/show.json.jbuilder
Normal file
3
app/views/public/api/v1/inboxes/show.json.jbuilder
Normal file
|
@ -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
|
6
app/views/public/api/v1/models/_inbox.json.jbuilder
Normal file
6
app/views/public/api/v1/models/_inbox.json.jbuilder
Normal file
|
@ -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
|
|
@ -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
|
|
@ -58,6 +58,8 @@ public_conversation:
|
||||||
$ref: ./resource/public/conversation.yml
|
$ref: ./resource/public/conversation.yml
|
||||||
public_message:
|
public_message:
|
||||||
$ref: ./resource/public/message.yml
|
$ref: ./resource/public/message.yml
|
||||||
|
public_inbox:
|
||||||
|
$ref: ./resource/public/inbox.yml
|
||||||
|
|
||||||
|
|
||||||
## ---------- REQUEST------------- ##
|
## ---------- REQUEST------------- ##
|
||||||
|
|
50
swagger/definitions/resource/public/inbox.yml
Normal file
50
swagger/definitions/resource/public/inbox.yml
Normal file
|
@ -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
|
|
@ -70,6 +70,14 @@
|
||||||
|
|
||||||
# ------------ Public API routes ------------#
|
# ------------ Public API routes ------------#
|
||||||
|
|
||||||
|
# Inbox
|
||||||
|
|
||||||
|
/public/api/v1/inboxes/{inbox_identifier}:
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/parameters/public_inbox_identifier'
|
||||||
|
get:
|
||||||
|
$ref: './public/inboxes/show.yml'
|
||||||
|
|
||||||
# Contacts
|
# Contacts
|
||||||
|
|
||||||
/public/api/v1/inboxes/{inbox_identifier}/contacts:
|
/public/api/v1/inboxes/{inbox_identifier}/contacts:
|
||||||
|
|
15
swagger/paths/public/inboxes/show.yml
Normal file
15
swagger/paths/public/inboxes/show.yml
Normal file
|
@ -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
|
|
@ -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": {
|
"/public/api/v1/inboxes/{inbox_identifier}/contacts": {
|
||||||
"parameters": [
|
"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": {
|
"account_create_update_payload": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
Loading…
Reference in a new issue