Messaging is one of the core features of the GameSparks platform. Messages are primarily used to keep your players informed about events within your game, as those events occur.
Message Use Cases
This diagram shows several messaging use cases in action:
Messages within GameSparks are entirely cross-platform - it doesn't matter what client your players are using they will receive the messages, even if they originate from a player on a different platform.
There are two mechanisms that the GameSparks platform uses to deliver messages to a player, depending on the state of the message recipient:
1. Online Player
As well as using WebSockets for standard request/response use-cases, the GameSparks platform also uses WebSockets for delivering asynchronous messages. This means that an online player will receive any messages sent to them almost instantly.
In the above diagram 'Offline Player' represents a player without an authenticated WebSocket connection. All the other players currently have authenticated WebSocket connections, so receive their messages as they are sent, via the WebSocket.
2. Offline Player
The GameSparks platform allows you to set up a Game to use push notifications where they are supported on the players' devices. The set up for these notifications varies depending on the target device, so some configuration is required for your game within the GameSparks developer portal to get these notifications to work.
In addition to the configuration, the players' devices must be registered to receive push notifications, which can be done using a PushRegistrationRequest. When a message is sent to a player who does not have an authenticated WebSocket connection, the GameSparks platform will send a notification to all of the players' devices that have been registered to receive a push notification.
There are three types of trigger that you can use to send a message:
1. Request Message
Requests such as SendFriendMessageRequest and ChatOnChallengeRequest are explicit calls to the platform to send requests to the target players. The content of the message is determined by the sender of the request.
2. Event Message
Certain events that occur within the platform will trigger a message to be sent to the relevant players. For example, a message will be sent to a player:
- When they post a new high score on a Leaderboard.
- Once a Challenge they are participating in has officially started.
The content of these sorts of messages is determined by message templates that you can configure within the GameSparks developer portal.
3. Script Message
Like the Request messages, this is an explicit call to the platform to send a message to the target players. In this case, the message is created using Spark.message and then can be sent using SparkMessage.send.
Messages and Cloud Code
You can also tie Cloud Code scripts to the sending of messages to further customize the platform behavior. For more information on this see Cloud Code.
Setting Up Messaging? For details on how to set up messaging for your game, see the Messages page.
FAQs? You can review Frequently Asked Questions about working with Messages.