HiveMP Chat Quickstart

How did we do?

HiveMP Chat provides you with a scalable real-time solution for text-based messaging in your game. This quickstart will guide you through connecting to the chat endpoint and sending a message to another user.

Create a session

If you don't currently have an active HiveMP session, you'll need to create one as outlined in HiveMP Sessions Quickstart. Once you have a session ID and API key, you can proceed with the guide below.

Add a friend

The account you are sending messages from will need at least one accepted friend account to send messages to. You can create a secondary HiveMP account at the Account Portal for testing purposes. Note down the account ID of the target friend account.

Connect to the WebSocket

In order to use HiveMP Chat, you'll need to connect to the GET /chat/connect WebSocket endpoint. We recommend connecting to this using our official SDKs, as it's not easy to connect to the WebSocket using command-line tools.

Create a chat group

You'll need to create a new chat group or retrieve an existing chat group for the friend you want to send a message to. In order to do that, send a cg (createGroup) message to the WebSocket:

{
  "type": "cg",
  "value": {
    "ids": [
      "YOUR_ACCOUNT_ID",
      "FRIEND_ACCOUNT_ID"
    ]
  }
}

Receive the chat group information

After sending this request, all users that are connected to HiveMP Chat that are part of the group will receive a gi (groupInfo) message that indicates the group ID and the ID of the members in the group:

{
  "type": "gi",
  "value": {
    "id": "cg-5682741632827394",
    "ids": [
      "YOUR_ACCOUNT_ID",
      "FRIEND_ACCOUNT_ID"
    ],
    "t": "Group Title"
  }
}

Send a message to the group

Now that you have the group ID, you can send a message to the group with the mi (sendMessage) request:

{
  "type": "mi",
  "value": {
    "msg": "This is my message.",
    "rid": "cg-5682741632827394",
    "sts": 1534754271
  }
}

Receive a message from the group

When new messages arrive for members of the group, they'll receive a mo (receiveMessage) message from the WebSocket:

{
  "type": "mo",
  "value": {
    "id": "5682741632234522",
    "msg": "This is my message.",
    "rid": "cg-5682741632827394",
    "sid": "u-5682741632827394",
    "sts": 1534754271
  }
}