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 https://heroiclabs.com/docs/tutorial-send-push-messages/

1 Like

Hi,

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”:“github.com/heroiclabs/nakama/v2/server.(*RuntimeLua).loadModules\n\tgithub.com/heroiclabs/nakama/v2@/server/runtime_lua.go:1666\ngithub.com/heroiclabs/nakama/v2/server.newRuntimeLuaVM\n\tgithub.com/heroiclabs/nakama/v2@/server/runtime_lua.go:1883\ngithub.com/heroiclabs/nakama/v2/server.NewRuntimeProviderLua\n\tgithub.com/heroiclabs/nakama/v2@/server/runtime_lua.go:175\ngithub.com/heroiclabs/nakama/v2/server.NewRuntime\n\tgithub.com/heroiclabs/nakama/v2@/server/runtime.go:459\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”:“github.com/heroiclabs/nakama/v2/server.NewRuntime\n\tgithub.com/heroiclabs/nakama/v2@/server/runtime.go:461\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.