// The list of GetSocial user IDs whom we will send notification tovalreceivers:UserIdList=...valnotificationContent=NotificationContent.notificationWithText("Notification text").withTitle("Greetings!").withAction(action).withMediaAttachment(attachment)valtarget=SendNotificationTarget.users(receivers)Notifications.send(notificationContent,target,{Log.d("Notifications","Successfully sent notifications")},{error:GetSocialError->Log.d("Notifications","Failed to send notifications: $error")})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// The list of GetSocial user IDs whom we will send notification toletreceivers:[String]=...letnotificationContent=NotificationContent.withText("Notification text")notificationContent.title="Greetings!"notificationContent.action=actionnotificationContent.mediaAttachment=attachmentslettarget=SendNotificationTarget.users(UserIdList.create(receivers))Notifications.send(notificationContent,target:target,success:{print("Successfully sent notifications!")},failure:{errorinprint("Failed to send notifications, error: \(error)")})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// The list of GetSocial user IDs whom we will send notification toList<string>receivers=null;varnotificationContent=NotificationContent.CreateWithText("Notification text");notificationContent.WithTitle("Greetings");notificationContent.WithAction(action);notificationContent.WithMediaAttachment(mediaAttachment);vartarget=SendNotificationTarget.Users(UserIdList.Create(receivers));Notifications.Send(notificationContent,target,()=>{Debug.Log("Successfully sent notifications!");},(error)=>{Debug.Log("Failed to send notifications, error: "+error);});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// The list of GetSocial user IDs whom we will send notification toconstreceivers:string[]=...;// The content of the notificationconstmediaAttachment:MediaAttachment=...;// Create and instance of MediaAttachment from image or videoconstaction:Action=...;// Create an Action instanceconstnotificationContent=NotificationContent.withText('Notification text');notificationContent.title='Greetings!';notificationContent.action=action;notificationContent.mediaAttachment=media;consttarget=SendNotificationTarget.usersWithIds(UserIdList.create(receivers));Notifications.send(notificationContent,target).then(()=>{console.log('Successfully sent notifications!');},(error)=>{console.log('Failed to send notification.');});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//ThelistofGetSocialuserIDswhomwewillsendnotificationtovarreceivers=List<String>();//ThecontentofthenotificationvarmediaAttachment= ... ; // Create and instance of MediaAttachment from image or videovaraction= ... ; // Create a GetSocialAction instancevarnotificationContent=NotificationContent();notificationContent.text='Notification text';notificationContent.title='Greetings!';notificationContent.action=action;notificationContent.mediaAttachment=media;vartarget=SendNotificationTarget();target.userIdList=UserIdList.create(receivers);Notifications.send(notificationContent, target)
.then((result)=>print('Successfully sent notifications!'))
.catchError((onError)=>print('Failed to send notification.'));
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.
There are two ways to create a notification content:
Create all the content on the client side. You can customize notification text (mandatory), title, configure notification click action and attach media.
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.
varaction=GetSocialAction('action',{});varnotificationContent=NotificationContent();notificationContent.text='Push notification with Action';notificationContent.action=action;
Check GetSocial Actions guide for Android and iOS.
valaction=Action.create(ActionTypes.ADD_FRIEND,mapOf(ActionDataKeys.AddFriend.USER_IDtoGetSocial.getCurrentUser()!!.id))valnotificationContent=NotificationContent.notificationWithText("Add ${SendNotificationPlaceholders.CustomText.SENDER_DISPLAY_NAME} to friends").withAction(action).addActionButton(NotificationButton.create("Accept",NotificationButton.CONSUME_ACTION)).addActionButton(NotificationButton.create("Decline",NotificationButton.IGNORE_ACTION))
1
2
3
4
5
6
letaction=Action.create(type:ActionType.addFriend,data:[ActionDataKey.addFriend_UserId:GetSocial.currentUser()!.userId])letnotificationContent=NotificationContent.withText("Add \(NotificationContentPlaceholders.senderDisplayName) to friends")notificationContent.action=actionletacceptButton=NotificationButton(title:"Accept",actionId:NotificationButton.actionIdConsume)letdeclineButton=NotificationButton(title:"Decline",actionId:NotificationButton.actionIdIgnore)notificationContent.actionButtons=[acceptButton,declineButton]
1
2
3
4
5
6
7
8
9
10
varactionData=newDictionary<string,string>(){{GetSocialActionKeys.AddFriend.UserId,GetSocial.GetCurrentUser().Id}};varaction=GetSocialAction.Create(GetSocialActionType.AddFriend,actionData);varnotificationContent=NotificationContent.CreateWithText("Add "+SendNotificationPlaceholders.CustomText.SenderDisplayName+" to friends");notificationContent.WithAction(action);varacceptButton=NotificationButton.Create("Accept",NotificationButton.ConsumeAction);vardeclineButton=NotificationButton.Create("Decline",NotificationButton.IgnoreAction);notificationContent.AddActionButton(acceptButton);notificationContent.AddActionButton(declineButton);
1
2
3
4
constnotificationContent=NotificationContent.withText('Add [SENDER_DISPLAY_NAME] to friends');notificationContent.action=newAction('add_friend',{'$user_id',userId});notificationContent.buttons.push(NotificationButton.create('Accept','consume');notificationContent.buttons.push(NotificationButton.create('Decline','ignore');
1
2
3
4
5
varnotificationContent=NotificationContent();notificationContent.text='Add [SENDER_DISPLAY_NAME] to friends';notificationContent.action=GetSocialAction('add_friend',{'$user_id',userId});notificationContent.actionButtons.add(NotificationButton('Accept','consume');notificationContent.actionButtons.add(NotificationButton('Decline','ignore');
It’s possible to send image and video content in notification. To set image or video:
1
2
3
valmediaAttachment:MediaAttachment=...valnotificationContent=NotificationContent.notificationWithText("Check this cool image").withMediaAttachment(mediaAttachment)
1
2
3
letmediaAttachment:MediaAttachment=...letcontent=NotificationContent.withText("Check this cool image")content.mediaAttachment(mediaAttachment)
1
2
3
MediaAttachmentmediaAttachment=...varnotificationContent=NotificationContent.CreateWithText("Check this cool image");notificationContent.WithMediaAttachment(mediaAttachment);
1
2
3
constmediaAttachment=...;constnotificationContent=NotificationContent.withText('Check this cool image!');notificationContent.mediaAttachment=mediaAttachment;
Create a new template by giving a unique name and meaningful description.
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.
To check the list of your custom templates switch to Custom tab using radio button.
Now create and setup notification using GetSocial Android SDK:
1
2
3
4
5
6
7
8
9
10
11
12
13
// 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!"valnotificationContent=NotificationContent.notificationFromTemplate("new_level_achieved").addTemplatePlaceholder("USER_LEVEL","7")// add replacement for your placeholders without bracketsNotifications.send(notificationContent,target,{Log.d("Notifications","Successfully sent notifications")},{error:GetSocialError->Log.d("Notifications","Failed to send notifications: $error")})// Your recipients will receive text:// "Your friend John Doe just reached 7 lvl! Try to beat his score!"
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!"letnotificationContent=NotificationContent.withTemplate("new_level_achieved")...// set up your notificationnotificationContent.templatePlaceholders=["USER_LEVEL":"7"]// add replacement for your placeholders without bracketsNotifications.send(notificationContent,target:receivers,success:onSuccess,failure:onFailure)// Your recipients will receive text:// "Your friend John Doe just reached 7 lvl! Try to beat his score!"
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!"varnotificationContent=NotificationContent.CreateWithTemplate("new_level_achieved");...// set up your notificationnotificationContent.AddTemplatePlaceholder("USER_LEVEL","7");// add replacement for your placeholders without bracketsNotifications.Send(notificationContent,target,OnSuccess,OnError);// Your recipients will receive text:// "Your friend John Doe just reached 7 lvl! Try to beat his score!"
1
2
3
4
5
6
7
8
9
10
11
12
// 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!'constnotification=NotificationContent.withTemplate('new_level_achieved');...// set up your notificationnotification.templatePlaceholders['USER_LEVEL']='7'// add replacement for your placeholders without bracketsconsttarget=..// SendNotificationTarget instanceNotifications.send(notification,target).then();// Your recipients will receive text:// "Your friend John Doe just reached 7 lvl! Try to beat his score!"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Textforthetemplate'new_level_achieved'ontheDashboard:
//'Your friend [SENDER_DISPLAY_NAME] just reached [USER_LEVEL] lvl! Try to beat his score!'varnotification=NotificationContent();notification.templateName='new_level_achieved';
... //setupyournotificationnotification.templatePlaceholders['USER_LEVEL'] ='7'; // add replacement for your placeholders without bracketsvartarget= ..//SendNotificationTargetinstanceNotifications.send(notification, target)
.then((result)=> {});//Yourrecipientswillreceivetext:
//"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 NotificationContentPlaceholders class.
Sound customization is supported via Templates only. But first you have to add sound file to your application.
Prepare your audio file. It should not contain any special symbols or spaces in its name.
Add your file to raw resources of your application by putting it into your application’s res/raw directory.
After file is added you should create a template on the Dashboard and specify this file name without extension in Android Sound configuration.
Build the application and run it on a device.
Send notification to the user authenticated on this device. You can send notification via Smart Targeting or SDK. When the notification arrives to the device you should hear custom sound instead of the default one. Make sure your device is not muted and volume is on.
Prepare your audio file. It should be in aiff, wav, or caf formats and not longer than 30 seconds. You can read more about this on the official Apple documentation in Preparing Custom Alert Sounds section.
Add your file to your application target in the Xcode. Make sure it’s added by checking if the file is listed in Copy Bundle Resources section of your target.
After file is added you should create a template on the Dashboard and specify this file name with extension in iOS Sound configuration.
Build the application and run it on a device.
Send notification to the user authenticated on this device. You can send notification via Smart Targeting or SDK. When the notification arrives to the device you should hear custom sound instead of the default one. Make sure your device is not muted and volume is on.
Example - send notification and increase badge by 3:
1
2
3
4
5
6
7
8
9
10
valnotificationContent=NotificationContent.notificationWithText("You have 3 new messages!")// increase badge by 3.withBadge(NotificationContent.Badge.increaseBy(3))// set badge to 5.withBadge(NotificationContent.Badge.setTo(5))Notifications.send(notificationContent,target,{Log.d("Notifications","Successfully sent notifications")},{error:GetSocialError->Log.d("Notifications","Failed to send notifications: $error")})
1
2
3
4
5
6
letnotificationContent=GetSocialNotificationContent.withText("You have 3 new messages!")// increase badge by 3notificationContent.setBadge(GetSocialNotificationBadge.increaseBy(3))// set badge to 5notificationContent.setBadge(GetSocialNotificationBadge.set(5))Notifications.send(notificationContent,target:receivers,success:onSuccess,failure:onFailure)
1
2
3
4
5
6
7
varnotificationContent=NotificationContent.CreateWithText("You have 3 new messages!");// increase badge by 3notificationContent.WithBadge(Badge.IncreaseBy(3));// set badge to 5notificationContent.WithBadge(Badge.SetTo(5));Notifications.Send(notificationContent,target,OnSuccess,OnFailure);
1
2
3
4
5
6
7
constcontent=NotificationContent.withText('You have 3 new messages');// increase badge by 3content.badge=NotificationBadge.increase(3);// set badge to 5content.badge=NotificationBadge.set(5);Notifications.send(content,target);