The Messaging Service API is the Open Cloud equivalent of the Engine MessagingService, which lets you communicate across your experience's servers and clients. The Engine API only allows you to write and update scripts manually in Studio for publishing messages, but the Open Cloud API lets you send messages to live servers from external tools to automate and improve your operations workflows.
Usage
There are several helpful tools that you can build by supporting cross-server communication with the Messaging Service API, including:
Announcement Portals: A web portal can be helpful to support sending announcements to all users across servers in your experience, such as announcing an upcoming event, an update, and the winner for a competition. On the portal, you can edit a message and click a button that calls the API to send the message out for all users or selected users.
Moderation System: A moderation system can help keep your experience safe and secure. When detecting a user with inappropriate behavior, you can publish a message to trigger the experience server to warn or ban the specific user. You can also use data stores in the moderation system to add user accounts to a blocklist that prevents them from rejoining.
LiveOps Dashboard: LiveOps dashboards are useful tools for managing live events, such as a Halloween party. On the dashboard, you can pre-code an event, update event messages, trigger the event when it's ready, and reward selected users with special items like a virtual crown without updating any of the experience's code.
Limits
Limit | Description |
---|---|
Rate | Roblox throttles message requests at 50 + (5 * number_of_players_in_experience). For example, an experience with 20 players begins to throttle at 150 message requests per minute. |
Topic size | 80 characters |
Message size | 1,024 characters (1 KB) |
Set up a topic for messaging
Before you can publish a message to your experience's live servers, you must set up a topic, which is a customized message channel that is accessible from multiple servers. After defining a topic, you subscribe users to the topic in order to receive your incoming messages.
Currently, you can only define a topic in Studio and use Lua MessagingService:SubscribeAsync() to subscribe users to it. The following code sample subscribes any user to a topic when they join the experience:
Set up and Subscribe Users to a Topic
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
-- Define and subscribe to the topic
local topic = "YourTopic"
local connection = MessagingService:SubscribeAsync(topic, function(message)
print(message.Data)
end)
player.AncestryChanged:Connect(function()
-- Unsubscribe from the topic upon player ancestry change
connection:Disconnect()
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Publish messages to live servers
After setting up a topic, publish a message to your experience's live servers:
Create an API key on Creator Dashboard and copy it somewhere safe. Make sure you perform the following settings:
- Add messaging-service to Access Permissions.
- Select an experience, and add the universe-messaging-service:publish operation.
Get the Universe ID for your experience:
Navigate to the Creator Dashboard.
Find the experience that you want to publish your messages to.
Click the ⋯ button on the target experience's thumbnail to display a list of options, then select Copy Universe ID.
Add the API key and universe to a POST request, as in this example:
Example Request for Publishing a Messagecurl -L -X POST 'https://apis.roblox.com/cloud/v2/universes/{universe}:publishMessage' \-H 'x-api-key: {api-key}' \-H 'Content-Type: application/json' \--data '{"topic": "your-topic","message": "Hello, everyone!"}'Send the HTTP request to publish the message.
Add the Messaging Service API to OAuth 2.0 apps
You can create OAuth 2.0 applications that allow your users to publish messages to their own live servers.
To use Messaging Service API for your application and request permissions from your users, perform the following settings:
When registering your application, under Permissions, select the universe-messaging-service:publish scope.
When implementing the authorization flow, include universe-messaging-service:publish in the scope parameter of the authorization URL that redirects users back to your application, like the following example:
https://authorize.roblox.com?client_id=816547628409595165403873012&redirect_uri=https://my-app.com/redirect&scope=openid+universe-messaging-service:publish&response_type=Code&prompts=login+consent&nonce=12345&state=6789Request access to the universeId of the experience that the user wants to publish their messages to. Your application can send a POST request to the token resources endpoint with the access token, client ID and secret or the code challenge, depending on your implementation of your authorization flow, as request parameters to get a list of universeIds of experiences that the user granted permission to:
Example Requestcurl --location --request POST 'https://apis.roblox.com/oauth/v1/token/resources' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'token=<access_token>' \--data-urlencode 'client_id=<client_id>' \--data-urlencode 'client_secret=<client_secret>'This endpoint returns a list of universeIds like the following example response:
Example Response{"resource_infos": [{"owner": {"id": "1516563360","type": "User"},"resources": {"universe": {"ids": ["3828411582"]}}}]}Your application can now send messages to any experience that a user has granted permission. When sending the request, include the access token in the authorization header and the universeId and topic in the request URI in the following format:
Example Requestcurl --location --request POST 'https://apis.roblox.com/cloud/v2/universes/{universe}:publishMessage' \--header 'Authorization: Bearer <access_token>' \--header 'Content-Type: application/json' \--data-raw '{"topic": "some-topic","message":"message to publish"}'