Coder Social home page Coder Social logo

dgkanatsios / messageoftheday Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 43 KB

A simple Message Of The Day implementation with a REST API that can be consumed by gaming clients. Using Azure Functions in Node.js

License: MIT License

JavaScript 48.70% C# 51.30%
azure azure-functions table-storage javascript nodejs

messageoftheday's Introduction

Software License PRs Welcome unofficial Google Analytics for GitHub

Message Of The Day

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.

One-click deployment

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).

Architecture - Technical Details

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 and message properties are required, you can also set from and to if you want your message to appear in a specific day (this is the message of the day after all). You can optionally set a priority (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_MONTHTHOUR:MINUTE:SECONDS.MILISECONDSZ

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.

Adding/editing/deleting messages

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.

Resources

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.