Skip to content

Send GetSocial Notifications from Unity SDK

Prerequisite

Send Notifications

You can send GetSocial Notification to any user in you application. To send notification you have to:

  1. Create a list of receivers. The list should contain GetSocial user IDs.
  2. Create a notification content.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    // The list of GetSocial user IDs whom we will send notification to
    List<string> receivers = ... ;
    
    // The content of the notification
    var notification = NotificationContent
                            .NotificationWithText("Notification text")
                            .WithTitle("Greetings!")
                            .WithAction(Notification.ActionType.OPEN_ACTIVITY)
                            .WithMediaAttachment(MediaAttachment.Image(customImage));
    
    GetSocial.User.SendNotification(receivers, notification,
                            summary => Debug.Log("Sent " + summary.SuccessfullySentCount + " notifications"),
                            error => Debug.LogError("Failed to send notifications: " + error));
    

Receivers

  • Receivers list can not be empty.
  • It may contain up to 25 unique user IDs and one or many placeholders from SendNotificationPlaceholders.Receivers.
    1
    2
    3
    4
    5
    List<string> receivers = new List<string> {
                    SendNotificationPlaceholders.Receivers.ReferredUsers,
                    SendNotificationPlaceholders.Receivers.Referrer 
                    "[put user 1 id here]", 
                    "[put user 2 id here]" };
    
  • If you will send more that 25 user IDs - method will fail and notification will not be sent.
  • If you mentioned one user twice or user is in two or more placeholder groups - the notification will be sent only once.
  • If our service can not send the notification to one or many users, it will be delivered to all other users. You can check the number of successfully sent notifications in the response.

Notification Content

There are two ways to create a notification content:

  1. Create all the content on the client side. You can customize notification text (mandatory), title, configure notification click action and attach media.

    1
    2
    NotificationContent notification = NotificationContent
                            .NotificationWithText("Notification text");
    
  2. Use templates provided by GetSocial or create your custom template on the GetSocial Dashboard. You can override any content in the template dynamically on the client side.

    1
    2
    var notification = NotificationContent
                            .NotificationFromTemplate("template-name");
    

Action

To set an action to the notification click, use notification.WithAction(GetSocialAction action).

1
2
3
var action = GetSocialAction.CreateBuilder(GetSocialActionType.OpenInvite).build();
var notificationContent = NotificationContent.NotificationWithText("Invite friends!")
                        .WithAction(action);

Read how to create actions.

Action Buttons

To add an action button use notification.AddActionButton(ActionButton button) or notification.AddActionButtons(List<ActionButton> actionButtons) to add multiple buttons at once.

1
2
3
4
var notificationContent = NotificationContent.NotificationWithText("Add " + SendNotificationPlaceholders.CustomText.SenderDisplayName + " to friends")
                        .WithAction(Action.builder("add_friend").build())
                        .AddActionButton(ActionButton.create("Accept", ActionButton.ConsumeAction)
                        .AddActionButton(ActionButton.create("Decline", ActionButton.IgnoreAction);

Media Attachment

It’s possible to send image and video content in notification. To set image or video use NotificationContent.WithMediaAttachment().

1
2
3
MediaAttachment attachment = ... ;
var content = NotificationContent.NotificationWithText("Check this cool image!")
         .WithMediaAttachment(MediaAttachment.Image(customImage));

Check full Media Attachment guide to learn about supported image, GIF and video formats and limitations.

Notification Templates

To create a template for notifications:

  1. Login to the GetSocial Dashboard.

  2. Go to the Notifications section → Templates tab.

  3. Press New Template button.

    GetSocial Dashboard - Create New Template

  4. Create a new template by giving a unique name and meaningful description.

  5. Setup the notification content. You can add translations, emojis, default placeholders(Sender/Receiver display name) or custom placeholders that can be replaced on the SDK. Also you can set the fallback value for each placeholder which will be used if it wasn’t sent from the SDK side.

  6. To check the list of your custom templates switch to Custom tab using radio button.

  7. Now create and setup notification using GetSocial SDK:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    // Text for the template "new_level_achieved" on the Dashboard:
    // "Your friend [SENDER_DISPLAY_NAME] just reached [USER_LEVEL] lvl! Try to beat his score!"
    
    NotificationContent notification = NotificationContent.NotificationFromTemplate("new_level_achieved");
    ... // set up your notification
    notification.AddTemplatePlaceholder("USER_LEVEL", "7"); // add replacement for your placeholders without brackets
    
    GetSocial.User.SendNotification(users, notification, onSuccess, onError);
    // Your recipients will receive text:
    // "Your friend John Doe just reached 7 lvl! Try to beat his score!"
    

    [SENDER_DISPLAY_NAME] is automatically replaced with sender display name. You can check all possible placeholders in SendNotificationPlaceholders.CustomText.

Next Steps

Give us your feedback! Was this article helpful?

😀 🙁