-
Notifications
You must be signed in to change notification settings - Fork 28
EmergencyMessage
Emergency Priority causes the system to deliver the message multiple times until acknoledged by the recipient. From the API documention of Pushover
Emergency-priority notifications are similar to high-priority notifications, but they are repeated until the notification is acknowledged by the user. These are designed for dispatching and on-call situations where it is critical that a notification be repeatedly shown to the user (or all users of the group that the message was sent to) until it is acknowledged. Applications sending emergency notifications are issued a receipt that can be used to get the status of a notification and find out whether it was acknowledged, or automatically receive a callback when the user has acknowledged the notification.
To send an emergency message start with a Message Builder like so
PushoverMessage msg = PushoverMessage.builderWithApiToken("MY_APP_API_TOKEN")
.setUserId("[USER_ID_TOKEN]")
.setTitle("SERVER DOWN")
.setMessage("Server 10 just went offline!")
.setPriority(MessagePriority.EMERGENCY)
.setSound("siren")
.setRetry(120)
.setExpire(7200)
.build());
The key to the message is in the last two seters .setRetry(seconds)
and .setExpire(seconds)
. These are required parameters that enable the retransmit ability. Without the 'retry' and 'expire' parameters pushover will fail the send and return a response error code. The 'title' and 'sound' paremeters are optional but are handy for quickly seeing and hearing what is going on. Another option is to use .setCallbackUrl(URL string)
and set a endpoint for the Pushover servers to call when the user responds to the message. See the callback API documentation for the format of the posted data.
The difference between a normal Pushover message and an Emergency Priority is that the server will return a Receipt token to use when checking the server. The status of the mesasge can be polled on an interval or have the server respond automatically through a callback URL.
To send the Emergency Message and get back a receipt a call to the .pushMessageResponse(PushoverMessage)
will be necessary as .pushMessage(PushoverMessage)
will return only status
.
First setup a client
PushoverClient client = new PushoverRestClient();
Then use the client to send the the API with the Response returned
Response resp = client.pushMessageResponse(msg);
If the request was successfull the status will be 1 and the receipt will be available.
String receipt = "";
if(resp.getStatus() == 1){
receipt = resp.getRecipt();
}
Now the receipt can be used to manange the message.