Message Count API
This function is created for showing how many messages are in the room by providing the roomId.
REST API
URLs
https://webbackend.stage.watchers.io/message/external/count - dev environment
https://chatbackend.watchers.io/message/external/count - prod environment
Parameters:
Name | type | Description |
---|---|---|
roomiIds | string(Array) | roomID used in the chat initialisation in your App |
apiKey | string | API Key |
Response Example:
[{"count":2,"roomId":"1234"},{"count":0,"roomId":"123"}]
Development stand usage Example:
curl --location --request POST 'https://webbackend.stage.watchers.io/message/external/count' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'roomIds[]={ROOM ID}' \
--data-urlencode 'roomIds[]={ROOM ID}' \
--data-urlencode 'apiKey={API KEY}'
Production stand usage Example:
curl --location --request POST 'https://chatbackend.watchers.io/message/external/count' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'roomIds[]={ROOM ID}' \
--data-urlencode 'roomIds[]={ROOM ID}' \
--data-urlencode 'apiKey={API KEY}'
WS Version
You can connect by WebSockets to URLs below and emit event “listenMessageCount” with parameters
Name | Type | Description |
---|---|---|
roomIds | string(Array) | room id of room which you want to get a last message (Limit 50 rooms) |
apiKey | string | your puclic API key |
And you will receive the events for each room with name “messageCount” every 30 seconds
Urls
https://webbackend.stage.watchers.io - dev environment
https://chatbackend.watchers.io - prod environment
Response (WS payload what you will receive)
Our server will send different events for each room every 30 seconds
(If you provide 50 room ids you will receive 50 events)
//Event 1
{
"roomId": "123",
"count": 2982
}
//Event 2
{
"roomId": "456",
"count": 441
}
Usage example
const socket3 = io("https://webbackend.stage.watchers.io", {
transports: ["websocket"],
upgrade: false,
});
socket3.on("messageCount", (payload) => {
console.log(payload);
});
socket3.on("connect", () => {
socket3.emit("listenMessageCount", {
roomIds: "<ROOM ID>",
apiKey: "<API KEY>",
});
});
Updated 20 days ago