-
Notifications
You must be signed in to change notification settings - Fork 0
3. Custom Messaging
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
}
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:
Following are the details of the steps involved:
- Client A sends a donations request to the game server (via a game server API).
- 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).
- Fizz publishes the messages to all clients in the specified channel (Client A and Client B in this scenario).
- 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.
- 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).
- 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.