https://metaplay.io logo
Programmatic Push Notification with TTL
# questions-and-feedback
l
Hi all, I've been looking into implementing some push notifications. One use-case we'd like to be able to cover is attaching some delay (TTL) to a programmatic notification created by the server, rather than by some campaign. An example here might be "Issue a push notification 12 hours after the player has logged in for the first time today" From what I can see,
PlayerActor.SendPushNotification
doesn't take any delay parameters, and if we look at
PushNotificationActor.SendBatchAsync
, it looks like we construct the Firebase
Message
object using
Android = DefaultAndroidConfig
. From Firebase's documentation, it looks like this is where we'd inject the TTL, and there is a corresponding parameter
TimeToLive
available on
AndroidConfig
. This config looks like it exposes a number of other potentially useful fields, e.g.
Priority
. Is it feasible to make my own edits to the Metaplay SDK (
Unity/Project/MetaplaySDK/Backend/Server/Player/PlayerActorBase.cs
) to allow mutation of the
AndroidConfig
? What are the implications for when I wish to stop running the Metaplay server locally, and move to your own cloud hosted solution?
j
For the specific use-case I would recommend using local scheduled notifications instead of push notifications. Local notifications are easier to implement and more reliable. For the firebase API, I believe the TTL parameter would not allow delaying delivery but instead controls how long the Firebase backend keeps the message in its message buffer if its not able to deliver the push notification immediately. (So in order to use the push notification and delay, you will need some way to schedule operations on server. The SDK at the moment does not ship with any Scheduler system so your best bet is to add your own SchedulerPushNotifiManager (persisted entity, singleton service) into which PlayerActors register things to do, and SchedulerPushNotifiManager ticks like once per 5s to check for expired tasks and runs them..) For making edits to the SDK. Yes, you can make edits and run it in the managed cloud too. In the cloud hosting, you are deploying container images and not source code, so we wouldn't even know if the SDK in the deployed server has been modified. But you need to be careful with the changes when you update the SDK to keep your changes. Also naturally the stability of internal APIs are not guaranteed nor documented in release notes. One trick you can use is to have edits if possible in a separate file, such as
PlayerActorBase.MyGameName.cs
and there extend
partial clas PlayerActorBase<> { public int MySendNotification(..) { ... }
. This way if you get new PlayerActorBase.cs from new SDK version you wouldn't overwrite your additions.
l
That's all very helpful, thank you!