Skip to content

3. Custom Messaging

Hassan Ali edited this page Nov 1, 2019 · 1 revision

Fizz allows the messaging system to be extended by allowing applications to associate custom data with messages. This allows applications to implement features such as donations, guild notifications, location sharing, polls, etc

Each channel message contains a 'data' field. This field is owned by the application and can be used to store any metadata about the message. For instance, the data field can be used to add custom message types using the following (stringified) JSON payload:

{
  "type": "troop_donation",
  "requester_id": "userA",
  "requested": 40,
  "donated": 0
}

Donations

Some games implement a donations feature which allows users to request donations (cards, troops, etc) from other users through the chat. On receiving a message in the channel requesting donations, other users can donate via the chat UI to the requester.

Normally this feature is implemented using the following scheme:

donation with custom messages

Following are the details of the steps involved:

  1. Client A sends a donations request to the game server (via a game server API).
  2. After validations (whether A can request donations or not), the game server publishes a donations request message in the appropriate channel (the sender can be a user-created specifically for this purpose and used only by the game server).
  3. Fizz publishes the messages to all clients in the specified channel (Client A and Client B in this scenario).
  4. On receiving the message, Client B decides to donate to Client A via the chat UI. This, in return, sends a request to the Game Server to donate to Client A.
  5. After validations (whether B can donate to A or not), the Game Server updates the donations request message by updating the number of donations (1 in this case).
  6. Fizz pushes the message update in the channel which updates the donation count for each client in the channel.

Please note that the donations message can contain any data needed to implement this feature. As an example, something similar the JSON payload above can be used to implement this feature.

Clone this wiki locally