Pass URL from fucntion to call service data

Help with passing URL into notification

Hi, I am trying to pass a url into an actionable notification that is to take doorbell press as a trigger to check for doubletake if there is a facial match, send the snapshot into a notification or if its unknown to send the latest unknown snapshot from the doorbell. if i check the debug it shows the URL, but when pressing the notification on my phone it doesnt open the image, it instead loads my dashboard.

This is the function node:

    function toProperCase(str) {
    return str.replace(/\w+/g, function(txt) {
    return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase();
    });
    }
    
    
    // Check if msg.doubletake and its properties exist
    if (msg.payload && msg.payload.attributes && msg.payload.attributes.matches && msg.payload.attributes.matches[0]) {
    var name = msg.payload.attributes.matches[0].name;
    var snapshot = msg.payload.attributes.matches[0].filename;
    
    if (name && snapshot) {
    // Both 'name' and 'image' exist, publish them as is
    msg.name = toProperCase(name); // Use proper case for 'name'
    msg.snapshot = 'https://domain.com/api/storage/matches/' + snapshot;
    } else {
    // At least one of them is missing, publish holding image and name "Someone"
    msg.name = "Someone";
    msg.snapshot = 'https://domain.com/api/storage/matches/' + snapshot; // Remove the extra single quote here
    }
    } else {
    // If msg.doubletake.attributes.matches[0] doesn't exist, publish holding image and name "Someone"
    msg.name = "Someone";
    msg.snapshot = 'https://domain.com/api/storage/latest/front_door.jpg'; // Replace with your desired holding image URI
    
    }
    
    return msg;

This is the call service node data:

    {
        "title": "Front Door",
        "message": "{{name}} Rang the Doorbell at {{mytime}}",
        "data": {
            "ttl": 0,
            "priority": "high",
            "image": "/api/camera_proxy/camera.front_door",
            "channel": "Doorbell-Test",
            "color": "#ff5722",
            "notification_icon": "mdi:doorbell-video",
            "tag": "Doorbell-Test",
            "alert_once": true,
            "actions": [
                {
                    "action": "URI",
                    "title": "Open Reolink App",
                    "uri": "app://com.mcu.reolink"
                },
                {
                    "action": "URI",
                    "title": "Open Snapshot",
                    "uri": "{{snapshot}}"
                }
            ]
        }
    }

This looks like you are using Node Red in Home Assistant. Perhaps this link in the HA forum will help you Call Service -- Notification w/ Image ... Works in HA but not NodeRED - Third party integrations / Node-RED - Home Assistant Community (home-assistant.io)

Hi, yes this is home assistant.

If i change the uri in the call service node to be "domain.com" instead of "{{snapshot}}" the link works, but not when passed in from the function node. Even though thr debug shows that snapshot variable populates a working URL.

You can also see the other variables such as {{mytime}} work correctly.

As msg.snapshot has special url chars, i.e :/, so by default, mustache will escape any non-alphanumeric or HTML entities in the values it substitutes. To prevent this, use {{{snapshot}}} triple braces.

Ah i had a feeling the :confused: could have effected something, but didnt know you could tripple mustache, great info and I will give it a go soon.

The solution I referred to you used entities.

Triple mustache did the job, thank you. That was causing me a headache!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.