GSM Notification Data

Sử dụng các api để lấy được các data của push notification được gửi kèm khi push từ trên GSM

  • Chỉ có từ GSM V1.2.3.8 trở lên

  • Khi Push Notification từ hệ thống GSM thì nếu trong Push có chứa custom Data thì các Data này được lưu vào kho Notification Data của user.

  • Khi phía game sử dụng API để lấy data về thì có thể claim để xóa data đó trên server, để lần sau khi gọi sẽ không bị lặp data.

  • Ví dụ: Trong bài toán, khi push notification và kèm thêm 1 data phần thưởng cho user. Khi user vào game thì phía game sẽ call api để lấy các data phần thưởng và sau đó claim để lấy dữ liệu và xóa trên server.

1. Lấy danh sách Notification Data

  • Khi vào game và khi GSM đã Login Success thì có thể call api này để lấy data.

public static void GetNotificationDatas(Action<List<NotificationDataItem>> onSuccess, Action<long, string> errorCallBack = null)

Code mẫu:

GSMNotificationData.GetNotificationDatas((items) =>
{
    //Hiển thị hoặc xử lý dữ liệu các notification
    items.ForEach(item =>
    {
        Debug.Log($"id: {item.id}");
        Debug.Log($"title: {item.title}");
        Debug.Log($"body: {item.body}");
        Debug.Log($"imageUrl: {item.imageUrl}");
        Debug.Log($"data: {item.customData}");        
    });
}, (statusCode, error) => { 
    //Xử lý khi có lỗi
});

Chú ý: Không nên trả thưởng cho user khi lấy list Notification về, mà nên sử dụng Api Claim ở các hướng dẫn bên dưới

2. Claim Notification Data

  • Mục đích để kiểm tra thực sự 1 Notification Data đang hợp lệ trên server.

public static void ClaimNotificationData(string notificationId, Action<NotificationDataItem?> onSuccess, Action<long, string> errorCallBack = null)

Code mẫu:

GSMNotificationData.ClaimNotificationData(<Id Notification>, (notificationData) =>
{
    if (notificationData != null)
    {
        //Xử lý data
    }
}, (statusCode, error) =>
{
    //Xử lý khi có lỗi
});

3. Claim theo danh sách

  • Mục đích để Claim và xử lý 1 loạt các Notification Data hợp lệ trên server

public static void ClaimNotificationDatas(string[] notificationIds, Action<List<NotificationDataItem>> onSuccess, Action<long, string> errorCallBack = null)

Code mẫu:

GSMNotificationData.ClaimNotificationDatas(new string[] { <notificationId1>, <notificationId2>,<notificationId3> }, (items) =>
{
            //Hiển thị hoặc xử lý dữ liệu các notification
            items.ForEach(item =>
            {
                Debug.Log($"id: {item.id}");
                Debug.Log($"title: {item.title}");
                Debug.Log($"body: {item.body}");
                Debug.Log($"imageUrl: {item.imageUrl}");
                Debug.Log($"data: {item.customData}");
         });
 }, (statusCode, error) =>
 {
    //Xử lý khi có lỗi
 });

Last updated