Set up push notifications

How can I set up push notifications with Nakama?

We can easily write a Lua module which provides the One Signal HTTP API as a set of functions which can be imported into other code but instead we’ll import one written by the Heroic Labs team and maintained with the community. You can find the code in the official repository of modules.

Download and add the “onesignal.lua” file to the location you use for your Lua modules. You can put the files into whatever folder you like and specify the location when you run the server.

nakama --runtime.path "/some/path/dir/"

When you server is started you’ll see the One Signal module loaded and recorded in the startup logs. In development it can be helpful to run the server with “–log.stdout” for log output in the console.

Read more on push notifications, keys and credentials, etc here

1 Like


I added the onesignal.lua to the modules according to the tutorial and it is ok. But in the following lines with the heading “Keys and credentials” it is told to create a file with name pmessage.lua.

I got the ONESIGNAL_API_KEY and the ONESIGNAL_APP_ID for my app from the OneSignal dashboard according to their instructions and placed it in to related locals.

I created a file named pmessage.lua and replaced those variables with my credentials and placed this file in to the modules as I placed the onesignal.lua.

But I receive the error below.

{“level”:“error”,“ts”:“2020-05-20T11:47:05.676Z”,“msg”:“Could not load module”,“name”:"/nakama/data/modules/pmessage.lua",“error”:"/nakama/data/modules/pmessage.lua line:1(column:1) near ‘\ufffd’: Invalid token\n",“stacktrace”:“*RuntimeLua).loadModules\n\\\n\\\n\\\n\\nmain.main\n\tmain.go:130\nruntime.main\n\truntime/proc.go:203”}
{“level”:“error”,“ts”:“2020-05-20T11:47:05.677Z”,“msg”:“Error initialising Lua runtime provider”,“error”:"/nakama/data/modules/pmessage.lua line:1(column:1) near ‘\ufffd’: Invalid token\n",“stacktrace”:“\n\\nmain.main\n\tmain.go:130\nruntime.main\n\truntime/proc.go:203”}
{“level”:“fatal”,“ts”:“2020-05-20T11:47:05.677Z”,“msg”:“Failed initializing runtime modules”,“error”:"/nakama/data/modules/pmessage.lua line:1(column:1) near ‘\ufffd’: Invalid token\n",“stacktrace”:“main.main\n\tmain.go:132\nruntime.main\n\truntime/proc.go:203”}

What am i doing wrong?

Thank you for your help.

This error indicates you have an unexpected byte at the beginning of your file, likely a non-printable character or similar.

Make sure your file is saved as plain text with UNIX line endings ideally.

Thank you,

It was blank a file created over visual studio. It had this problem you just saw and which I couldn’t realize it would be this simple. In appearance there is no problem but somehow it can’t be parsed because of that funny issue.

I used another working file an paste the content and saved it as pmessage.lua. I did lots of other things to figure the problem out and solve yesterday and I had gave up until I put my pride aside and raise it here.

Thanks again and sorry for wasting your time.