A simple "Message Of The Day" implementation for gaming clients, using Azure Functions and Azure Table Storage for the backend storage. Functions are implemented in Node.js.
Click the following button to deploy the project to your Azure subscription:
This operation will trigger a template deployment of the deploy.json and deploy.function.json ARM template files to your Azure subscription, which will create the necessary Azure resources, the required environment variables as well as pull the source code from this repository (or your fork).
The Message Of The Day API is served by Azure Functions whereas the storage is implemented using Azure Table Storage, thus making this solution pretty inexpensive. The name of the Table Storage table is a random string plus the string 'messages' (e.g. 'aj7pc3e5tixr4messages'). The Function App contains 3 Functions, all of which are HTTP triggered:
- sampleadd: you can call this Function to add 3 sample messages for your game. Use for demo purposed and/or to check if your deployment is actually working (GET)
- getmessages: this Function will return the list of messages in JSON format, similar to the following (GET):
[
{
"message":"message2",
"title":"title2",
"priority":1,
"isActive":true
},
{
"message":"message3",
"title":"title3",
"priority":2,
"isActive":true
},
{
"message":"message1",
"title":"title1",
"priority":100,
"from":"2018-07-17T00:00:00Z",
"to":"2018-07-19T00:00:00Z",
"isActive":false
}
]
The getmessages Function has a 10-minute in-memory cache enabled by default, if you wish to modify it you can change the code in functions/getmessages/index.js
file. Take into consideration that the cache will be reloaded (for a new instance) each time the Function App gets scaled (possibly due to many requests) or taken down by the runtime due to inactivity.
- add: this Function allows you to add a custom message in JSON format.
title
andmessage
properties are required, you can also setfrom
andto
if you want your message to appear in a specific day (this is the message of the day after all). You can optionally set apriority
(lower comes first). POST data is similar to the following:
{
"title":"title1",
"message":"message1",
"from":"2018-07-20T00:00:00.000Z",
"to":"2018-07-21T00:00:00.000Z",
"priority":"1"
}
As described, From
,To
and Priority
are optional. Moreover, if you omit Priority
, it will be automatically setup to a default of 100 (pretty low). If you omit From
and To
, your message will always be sent to the clients, unless you manually set the IsActive
property to 'false'. All dates/times are in UTC. Regarding the details regarding date/time format for the From
and To
variables:
- This is a sample entry for July 17th, 2018, at 00:00 UTC
2018-07-17T00:00:00.000Z
- This is a sample entry for July 20th, 2018, at 13:25 UTC
2018-07-20T13:25:00.000Z
- This is a sample entry for July 21st, 2019, at 05:17 UTC
2019-07-21T05:17:00.000Z
As you can see, the format for UTC date-time objects is:
YEAR
-MONTH
-DAY_OF_MONTH
THOUR
:MINUTE
:SECONDS
.MILISECONDS
Z
Last but not least, a Unity game engine SDK and sample scene (compatible with Unity 5.6 and higher) is provided in the client-unity
folder.
In order to add new messages, you can use the add Function, as previously described. However, to add/edit/delete messages you can use the free and cross-platform utility called Azure Storage Explorer. There, you can also set the IsActive
boolean variable to true/false, depending on whether you want your message to be visible to the clients.