Skip to main content

Tutorial: notify a phone

In about ten minutes you will make a workflow talk to a phone. A guest registers the phone on a web page and closes the browser. Later the workflow sends a notification that shows up in the status bar of the phone, although the browser is closed, with two buttons the guest can tap. A tap continues the workflow on the path of that button.

You do not build anything: the diagram is the shipped example Browser Push Pager. You only need a running installation, see Installation, and a phone or an Android emulator with Chrome.

Browser requirement

Browsers only allow notifications for pages opened over https or on localhost. For a test on the computer that runs Cocosplate AI, open http://localhost:<port>. For a real phone use the https address of your installation. A phone that reaches your server as localhost works as well, for example an Android device connected with adb reverse tcp:<port> tcp:<port> (the emulator of Android Studio is such a phone).

1. Get your push keys​

Notifications are signed with a key pair that belongs to you.

  1. Open Account → Settings and unfold Push notifications.
  2. Click Generate key pair. Both keys are filled in and the panel says The keys are valid and belong together.
  3. Leave the contact as it is or enter your e-mail address as mailto:you@example.org. Push services may use it to reach you if your notifications misbehave.

The changes are saved at once. The public key is handed to the phones, the private key stays on the server.

2. Open the example​

  1. On the start page click (Re-)load examples if the examples are not there yet.
  2. Open Diagram → Open and select examples/Conditional/Browser Push Pager.

The diagram reads from top to bottom:

NodeWhat it does
Welcome: register this deviceA user input with Offer browser push registration. It shows a page with the button Enable notifications. The run waits here until the guest pressed next.
Wait (stands for: the table gets free)A wakeup timer of one minute. It stands for the event on your side. The run sleeps and nothing is running.
Call the guestThe push notification with the title Your table is ready.
Answer?A click response. Every outgoing edge becomes a button in the notification: coming and later.
Wait 10 minutes for an answerA second timer. When nobody answers, the edge timeout is taken.

Click a node to see its settings. The note on the canvas repeats what the guest has to do.

3. Start it​

Press Start. The run stops at the first node, because it waits for the guest. Open Tasks: the run is Waiting for input and the line has a Weblink. This is the web page of the waiting input. Open it on the phone, or write it on an NFC tag or into a QR code.

If the editor is set to another language than English, Start first asks Translate button labels?. The example needs no translation: choose Start without translation.

One run, one guest

The link belongs to this run and works until the page was submitted. Start the diagram again for the next guest.

4. Register the phone​

On the phone open the link in Chrome. The page says Welcome!.

  1. Tap Enable notifications. Chrome asks for the permission, tap Allow.
  2. The status line under the button changes to This device is coupled. This is the acknowledgement: the phone is registered and its subscription is stored in the variable push.subscription of the run.
  3. Tap next. Then close Chrome, swipe it away from the recent apps.

5. The notification arrives​

After one minute the timer wakes the run and Call the guest sends the notification. It appears in the status bar of the phone, although Chrome is closed. Pull the status bar down: the title Your table is ready, the text and the buttons coming and later.

Tap coming, or the notification itself: it opens the first link, coming. The browser opens a small answer page, and the run continues on the path of that answer: it reaches the end node Guest is coming and leaves the task list, because it is finished. Answer later the next time and it ends at Guest comes later. Do not answer at all and, after ten minutes, it ends at No answer. The log of the run shows which end node it reached.

Where to go from here​

  • Replace the timer with the event you really wait for, for example the answer to an e-mail.
  • Change the title and the text of the notification: Call the guest, parameters push.title and push.message. A notification shows plain text only, see the limits in the push notification manual.
  • If nothing arrives: the status line of the registration page says why (blocked, no secure connection, keys missing). If you replace your keys, every phone has to register again.