question

Jakub Smekal avatar image
Jakub Smekal asked

Push notification template with arguments

Hello,

is it possible to send push notification from cloud script using template, with custom parameters?

I'd like to have the notification translated in multiple languages, but use custom values inside the text.

Example:

Notification template XYZ, English entry: <Profile.DisplayName> made a move <CustomParams.Move>!

Cloud script:

server.SendPushNotificationFromTemplate({
                 
Recipient: "playfab ID",
PushNotificationTemplateId: "XYZ",
CustomParams: {
Move: "A5" }
});

Result notification: Player made a move A5!

Thank you

Push Notifications
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

PlayFab does not support to define the formatting fields such as <CustomParams.Move> in the Notification Templates on your own. Currently, Notification Templates only support catching the first-level string and number attributes of Player Profile Model and the similar common properties of PlayStream Event Models. <Profile.DisplayName> is from Player Profile, just like this sample, you can also get the Player’s PlayerId via formatting field <Profile.PlayerId>.

Besides, if you use PlayFab Rules to trigger action Send Push Notification through some types of events. You can add the properties of the corresponding event to the notification templates, such as <Event.Timestamp>. For more information about how to use formatting fields and payload in Notification Templates, please check the link [What’s this?] which in the right-up corner of Edit Push Notification Template page.

For your case, if you want to define the content in the notification more flexibly, we would suggest you migrate the notification templates to CloudScript directly. You can let the function choose the different languages’ templates according to the languages in the Player’s EntityProfile, then use SendPushNotification to send the combined notifications to the specific players. You can refer to the following code.

If you still want the feature that adding custom formatting fields to Notification templates, please try to add a feature request for it.

handlers.sendCustomPushNotification = function (args, context) {

    var entityProfile = context.currentEntity;
    var language = entityProfile.Language;
    var getProfileResult = server.GetPlayerProfile(
        {
            PlayFabId: entityProfile.Lineage.MasterPlayerAccountId
        });
    var playerdisplayName = getProfileResult.PlayerProfile.DisplayName;
    switch (language) {
        case "en":
            var apiResult = server.SendPushNotification(
                {

                    Recipient: entityProfile.Lineage.MasterPlayerAccountId,
                    Message: playerdisplayName + " made a move " + args.move
                }
            )
            break;
        case "ko":
            var apiResult = server.SendPushNotification(
                {
                    Recipient: entityProfile.Lineage.MasterPlayerAccountId,
                    Message: playerdisplayName + " made a move  " + args.move //Translate the message to the corresponding language
                }
            )
            break;
        default:

    };

}



10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.