Debian Codegraph @

docs/_common.txt

raw
1 Application Helpers
2 -------------------
3
4 The payload delivered to push-client will be passed onto a helper program that can modify it as needed before passing it onto
5 the postal service (see `Helper Output Format <#helper-output-format>`__).
6
7 The helper receives two arguments ``infile`` and ``outfile``. The message is delivered via ``infile`` and the transformed
8 version is placed in ``outfile``.
9
10 This is the simplest possible useful helper, which simply passes the message through unchanged:
11
12 #!/usr/bin/python3
13 import sys
14 f1, f2 = sys.argv[1:3]
15 open(f2, "w").write(open(f1).read())
16
17 Helpers need to be added to the click package manifest:
18
19 {
20 "architecture": "all",
21 "description": "Example app for push notifications.",
22 "framework": "ubuntu-sdk-16.04.5",
23 "hooks": {
24 "hello": {
25 "apparmor": "hello.json",
26 "desktop": "hello.desktop"
27 },
28 "helloHelper": {
29 "apparmor": "helloHelper-apparmor.json",
30 "push-helper": "helloHelper.json"
31 }
32 },
33 "maintainer": "Example Developer <[email protected]>",
34 "name": "hello.example",
35 "title": "Hello",
36 "version": "0.5.0"
37 }
38
39 Here, we created a helloHelper entry in hooks that has an apparmor profile and an additional JSON file for the push-helper hook.
40
41 helloHelper-apparmor.json must contain **only** the push-notification-client policy group and the lomiri-push-helper template:
42
43 {
44 "template": "ubuntu-push-helper",
45 "policy_groups": [
46 "push-notification-client"
47 ],
48 "policy_version": 16.04
49 }
50
51 And helloHelper.json must have at least a exec key with the path to the helper executable relative to the json, and optionally
52 an app_id key containing the short id of one of the apps in the package (in the format packagename_appname without a version).
53 If the app_id is not specified, the helper will be used for all apps in the package::
54
55 {
56 "exec": "helloHelper",
57 "app_id": "hello.example_hello"
58 }
59
60 .. note:: For deb packages, helpers should be installed into /usr/lib/lomiri-push-service/legacy-helpers/ as part of the package.
61
62 Helper Output Format
63 --------------------
64
65 Helpers output has two parts, the postal message (in the "message" key) and a notification to be presented to the user (in the "notification" key).
66
67 .. note:: This format **will** change with future versions of the SDK and it **may** be incompatible.
68
69 Here's a simple example::
70
71 {
72 "message": "foobar",
73 "notification": {
74 "tag": "foo",
75 "card": {
76 "summary": "yes",
77 "body": "hello",
78 "popup": true,
79 "persist": true,
80 "timestamp": 1407160197
81 }
82 "sound": "buzz.mp3",
83 "vibrate": {
84 "pattern": [200, 100],
85 "repeat": 2
86 }
87 "emblem-counter": {
88 "count": 12,
89 "visible": true
90 }
91 }
92 }
93
94 The notification can contain a **tag** field, which can later be used by the `persistent notification management API. <#persistent-notification-management>`__
95
96 :message: (optional) A JSON object that is passed as-is to the application via PopAll.
97 :notification: (optional) Describes the user-facing notifications triggered by this push message.
98
99 The notification can contain a **card**. A card describes a specific notification to be given to the user,
100 and has the following fields:
101
102 :summary: (required) a title. The card will not be presented if this is missing.
103 :body: longer text, defaults to empty.
104 :actions: If empty (the default), a bubble notification is non-clickable.
105 If you add a URL, then bubble notifications are clickable and launch that URL. One use for this is using a URL like
106 ``appid://com.ubuntu.developer.ralsina.hello/hello/current-user-version`` which will switch to the app or launch
107 it if it's not running. See `URLDispatcher <https://wiki.ubuntu.com/URLDispatcher>`__ for more information.
108
109 :icon: An icon relating to the event being notified. Defaults to empty (no icon);
110 a secondary icon relating to the application will be shown as well, regardless of this field.
111 :timestamp: Seconds since the unix epoch, only used for persist (for now). If zero or unset, defaults to current timestamp.
112 :persist: Whether to show in notification centre; defaults to false
113 :popup: Whether to show in a bubble. Users can disable this, and can easily miss them, so don't rely on it exclusively. Defaults to false.
114
115 .. note:: Keep in mind that the precise way in which each field is presented to the user depends on factors such as
116 whether it's shown as a bubble or in the notification centre, or even the version of Ubuntu Touch the user
117 has on their device.
118
119 The notification can contain a **sound** field. This is either a boolean (play a predetermined sound) or the path to a sound file. The user can disable it, so don't rely on it exclusively.
120 Defaults to empty (no sound). The path is relative, and will be looked up in (a) the application's .local/share/<pkgname>, and (b)
121 standard xdg dirs.
122
123 The notification can contain a **vibrate** field, causing haptic feedback, which can be either a boolean (if true, vibrate a predetermined way) or an object that has the following content:
124
125 :pattern: a list of integers describing a vibration pattern (duration of alternating vibration/no vibration times, in milliseconds).
126 :repeat: number of times the pattern has to be repeated (defaults to 1, 0 is the same as 1).
127
128 The notification can contain a **emblem-counter** field, with the following content:
129
130 :count: a number to be displayed over the application's icon in the launcher.
131 :visible: set to true to show the counter, or false to hide it.
132
133 .. note:: Unlike other notifications, emblem-counter needs to be cleaned by the app itself.
134 Please see `the persistent notification management section. <#persistent-notification-management>`__
135
136 .. FIXME crosslink to hello example app on each method
137
138 Security
139 ~~~~~~~~
140
141 To use the push API, applications need to request permission in their security profile, using something like this:
142
143 {
144 "policy_groups": [
145 "networking",
146 "push-notification-client"
147 ],
148 "policy_version": 16.04
149 }
150
151
152 Push Server API
153 ---------------
154
155 The Push server is located at https://push.ubports.com and has a single endpoint: ``/notify``.
156 To notify a user, your application has to do a POST with ``Content-type: application/json``.
157
158 .. note:: The contents of the data field are arbitrary. They should be enough for your helper to build
159 a notification using it, and decide whether it should be displayed or not. Keep in mind
160 that this will be processed by more than one version of the helper, because the user may be using
161 an older version of your app.
162
163 Here is an example of the POST body using all the fields::
164
165 {
166 "appid": "app.example_app",
167 "expire_on": "2014-10-08T14:48:00.000Z",
168 "token": "LeA4tRQG9hhEkuhngdouoA==",
169 "clear_pending": true,
170 "replace_tag": "tagname",
171 "data": {
172 "id": 43578,
173 "timestamp": 1409583746,
174 "serial": 1254,
175 "sender": "Joe",
176 "snippet": "Hi there!"
177 }
178 }
179
180
181 :appid: ID of the application that will receive the notification, as described in the client side documentation.
182 :expire_on: Expiration date/time for this message, in `ISO8601 Extendend format <http://en.wikipedia.org/wiki/ISO_8601>`__
183 :token: The token identifying the user+device to which the message is directed, as described in the client side documentation.
184 :clear_pending: Discards all previous pending notifications. Usually in response to getting a "too-many-pending" error.
185 :replace_tag: If there's a pending notification with the same tag, delete it before queuing this new one.
186 :data: A JSON object.
187
188 Limitations of the Server API
189 -----------------------------
190
191 The push notification infrastructure is meant to help ensuring timely
192 delivery of application notifications if the device is online or
193 timely informing the device user about application notifications that
194 were pending when the device comes back online. This in the face of
195 applications not being allowed to be running all the time, and
196 avoiding the resource cost of many applications all polling different services
197 frequently.
198
199 The push notification infrastructure is architected to guarantee at
200 least best-effort with respect to these goals and beyond it, on the
201 other end applications should not expect to be able to use and only
202 rely on the push notification infrastructure to store application
203 messages if they want ensure all their notification or messages are
204 delivered, the infrastructure is not intended to be the only long term
205 "inbox" storage for an application.
206
207 To preserve overall throughput the infrastructure imposes some limits
208 on applications:
209
210 * message data payload is limited to 2K
211
212 * when inserted all messages need to specify an expiration date after
213 which they can be dropped and not delivered
214
215 * an application is limited in the number of messages per token
216 (application/user/device combination) that can be undelivered/pending at the
217 same time (100 currently)
218
219 replace_tag can be used to implement notifications for which the newest
220 one replace the previous one if pending.
221
222 clear_pending can be used to be deal with a pending message limit
223 reached, possibly substituting the current undelivered messages with a
224 more generic one.
225
226 Applications using the push notification HTTP API should be robust
227 against receiving 503 errors, retrying after waiting with increasing
228 back-off. Later rate limits (signaled with the 429 status) may also come
229 into play.