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