I do, the sender piston uses an expression to deliver to a contact by id rather than selecting the name from the dropdown.
Code review wanted: notification suite with @recipients, urgency levels, repeating, and presence-based message queuing
hmm … looking at send notification to contact that seemed to support an expression for contact … that might suggest that there is some possibility here …
Yes the expression works fine, I am just curious whether there is an easier way for the end-user to get a contact into a variable in a way that can be used in this expression. Currently the variable needs to be set to the contact id formatted :0e657415ab1e4b0db90db24d12117ec2:
, a value which can be found using the console snippet posted above.
understood. but, i was thinking about it slightly differently. if send notification to contact supports an expression for contact, was @ady624 expecting users to dig up the contact id via some steps like the one above or is there another way to specify the contact in that expression just as you can specify a device using [name of device]
Exactly, we’ve come back around to my original question of any easier way to get those ids or alternate expressions for sending a notification to a contact.
Oddly, the contactId as a string is no longer working for me - I keep getting “Invalid list of contacts” so I’m checking into that now.
yeah, that would be nice. maybe just following the pattern of how devices can be used anywhere with []
That might be best, similar to how devices work. It looks like this could be worked around by handling strings here if ((operand.vt == 'contact') && (operand.c instanceof List)) {
so that the contacts get loaded but frankly the raw id format is too obscure anyway.
Edit: not a good guess, that code wasn’t related
The following tweak works for me to support contact expressions as literal strings or variables though I’m sure it needs some safety and cleanup. It includes any ids specified in the expression so that the contacts do not also need to be selected.
if ((operand.vt == 'contact') && (operand.c instanceof List || operand.exp instanceof Map)) {
def ids = []
if (operand.c instanceof List) {
ids += operand.c
}
if (operand.exp instanceof Map) {
def val = evaluateExpression(rtData, operand.exp, 'string').v
ids += val.tokenize(',')
}
for (c in ids.unique()) {
rawContacts[c] = rtData.contacts[c]
}
}
A bit of debug output showed me that this code runs when a piston is saved which is why nothing was happening when I tried to fuss with this bit of code earlier. Makes sense, didn’t get it last night
What do you think @ady624, is it worth making the Expression input work for notifying contacts or should I just avoid the example of sending to a contact for now? I’m not sure if the above code is the only place that needs to be modified but it has my live notifications to contacts working. Ultimately this is a low priority for me since this notification sender piston could be modified in a number of ways to work within the confines of only being able to select contacts from the dropdown.
I plan to revisit this in a few weeks, I’ve had some issues with notifications but not enough time to figure out if it’s related to the sender or the pistons triggering the messages.
Also, I realized that the patch shown above only fixes literal expressions since obviously if the expression is a variable, then all possible values of that variable can’t be known at the time this code runs.
Runtime Code Reuse