cozie-app / cozie-apple

https://cozie-apple.app
GNU Lesser General Public License v3.0
15 stars 9 forks source link

Create notification groups #8

Closed FedericoTartarini closed 3 years ago

FedericoTartarini commented 3 years ago

Create notification groups so I can send different reminders to different groups of people

FedericoTartarini commented 3 years ago

I have implemented this by specifying some filters when I send the notification with Python. More information here. Sample code below:

import requests
import json

header = {"Content-Type": "application/json; charset=utf-8",
          "Authorization": "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

payload = {"app_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
           "filters": [
                {"field": "country", "relation": "=", "value": "SG"},
                {"operator": "AND"}, {"field": "app_version", "relation": "=", "value": "15"}
            ],
           "included_segments": ["All"],
           "contents": {"en": "Please complete the Cozie survey, app version 15."}}

req = requests.post("https://onesignal.com/api/v1/notifications", headers=header, data=json.dumps(payload))

print(req.status_code, req.reason)