API: Chat

Conversation list

Allows to fetch a list of conversations for the current login - based on API: Contact related to API: User (/me) and BrokerStar User (in most cases some Client Manager.)
By default we fetch only unmuted conversations - so ones that have at leas one unmuted message (Unmuted by API: Contact by Chat endpoint.) 

JWT Authorisation

GET /api/v3/chat/conversations

Request parameter:

No Request parameter

Filtering parameters:

No Filtering parameter

Sorting options:

OptionTypeDescription
chat.idintSorting by message id
user.idintSorting by user id
contact.idintSorting by contact id

See API: _ Default behavior # sorting and ordering


Response data:

Metadata: object.

ParameterTypeDescription
countintNumber of all results matching criteria 
statusintResponse status (same as in http code)

Data:  object.data[array]

ParameterTypeDescription
countintCount of un-reeded messaged
user_idint|nullBrokerStar User id / if set to null the sender is a system (system notification)
datestring|dateLast message date

Response (Error):

ParameterTypeDescription
codeintegerAn error code
errorstringA message containing some information about the error 
errorsarrayList of errors devided by field in associative array {field_name:error message}

API: _ Default behavior#Authentication defaults 

Request
curl -X GET https://public.brokerstar.biz/api/v3/chat/unreed --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NTg[...]cm5hbWUiOiJkZW1vLWRlIn0.VTVp[...]cqIg'


Response (Success)
{
    "status": 200,
    "count": 3,
    "data": {
        "0": {
            "user_id": null,
            "count": 4,
            "date": "2023-06-29 22:07:22"
        },
        "1": {
            "user_id": 1,
            "count": 3,
            "date": "2023-06-29 22:26:44"
        },
        "17": {
            "user_id": 17,
            "count": 1,
            "date": "2023-06-29 11:24:23"
        }
    }
}

Or one of 

Un-reeded messages list

Get all un-reeded conversations with count and last message date.

JWT Authorisation

GET /api/v3/chat/conversations

Request parameter:

No Request parameter

Filtering parameters:

No Filtering parameter

Sorting options:

No sorting options

Response data:

Metadata: object.

ParameterTypeDescription
countintNumber of all results matching criteria 
statusintResponse status (same as in http code)

Data:  object.data[array]

ParameterTypeDescription
idintegerLast message id in this conversation
nrstringContact nr 
contactstringContact name (virtual field) - made from name_1 and name_2 
contact_idintAPI: Contact id
userstring|nullBrokerStar User name  / Client Advisor, if set null the sender is a system (system notification) 
user_idint|nullBrokerStar User id / if set to null the sender is a system (system notification)
created_atstrine|dateLast message date

Response (Error):

ParameterTypeDescription
codeintegerAn error code
errorstringA message containing some information about the error 
errorsarrayList of errors devided by field in associative array {field_name:error message}


Conversation messages

By fetching the messages at the same time we are marking them as read and set read_at date in database.

JWT Authorisation

GET /api/v3/chat/messages/{user_id}

Request parameter:

ParameterTypeInMandatoryExampleDescription
user_idint|nullurlYES12user_Id from the conversation list endpoint, if null provided system messages will be returned
limitint|nullQUERYNO10There will be 10 results returned (use only with page parameter)
pageint|nullQUERYNO2Will display 2nd page (use only with limit parameter will display results from 10 to 20, using the formula "start=(page-1)*limit"


Filtering parameters:

ParameterTypeINExampleDescription
last_idintegerQUERYfilters[last_id]=34Get only messages with id > value
created_afterstring|dateQUERYfilters[created_after]=2023-01-31T15:59:41+01:00Get only messages with created_at > value





Response data:

Metadata: object.

ParameterTypeDescription
statusintResponse status (same as in HTTP code)
countintNumber of results returned by request
totalintNumber of total results matching criteria
pageint|nullIf the pager used → the current page
limitint|nullif the pager used → the current limit

Data:  object.data

ParameterOut TypeDescription
idintegerChat message id
from_userbooleanContact nr
messagestring

Chat messages can contain BB code tags sent by Js plugin https://github.com/jordandelozier/wysibb eg:
\[b] bold \[\b]

created_atstring|dateChat message creation date (in db)
readboolIf the message was read by second parties based on from_user parameter.
read_atstring|nullDateTime of reading this chat message

Response (Error):

ParameterTypeDescription
codeintegerAn error code
errorstringA message containing some information about the error 
errorsarrayList of errors devided by field in associative array {field_name:error message}
Request
curl -X GET https://public.brokerstar.biz/api/v3/chat/messages/1 --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NTg[...]cm5hbWUiOiJkZW1vLWRlIn0.VTVp[...]cqIg'


Response (Success)
200 OK  
{
    "status": 200,
    "count": 19,
	"total": 29,
    "page": 2,
    "limit": 3,
    "data": [
        {
            "id": 38,
            "from_user": true,
            "message": "First message",
            "created_at": "2023-02-01T08:34:14+01:00",
            "read": true,
            "read_at": "2023-02-05T07:16:57+01:00"
        },
        {
            "id": 41,
            "from_user": false,
            "message": "Reply [b]bold text[/b]",
            "created_at": "2023-02-01T08:54:28+01:00",
            "read": true,
            "read_at": "2023-02-05T07:16:57+01:00"
        },
        {
            "id": 42,
            "from_user": true,
            "message": "Other message",
            "created_at": "2023-02-01T08:55:47+01:00",
            "read": true,
            "read_at": "2023-02-05T07:16:57+01:00"
        },
		[....]	
}

Or one of 

Get flooded chat

This endpoint provides all messages related to contact_id (Contact related to API: User API: Contact) not regarding the sender.

JWT Authorisation

GET /api/v3/chat/flooded

Request parameter:

No request parameters

Filtering parameters:

ParameterTypeINExampleDescription
last_idintegerQUERYfilters[last_id]=34Get only messages with id > value
created_afterstring|dateQUERYfilters[created_after]=2023-01-31T15:59:41+01:00Get only messages with created_at > value





Response data:

Metadata: object.

ParameterTypeDescription
statusintResponse status (same as in http code)

Data:  object.data

ParameterOut TypeDescription
idintegerChat message id
from_userbooleanContact nr
messagestring

Chat messages can contain BB code tags sent by Js plugin https://github.com/jordandelozier/wysibb eg:
\[b] bold \[\b]

created_atstring|dateChat message creation date (in db)
readboolIf the message was read by second parties based on from_user parameter.
read_atstring|nullDateTime of reading this chat message
user_namestring|nullUser/Client Advisor name - or if null system message
user_idstring|nullUser/Client Advisor id - or if null system message

Response (Error):

ParameterTypeDescription
codeintegerAn error code
errorstringA message containing some information about the error 
errorsarrayList of errors devided by field in associative array {field_name:error message}
Request
curl -X GET https://public.brokerstar.biz/api/v3/chat/flooded  --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NTg[...]cm5hbWUiOiJkZW1vLWRlIn0.VTVp[...]cqIg'
Response (Success)
200 OK   
{
    "status": 200,
    "count": 25,
    "data": [
        {
            "id": 2,
            "from_user": true,
            "message": "Welcome to system",
            "created_at": "2023-01-30T14:06:58+01:00",
            "read": true,
            "read_at": "2023-02-05T07:33:50+01:00",
            "user": null,
            "user_id": null
        },
        {
            "id": 3,
            "from_user": true,
            "message": "Hello this is Your Client Advisor [b]User Known[/] how can i help You ?",
            "created_at": "2023-01-30T14:12:18+01:00",
            "read": true,
            "read_at": "2023-02-05T07:33:50+01:00",
            "user": "User Known",
            "user_id": 1
        },

Or one of 

Post Message

Send new chat message as a Contact (from_user=false)

JWT Authorisation

POST /api/v3/chat

JSON parameters:

Parameter

Type

IN

Description

messagestring(1500)JSON DATAMessage can contain BBCode supported by  https://github.com/jordandelozier/wysibb plugin.
All HTML tags will be removed by strip_tags php function
userintJSON DATAWe always need to provide user/ClientAdvisor You can get them from Conversation List or aggregate from the flooded chat user/user_id field.

Response data:

ParameterOut TypeDescription
idintegerChat message id
from_userbooleanContact nr
messagestring

Chat messages can contain BB code tags sent by Js plugin https://github.com/jordandelozier/wysibb eg:
\[b] bold \[\b]

created_atstring|dateChat message creation date (in db)

Response (Error):

ParameterTypeDescription
codeintegerAn error code
errorstringA message containing some information about the error 
errorsarrayList of errors devided by field in associative array {field_name:error message}
Request
curl -X POST https://public.brokerstar.biz/api/v3/chat --data-raw '{
    "message":"This is some new message with [b] bbCode[/b]",
    "user": 1
}'
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NTg[...]cm5hbWUiOiJkZW1vLWRlIn0.VTVp[...]cqIg'
Response (Success)
200 OK   
{
	"id": 12312
    "fromUser": 0,
    "message": "This is some new message with [b] bbCode[/b]",
    "createdAt": {
        "date": "2023-02-05 19:44:59.837279",
        "timezone_type": 3,
        "timezone": "Europe/Zurich"
    }
}

Or one of 

Mute conversation

JWT Authorisation

GET /api/v3/chat/mute/{user_id}

Request parameter:

Filtering parameters:

Parameter

Type

IN

Example

Description

user_Idint|nullQUERY1

Mute conversation with user with id=user_id if null mute system_messages, Attention: if a new message is sent to or from this user conversation will be un-muted.

Response data:

Response (Error):

Parameter

Type

Description

codeintegerAn error code
errorstringA message containing some information about the error 
errorsarrayList of errors devided by field in associative array {field_name:error message}
Request
curl -X GET https://public.brokerstar.biz/api/v3/chat/mute/1 --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NTg[...]cm5hbWUiOiJkZW1vLWRlIn0.VTVp[...]cqIg'
Response (Success)
200 OK 
{
   
}

Or one of