How to target push messages to array segment

4 posts, 0 answers
  1. Erik
    Erik avatar
    2 posts
    Member since:
    Oct 2014

    Posted 13 Nov 2014 Link to this post

    Hi,

    We are building an application where users can subscribe to notifications from a long list of "channels". When sending notifications, we only want to send to those who have subscribed to the particular channel.

    We have modeled the channels as an array parameter, and sent this to the everlive backend to subscribe. E.g.:
    Parameters : {
          channels: ['channel1', 'channel26', 'channel99']
    }

    The trouble is that we don't know how to create segments targeting these channels via the Telerik Platform UI, or the REST services.

    When trying the Platform UI, it complains that the Parameters.channels segment is invalid.

    Your documentation (http://docs.telerik.com/platform/backend-services/features/push-notifications/target-and-send-push) only mentioned targeting with "equals", "not equals", and not something like "contains" or "has".

    We have also considered encoding the subscribed channels into a single field, e.g.
    Parameters : {
          channels: "channel1, channel25, channel101"
    }

    ...but we don't know how to target, say, anyone where Parameters.channels *contains* a specific channel.

    Do you have any suggestions?
  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 13 Nov 2014 Link to this post

    Hello Erik,

    Thank you for using the Telerik Developer Forums.

    Using an array with the channels in the device registration would be a suitable solution. Then you can implement the segmenting logic and send a notification using the REST API, the JavaScript and .NET SDKs of Backend Services.

    Construct the notification payload in the following way and create a notification in Backend Services. Note that you need to apply JSON.stringify on the Filter object before sending the payload if you are using the REST API or the JS SDK.



    {
        "Filter": "{\"Parameters.channels\":\"CHANNEL_NAME_HERE\"}", // must be a JSON string
        "Android": {
            "data": {
                "title": "Push Title",
                "message": "Push message for Android",
                "customData": "Custom data for Android"
            }
        },
        "IOS": {
            "aps": {
                "alert": "Push message for iOS",
                "badge": 1,
                "sound": "default",
                "category": "MY_CATEGORY"
            },
            "customData": "Custom data for iOS"
        }
    }

    In the UI you need to choose from the drop down menu the Parameters.channels field and enter, for example, channel11 in order to select all devices that have a channel11 in the channels array of their registration object.

    For example, let's say you have three devices in the backend project as follows:

    Device 1 - "channels": [ "MyChannelNameHere", "MyChannelNameHere1", "MyChannelNameHere2" ]
    Device 2 - "channels": "MyChannelNameHere"
    Device 3 - "channels": [ "MyChannelNameHere2", "MyChannelNameHere3", "MyChannelNameHere4" ]

    Case 1

    A filter { "Parameters.channels": "MyChannelNameHere" } will match Device 1 and Device 2:


    Case 2

    A filter { "Parameters.channels": "MyChannelNameHere2" } will match Device 1 and Device 3.

    Case 3 (Advanced)

    A filter

    { "$or": [{"Parameters.channels":"MyChannelNameHere2"}, {"Parameters.channels": "MyChannelNameHere4"}]  }
    will match Device 1 and Device 3. Use this when you'd like to sent notifications to users subscribed for any of the channels specified in the filter.

    Case 4 (Advanced)

    Alternatively, you may want to send a notification to users that have subscribed for all of the categories in the filter object (only Device 3 from the example):
    { "$and": [{"Parameters.channels":"MyChannelNameHere2"}, {"Parameters.channels": "MyChannelNameHere4"}]  }

    To do the above you can also use the following filter operator ($all) (matches Device 1):
    "Parameters.channels": {"$all": ["MyChannelNameHere2", "MyChannelNameHere4"] }}

    I hope that this helps. Could you please try it our on your side and let me know if you have questions?

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. Erik
    Erik avatar
    2 posts
    Member since:
    Oct 2014

    Posted 13 Nov 2014 in reply to Anton Dobrev Link to this post

    Hi Anton,

    Thanks for getting back to me.

    That works exactly as we would like, at least in the REST API. We can assign an array to a parameter, and filtering with { "Parameters.channels": "MyChannelNameHere" } matches any device with "MyChannelNameHere" in the Parameters.channels array. I would suggest adding those excellent examples to the documentation (http://docs.telerik.com/platform/backend-services/development/rest-api/push-notifications/sending-notifications), since it wasn't completely obvious that it works this way.

    I still can't get this to work in the platform web UI though. When I try to create a new push message, and select the Parameters.channels field, the UI complains that the segment is invalid, and does not give me any options for inputting a string.

    //Erik
  4. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 14 Nov 2014 Link to this post

    Hi Erik,

    I am glad to hear that the proposed approach is working for your use case.

    In regard to the segmenting from the UI portal. Currently, the parameters with value type array cannot be used for targeting through the UI, only through the REST API. This will be addressed with the improvements coming in the push notifications portal.

    Let me know if you have further questions or suggestions.

    Best regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top