Create Chat Message
Creates a new chat message associated with a specific content item.
Endpoint
POST /api/chat/
Authentication
Authentication is required. The request must include a valid authentication token.
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The content of the chat message |
ContentId | integer | Yes | The ID of the content item to associate the message with |
UserId | string | Yes | The ID of the user creating the message |
parentCommentId | integer | No | The ID of the parent comment if this is a reply |
Example Request Body
{
"message": "This is a great post!",
"ContentId": 4212,
"UserId": "9846"
}
Example Reply Request Body
{
"message": "I agree with your comment!",
"ContentId": 4212,
"UserId": "9846",
"parentCommentId": 123
}
Response
Success Response
Status Code: 200 OK
Response Body: An array containing the created message instance and a success flag:
[
{
"id": 5678,
"message": "This is a great post!",
"deleted": false,
"createdAt": "2023-08-15T14:22:33.000Z",
"updatedAt": "2023-08-15T14:22:33.000Z",
"ContentId": 4212,
"UserId": "9846"
},
true
]
Error Response
Status Code: 400 Bad Request or 500 Internal Server Error
Response Body:
{
"error": "Error message"
}
Notes
- When a chat message is created, a WebSocket notification is sent to all users viewing the same content.
- The response includes the newly created chat message object with all its properties.
- If the message is a reply to another comment, include the
parentCommentIdparameter. - The system supports rich text in the
messagefield, but also stores a plain text version internally.
Example
Request
curl -X POST "https://api.tribesocial.io/api/chat/" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN" \
-d '{
"message": "This is a great post!",
"ContentId": 4212,
"UserId": "9846"
}'
Response
[
{
"id": 5678,
"message": "This is a great post!",
"deleted": false,
"createdAt": "2023-08-15T14:22:33.000Z",
"updatedAt": "2023-08-15T14:22:33.000Z",
"ContentId": 4212,
"UserId": "9846"
},
true
]