Hi,
I was looking through the One Signal documentation, and you can actually call all the methods to One Signal using their web based API (and skip the PHP altogether), using the Coronium Network module, it’s just a simple JSON request and they actually include examples, you just need to convert the JSON syntax to Lua table stylings, which is pretty easy:
For example, a Coronium server-side API might look like:
local api = core.api() function api.createNotification(input) local data = { app\_id = "5eb5a37e-b458-11e3-ac11-000c2940e62c", included\_segments = { "All" }, contents = { en = "English Message" }, data = { foo = "bar" } } local resp, err = core.network.postJson("https://onesignal.com/api/v1/notifications", data, { ["Content-Type"] = "application/json;charset=utf-8", ["Authorization"] = "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj" }) if not resp then core.log(err) end core.log(resp) end return api
The above is the conversion of the https://documentation.onesignal.com/reference#section-send-to-all-subscribers-create-notification using the JSON tab.
If you don’t want to convert the JSON, you can do this instead:
local api = core.api() function api.createNotification(input) local data = --this is a JSON object string [[{ "app\_id": "5eb5a37e-b458-11e3-ac11-000c2940e62c", "included\_segments": ["Active Users"], "data": {"foo": "bar"}, "contents": {"en": "English Message"} }]] data = core.json.decode(data) local resp, err = core.network.postJson("https://onesignal.com/api/v1/notifications", data, { ["Content-Type"] = "application/json;charset=utf-8", ["Authorization"] = "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj" }) if not resp then core.log(err) end core.log(resp) end return api
In both cases it’s using the server-side network.postJson method.
I have a PHP addon pretty much done, but it would not be officially supported, and you’ll still need to use the Coronium Network module to call to the PHP, so in essence doubling the work, and putting more stress on the server.
-dev