I would like to include a URL in the message sent to pushover in one my apps (Life360 Tracker) but I just can't figure out how! Sending a message is easy, adding in the URL not so much.
Could someone give me an example? This is what I use now to send the message...
If you take a look at my old Pushover Driver (before Hubitat added built-in version), you can at least see how the URL functionality was added. There is no way from an App to include a URL within the deviceNotification()'s string that is passed in. The URL and URL Title are user preferences/settings within the driver.
Two options that I can think of...
Ask the Hubitat Team if they would consider adding some sort of additional delimiters that could be used allow the URL and URL Title to included in the deviceNotification() string argument. These would then be parsed out and sent in the http call correctly.
You could try to modify my old driver to add this functionality. Be aware - I haven't used it in a while, so I am not sure whether or not it still works correctly.
Well. You can send you message with separators he has defined [cc]and it allows you to manipulate the different options the driver has for creating notifications.
Join allows you to setup numerous different kind of actions that can be ran from an android device.
These actions can be presented as buttons within the notification. Those buttons can be picked based upon the above custom formating.
So for example if I can pass the url into the join api with the custom formatting. I can then react to it any many ways in my android device.
@bptworld, I skimmed this thread. Are you trying to pass the URL into the Pushover Supplementary Url input from another app?
If yes, I'll try to whip up something for you in a bit (busy atm). You can look at the deviceNotifications section of Dan's driver where I used [ ] to determine message priority. You can do something similar with the url.
If you want to allow for both custom priority and supplementary url, then you might need to use delimiters like I did in my Join driver. Take a look at the buildMessage() function. Feel free to use whatever part of the code you see fit.
I wasn't sure exactly how you planned to use this but my assumption was that you only needed to dynamically change the supp url and title with a location url.
With that in mind, here's what I came up with.
You can still use the priority prefixes (L, H, E, etc) but you can also add a [LOC] custom command that will override the default supp url with what follows it. The message will need to be constructed as follows.
[L,H,E]message[LOC]http://locationUrl
I hard-coded the url title to "Location Link" because I assume that's all it will ever be. You can easlily add code to make that an input or whatever you need. Hopefully this is what you needed. Now back to back breaking work...and thanks for the excuse to rest
Replace the deviceNotifications() method with this one. I commented my changes so you can see them in the code.
def deviceNotification(message) {
if(message.startsWith("[L]")){
customPriority = "-1"
message = message.minus("[L]")
}
if(message.startsWith("[N]")){
customPriority = "0"
message = message.minus("[N]")
}
if(message.startsWith("[H]")){
customPriority = "1"
message = message.minus("[H]")
}
if(message.startsWith("[E]")){
customPriority = "2"
message = message.minus("[E]")
}
if(customPriority){ priority = customPriority}
////////////////////////////////////////ADDED BY STEPHACK//////////////////////////////////////////////////////////////////////////////
def myUrl = settings["url"]
def myTitle = settings["urlTitle"]
//log.debug myUrl
if(message.contains("[LOC]")){
incMessage = message.tokenize("[LOC]")
message = incMessage[0]
myUrl = incMessage[1]
myTitle = "Location Link"
log.debug incMessage
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Define the initial postBody keys and values for all messages
def postBody = [
token: "$apiKey",
user: "$userKey",
message: "${message}",
priority: priority,
sound: sound,
url: myUrl, ///////////Changed url to myUrl - stephack
device: deviceName,
url_title: myTitle, ////////Changed urlTitle to myTitle - stephack
retry: retry,
expire: expire
]
if (deviceName) { log.debug "Sending Message: ${message} Priority: ${priority} to Device: $deviceName"}
else {log.debug "Sending Message: [${message}] Priority: [${priority}] to [All Devices]"}
// Prepare the package to be sent
def params = [
uri: "https://api.pushover.net/1/messages.json",
contentType: "application/json",
requestContentType: "application/x-www-form-urlencoded",
body: postBody
]
if ((apiKey =~ /[A-Za-z0-9]{30}/) && (userKey =~ /[A-Za-z0-9]{30}/)) {
httpPost(params){response ->
if(response.status != 200) {
sendPush("ERROR: 'Pushover Me When' received HTTP error ${response.status}. Check your keys!")
log.error "Received HTTP error ${response.status}. Check your keys!"
}
else {
log.debug "Message Received by Pushover Server"
}
}
}
else {
// Do not sendPush() here, the user may have intentionally set up bad keys for testing.
log.error "API key '${apiKey}' or User key '${userKey}' is not properly formatted!"
}
}
EDIT: not sure why the above code looks so strange with the green text.