Notice: All files / modules dependent on Composer.
~$ mkdir -p /path/to/chat-box ; cd /path/to/chat-box \
; git clone git@github.com:froq/chat-box.git . \
; rm -rf .git/ ; composer install
After running the command below, you can test all endpoints with Postman or similar tool through this base URL http://localhost:8000/.
~$ php -S localhost:8000 bin/server.php
~$ vendor/bin/phpunit --bootstrap=./boot.php ./ --colors --testdox
All endpoints work with JSON payloads.
Place a new subscription purchase for a device.
Name | Type | Default | Description |
---|---|---|---|
device_uuid | String | - | Device UUID. |
device_name | String | - | Device name. |
{
"device_uuid": "66b8baa6-7405-4d42-b950-ac2a39cf7196",
"device_name": "Android"
}
{
"status": 200,
"data": {
"id": 4,
"device_uuid": "66b8baa6-7405-4d42-b950-ac2a39cf7196",
"device_name": "Android",
"access_token": "5UZF1ATg2tY0HsE0DFhCS9yptlBBHS4bxri8yWrPY6fVkXDOhrWMIwDHVIGX7QzwOg6ZWCdDISobkPqny3wPRSBepDYuBCeRzhMwogYZGHxIlhslWcFfszeeKRlAVYYs1P4Qm4NGAovE",
"status": "premium",
"credit": 100,
"created_at": "2024-08-11T22:02:43+00:00",
"updated_at": null
},
"error": null
}
400 Bad Request
: If no valid device_uuid
or device_name
provided.
Get an authorization details.
Name | Type | Default | Description |
---|---|---|---|
device_uuid | String | - | Device UUID. |
device_name | String | - | Device name. |
{
"device_uuid": "66b8baa6-7405-4d42-b950-ac2a39cf7196",
"device_name": "Android"
}
{
"status": 200,
"data": {
"device_uuid": "66b8baa6-7405-4d42-b950-ac2a39cf7196",
"device_name": "Android",
"access_token": "5UZF1ATg2tY0HsE0DFhCS9yptlBBHS4bxri8yWrPY6fVkXDOhrWMIwDHVIGX7QzwOg6ZWCdDISobkPqny3wPRSBepDYuBCeRzhMwogYZGHxIlhslWcFfszeeKRlAVYYs1P4Qm4NGAovE",
"status": "premium",
"credit": 100
},
"error": null
}
404 Not Found
: If no authorization found with provided device_uuid
or device_name
.
Get a subscription details.
Name | Type | Default | Description |
---|---|---|---|
Authorization | String | - | From /api/auth (data.access_token ). |
{}
{
"status": 200,
"data": {
"id": 1,
"status": "premium",
"credit": 100
},
"error": null
}
400 Bad Request
: If no valid authorization provided.
404 Not Found
: If no subscription found with provided authorization.
Start or continue a chat.
Name | Type | Default | Description |
---|---|---|---|
Authorization | String | - | From /api/auth (data.access_token ). |
Name | Type | Default | Description |
---|---|---|---|
chat_id | String? | - | From /api/chat (data.id ), to continue with the same chat. |
message | String | - | Chat message. |
{
"chat_id": null,
"message": "Test."
}
{
"chat_id": 1,
"message": "Test again."
}
{
"status": 200,
"data": {
"id": 1,
"pid": null,
"response": "Lorem ipsum dolor.",
"subscription": {
"id": 1,
"status": "premium",
"credit": 99
}
},
"error": null
}
{
"status": 200,
"data": {
"id": 2,
"pid": 1,
"response": "Sit amet etiam in diam ex.",
"subscription": {
"id": 1,
"status": "premium",
"credit": 98
}
},
"error": null
}
400 Bad Request
: If no valid authorization provided.
401 Unauthorized
: If no valid subscription found with provided authorization.
401 Payment Required
: If subscription credits lower than 0 (each chat lowers it by -1).