BeeChat is real-time chat service for Hive built by Hive-Engine. You probably have read the announcement post by @aggroed. If you have a Hive account, you can start chatting immediately with other users from the websites which would implement BeeChat in them.
Hive-Engine is open sourcing BeeChat client website which may help other developers to add chat feature in their website or mobile apps.
BeeChat Demo: https://beechat.hive-engine.com/
BeeChat Client: https://github.com/hive-engine/beechat-frontend
Client website is written in Vue JS, the logic for implementation on other frameworks should be similar. In future we will provide a embed-able chat widget code which will make it very easy to add the chat in any website.
Base URL: https://beechat.hive-engine.com/api
GET /users/loginLogs in a user.
Query Parameters
username: String - Hive username, e.g. reazuliqbalts: Number - Timestamp in miliseconds, e.g. 1601355471900sig: String - Signed username + timestamp using user's posting/active key. e.g. reazuliqbal1601355471900Example Response
{
"username": "reazuliqbal",
"admin": true,
"ws_token": "01EKC3JVR2D81AM8Z9S3Q0NVAJ"
}
GET /users/verifyVerifies if the current access token is valid. If the access token is not valid and there is a refresh token, then a new access token will be issued.
Query Parameters
No parameters are needed.
Example Response
{
"username": "reazuliqbal",
"ws_token": "01EKC3JVR2D81AM8Z9S3Q0NVAJ"
}
GET /users/refresh-tokenRequests a new access token.
Query Parameters
No parameters are needed.
Example Response
{
"username": "reazuliqbal",
"ws_token": "01EKC3JVR2D81AM8Z9S3Q0NVAJ"
}
GET /users/friendsReturns user's friends and blocked list.
Query Parameters
No parameters are needed.
Example Response
{
"friends": ["codebull", "bdcommunity", "aggroed"],
"blocked": ["reazul-dev"]
}
GET /users/friend-requestsReturns an array of user's pending friend requests.
Query Parameters
No parameters are needed.
Example Response
[{
"id": "01EKC46ZMG111C2HYABE80WE8T",
"username": "reazul-dev"
}]
GET /users/settingsReturns user's settings.
Query Parameters
No parameters are needed.
Example Response
{
"dm": {
"only_from_friends": false
}
}
POST /users/settingsUpdates the user's settings.
Payload
dm - Objectonly_from_friends: BooleanExample Response
{
"dm": {
"only_from_friends": false
}
}
GET /users/channelsReturns an array of user-created channels.
Query Parameters
No parameters are needed.
Example Payload
[{
"moderators": [],
"members": ["reazuliqbal"],
"blocked": false,
"type": "channel",
"name": "BDCommunity Chat",
"creator": "reazuliqbal",
"created_at": "2020-09-29T05:17:43.848Z",
"updated_at": "2020-09-29T05:17:43.848Z",
"id": "01EKC4Q317YM484Z7BMVG9Y1K0"
},
....
....
]
POST /users/channelsCreates a new channel.
Payload
name: StringExample Response
{
"id": "01EKC4Q317YM484Z7BMVG9Y1K0",
"name": "BDCommunity Chat",
"creator": "reazuliqbal"
}
GET /users/logoutLogs out the user.
GET /messages/conversationsReturns an array of user's conversations.
Query Parameters
No parameters are needed.
Example Response
[{
"moderators": [],
"members": ["codebull", "reazuliqbal"],
"blocked": false,
"type": "dm",
"creator": "reazuliqbal",
"created_at": "2020-09-29T04:09:31.453Z",
"updated_at": "2020-09-29T04:09:51.596Z",
"id": "01EKC0T6HEVRDP0CYGZAE6VVFR"
},
.....
.....
]
GET /messages/conversationReturns details of a conversation.
Query Parameters
id: String - ID of a conversationids: String - Comma separated IDs of conversationsEither id, or ids is required.
Example Response
{
"moderators": [],
"members": ["codebull", "reazuliqbal"],
"blocked": false,
"type": "dm",
"creator": "reazuliqbal",
"created_at": "2020-09-29T04:09:31.453Z",
"updated_at": "2020-09-29T04:09:51.596Z",
"id": "01EKC0T6HEVRDP0CYGZAE6VVFR"
}
GET /messages/newReturn an array of unread messages.
Query Parameters
No parameters are needed.
Example Response
[{
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR",
"from": "codebull",
"to": "reazuliqbal",
"content": "Whats up?",
"timestamp": "2020-09-29T05:31:56.399Z",
"id": "01EKC5H3KFSWN7FE9XT497HGQT"
},
....
....
]
GET /messages/chatsQuery Parameters
conversation_id: String. Required - Conversation IDbefore: Number. Optional - Timestamp from which to return messageslimit: Number. Optional - Number of messages to returnExample Response
[{
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR",
"from": "reazuliqbal",
"to": "codebull",
"content": "Hey, first message from BeeChat",
"timestamp": "2020-09-29T04:09:31.473Z",
"id": "01EKC0T6JHCGEPGPSMRB3X88RR",
"read": true
}, {
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR",
"from": "codebull",
"to": "reazuliqbal",
"content": "Hey Hey!",
"timestamp": "2020-09-29T04:09:51.617Z",
"id": "01EKC0TT81T2WGRKKYPQRXWGVA",
"read": true
},
....
....
]
Server: wss://ws.beechat.hive-engine.com
A WebSocket server is for two way communication between a server and a user, this facilitates the real-time chatting. As soon as a user connects to the WebSocket server, they should authenticate themselves otherwise the connection will be closed by the server.
The server will only accept JSON message and will also reply in JSON.
Protocol
{
"type": String,
"payload": Object
}
Authenticate the user with the server.
Message
{
"type": "authenticate",
"payload": {}
}
Response
{
"type": "status",
"payload": {
"authenticated": true
}
}
authenticated could be true or false depending on the user's authentication status.
Creates a DM or group conversation.
Payload
to: String (dm) or Array (group)message: StringMessage
// DM
{
"type": "create-conversation",
"payload": {
"to": "reazuliqbal",
"message": "Hi"
}
}
// GROUP
{
"type": "create-conversation",
"payload": {
"to": ["codebull", "reazul-dev"],
"message": "This is a group conversation!"
}
}
Response
The server will respond with two messages. One for the created conversation and one for the new chat message.
{
"type": "conversation-created",
"payload": {
"moderators": [],
"members": ["codebull", "reazul-dev", "reazuliqbal"],
"blocked": false,
"type": "group",
"creator": "reazuliqbal",
"created_at": "2020-09-29T06:16:25.695Z",
"updated_at": "2020-09-29T06:16:25.695Z",
"id": "01EKC82JAMV9JQ1PPG9CNDF3ER"
}
}
{"type":"chat-message","payload":{"id":"01EKC82JBDQD25B94NZRSH2FMX","conversation_id":"01EKC82JAMV9JQ1PPG9CNDF3ER","content":"This is a group conversation!","from":"reazuliqbal","to":null,"read":false,"timestamp":"2020-09-29T06:16:25.709Z"}}
Renames a group conversation. Only the creator can rename a conversation.
Payload
conversation_id: String - ID of the conversation to be renamed.name: String - New nameMessage
{
"type": "rename-conversation",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"name": "The Awesome Group"
}
}
Response
{
"type": "conversation-renamed",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"name": "The Awesome Group"
}
}
Leaves a conversation.
Payload
conversation_id: String - ID of the conversation.Message
{
"type": "leave-conversation",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER"
}
}
Response
To user:
{
"type": "conversation-removed",
"payload": {
"id": "01EKC82JAMV9JQ1PPG9CNDF3ER"
}
}
To all members:
{
"type": "member-left",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"member": "codebull"
}
}
Send a new chat message.
Payload
conversation_id: String - ID of the conversation.to : String (dm) or null (group) - Username of the recipient or nullmessage: String - Message to be sent to the chatMessage
// DM
{
"type": "chat-message",
"payload": {
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR",
"to": "reazuliqbal",
"message": "Hey"
}
}
// GROUP
{
"type": "chat-message",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"to": null,
"message": "Hey!"
}
}
Response
{
"type": "chat-message",
"payload": {
"id": "01EKCA9BWCJXQEPMVF047QQFXW",
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR",
"content": "Hey",
"from": "codebull",
"to": "reazuliqbal",
"read": false,
"timestamp": "2020-09-29T06:55:05.613Z"
}
}
Deletes a message from chat. The sender can delete a message. Creator and Moderators can delete any message from a group chat.
Payload
id: String - ID of the messageMessage
{
"type": "delete-message",
"payload": {
"id": "01EKCAE9KSKTQ7SHX0P0PZZ53Z"
}
}
Response
{
"type": "message-deleted",
"payload": {
"id": "01EKCAE9KSKTQ7SHX0P0PZZ53Z"
}
}
Sets a conversation as read.
Payload
conversation_id: String - ID of the conversationMessage
{
"type": "acknowledgment",
"payload": {
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR"
}
}
Response
{
"type": "acknowledged",
"payload": {
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR"
}
}
Adds a new member to a group conversation. Creator and Moderators can add a new member.
Payload
conversation_id: String - ID of the conversation to be renamed.username: String - New member's Hive usernameMessage
{
"type": "add-member",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"username": "bdcommunity"
}
}
Response
{
"type": "member-added",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"username": "bdcommunity"
}
}
Removes a member from a group conversation. Creator and Moderators can remove a member.
Payload
conversation_id: String - ID of the conversation to be renamed.username: String - Hive username of the member to be removed.Message
{
"type": "remove-member",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"username": "bdcommunity"
}
}
Response
{
"type": "member-removed",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"username": "bdcommunity"
}
}
Adds a new moderator for a group conversation.
Payload
conversation_id: String - ID of the conversation.username: String - Hive username of the member.Message
{
"type": "add-moderator",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"username": "reazul-dev"
}
}
Response
{
"type": "moderator-added",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"username": "reazul-dev"
}
}
Removes a moderator. Only the Creator can remove a moderator.
Payload
conversation_id: String - ID of the conversation.username: String - Hive username of the member.Message
{
"type": "remove-moderator",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"username": "reazul-dev"
}
}
Response
{
"type": "moderator-removed",
"payload": {
"conversation_id": "01EKC82JAMV9JQ1PPG9CNDF3ER",
"username": "reazul-dev"
}
}
Sends a friend request.
Payload
username: String - Hive usernameMessage
{
"type": "request-friendship",
"payload": {
"username": "reazuliqbal"
}
}
Response
{
"type": "friendship-requested",
"payload": {
"id": "01EKCB8D4PVDHBQ4MC7T4JFYAB",
"username": "reazul-dev"
}
}
Accepts a friend request.
Payload
id: String - ID of the friend requestMessage
{
"type": "accept-friendship",
"payload": {
"id": "01EKCB8D4PVDHBQ4MC7T4JFYAB"
}
}
Response
{
"type": "friendship-accepted",
"payload": {
"id": "01EKCB8D4PVDHBQ4MC7T4JFYAB",
"username": "reazul-dev"
}
}
Rejects a friend request.
Payload
id: String - ID of the friend requestMessage
{
"type": "reject-friendship",
"payload": {
"id": "01EKCBKXX88MANDK8FWNQAG8AB"
}
}
Response
{
"type": "friendship-rejected",
"payload": {
"id": "01EKCBKXX88MANDK8FWNQAG8AB"
}
}
Removes a friend.
Payload
username: String - Hive usernameMessage
{
"type": "remove-friendship",
"payload": {
"username": "reazul-dev"
}
}
Response
{
"type": "friendship-removed",
"payload": {
"username": "reazul-dev"
}
}
Blocks a user, blocking a user will remove them from the friend list.
Payload
username: String - Hive usernameMessage
{
"type": "block-user",
"payload": {
"username": "codebull"
}
}
Response
{
"type": "user-blocked",
"payload": {
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR",
"username": "codebull"
}
}
Unblocks a user.
Payload
username: String - Hive usernameMessage
{
"type": "unblock-user",
"payload": {
"username": "codebull"
}
}
Response
{
"type": "user-unblocked",
"payload": {
"username": "codebull",
"conversation_id": "01EKC0T6HEVRDP0CYGZAE6VVFR"
}
}
Server will send reauthentication-required message 1 minute before authentication is about to expire. Do listen to those messages for renewing authentication by requesting a new access token from the /users/refresh-token API endpoint.
Response
{
"type": "reauthentication-required",
"payload": {
"username": "codebull"
}
}
Please note that this service is in Beta. If you find any bug, please report them to me @reazuliqbal (
reazuliqbal#1149). If you need any help in implementing this chat, feel free to contact me on Discord.
I am running a Hive Witness as @BDCommunity.
Please vote for @BDCommunity as a witness.