This is a migrated thread and some comments may be shown as answers.

Segment Push Notification from Windows Apps

1 Answer 98 Views
.NET SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
HSLaw
Top achievements
Rank 1
HSLaw asked on 17 Nov 2014, 07:10 AM
Hi,

I have a windows apps to test push notification with the code as below.
I try to send Push based on the devices hardwareIDs / UUIDs.

Private Sub btn_send_push_notification_Click(sender As Object, e As EventArgs) Handles btn_send_push_notification.Click
 
        Dim str_msg As String = "(3) - Pls inform HS if you got this. TQ."
 
        Dim dt As New DataTable
        Dim dc = New DataColumn
        dc.ColumnName = "hardwareID"
        dt.Columns.Add(dc)
 
        Dim dr As DataRow
        dr = dt.NewRow
        dr("hardwareID") = "4f8973a567f820c1"
        dt.Rows.Add(dr)
 
        dr = dt.NewRow
        dr("hardwareID") = "8d2cdcf8958a1f98"
        dt.Rows.Add(dr)
 
        'TODO: pull devices ID from database
 
        ' construct a filter
        Dim hardwareIds As String() = New String(dt.Rows.Count) {}
 
        For Each dr In dt.Rows
            hardwareIds(dt.Rows.IndexOf(dr)) = dr("hardwareID")
        Next
 
        ' specifies that only Android users will get the notification
        ' for all devices with a hardware id in the hardwareIds array
        Dim notificationFilter = New Dictionary(Of String, Object)() From { _
            {"HardwareId", New Dictionary(Of String, String())() From { _
                {"$in", hardwareIds} _
            }} _
        }
 
        Dim notification = New PushNotification()
 
        ' add the notification filter
        notification.Filter = Telerik.Newtonsoft.Json.JsonConvert.SerializeObject(notificationFilter)
 
        'ANDROID
        Dim androidNotificationPayload = New Dictionary(Of String, Object)() From { _
            {"data", New Dictionary(Of String, Object)() From { _
                {"title", _str_app_name}, _
                {"message", str_msg}, _
                {"customData", "customdata-123456"} _
            }} _
        }
 
        notification.Android = New Telerik.Everlive.Sdk.Core.Model.System.Push.Android.AndroidNotification()
 
        For Each pair As KeyValuePair(Of String, Object) In androidNotificationPayload
            notification.Android.SetValue(pair.Key, pair.Value)
        Next
 
 
        'IOS
        Dim iosNotificationPayload = New Dictionary(Of String, Object)() From { _
            {"aps", New Dictionary(Of String, Object)() From { _
                {"alert", str_msg}, _
                {"sound", "default"}, _
                {"badge", 1}, _
                {"category", ""} _
            }}, _
            {"customData", New Dictionary(Of String, Object)() From { _
                {"123456", "customdata"} _
            }} _
        }
 
        notification.iOS = New Telerik.Everlive.Sdk.Core.Model.System.Push.IOS.IOSNotification()
 
        For Each pair As KeyValuePair(Of String, Object) In iosNotificationPayload
            notification.iOS.SetValue(pair.Key, pair.Value)
        Next
 
 
        Dim settings = New EverliveAppSettings() With { _
            .ApiKey = _telerik_backend_services_API, _
            .UseHttps = False _
        }
 
        Dim app = New EverliveApp(settings)
        Dim result = app.WorkWith().Push().Notifications().Create(notification).ExecuteSync()
        txt_result.Text = txt_result.Text & result.ToString
 
    End Sub


However, in the Telerik Backend Services' Push list, I see the Push item as:

Send to:
Devices that match all of the following:

If I send manually I can see 
Send to:
Devices that match any of the following:
 HardwareId
 is
 4f8973a567f820c1


Is there something wrong with my VB codes?

Thanks.


1 Answer, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 17 Nov 2014, 03:37 PM
Hello,

From the code snippet it appears that you are using the "$in" operator which is perfectly fine - this filter targets devices whose HardwareId matches any of the items in the hardwareIds array.

However, this operator is not properly interpreted by the web portal and the criteria are not displayed. Note that the targeting logic is not impaired, this is a glitch only in the UI.

In order to workaround the issue, consider using the following operators:
  • "$and" - match all of the criteria in the array.
  • "$or" - match any of the criteria in the array.

For example:
' construct a filter
        Dim filterFieldName As String = "HardwareId"
        Dim hardwareIds As String() = New String() {"HardwareId1", "HardwareId2", "HardwareId3"}
 
        Dim filterParams As Dictionary(Of String, String)() = New Dictionary(Of String, String)(2) {}
 
        For i As Integer = 0 To hardwareIds.Length - 1
            filterParams(i) = New Dictionary(Of String, String)()
            filterParams(i).Add(filterFieldName, hardwareIds(i))
        Next
 
        Dim operatorName = "$or"
        Dim notificationFilter = New Dictionary(Of String, Object)()
        notificationFilter.Add(operatorName, filterParams)

This will send the following Filter object to the API:
"Filter": "{\"$or\":[{\"HardwareId\":\"HardwareId1\"},{\"HardwareId\":\"HardwareId2\"},{\"HardwareId\":\"HardwareId3\"}]}"

Let me know if you have questions.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
.NET SDK
Asked by
HSLaw
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Share this question
or