[
    {
        "id": "d77c819ef730f316",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "c305ed130daa4aa7",
        "type": "mqtt-broker",
        "name": "Mosquitto-Docker",
        "broker": "172.16.201.21",
        "port": 1883,
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": 4,
        "keepalive": 60,
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "mqtt_broker",
        "type": "mqtt-broker",
        "name": "Mosquitto",
        "broker": "127.0.0.1",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "6df6769c3f6596b1",
        "type": "mqtt in",
        "z": "d77c819ef730f316",
        "name": "Frigate Events",
        "topic": "frigate/events",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "c305ed130daa4aa7",
        "nl": false,
        "rap": false,
        "inputs": 0,
        "x": 150,
        "y": 380,
        "wires": [
            []
        ]
    },
    {
        "id": "280e9ac385062cd2",
        "type": "json",
        "z": "d77c819ef730f316",
        "name": "Parse JSON",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 350,
        "y": 480,
        "wires": [
            [
                "e3999086702b2c7f"
            ]
        ]
    },
    {
        "id": "e3999086702b2c7f",
        "type": "switch",
        "z": "d77c819ef730f316",
        "name": "Only End Events",
        "property": "payload.type",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "end",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 590,
        "y": 580,
        "wires": [
            [
                "save_event"
            ]
        ]
    },
    {
        "id": "3ae47274abaf5e48",
        "type": "http request",
        "z": "d77c819ef730f316",
        "name": "Fetch Snapshot",
        "method": "GET",
        "ret": "bin",
        "paytoqs": "ignore",
        "url": "http://172.16.201.21:5000/api/events/{{payload.after.id}}/snapshot.jpg",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 1020,
        "y": 660,
        "wires": [
            [
                "build_email_fixed",
                "174d9cc817eabec9"
            ]
        ]
    },
    {
        "id": "0e5101a3d76bf6d4",
        "type": "e-mail",
        "z": "d77c819ef730f316",
        "server": "10.19.19.3",
        "port": "25",
        "authtype": "NONE",
        "saslformat": false,
        "token": "oauth2Response.access_token",
        "secure": false,
        "tls": false,
        "name": "jkilloran@doppio.ca",
        "dname": "Send Email",
        "x": 1470,
        "y": 780,
        "wires": []
    },
    {
        "id": "save_event",
        "type": "change",
        "z": "d77c819ef730f316",
        "name": "Preserve Event",
        "rules": [
            {
                "t": "set",
                "p": "event",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "x": 800,
        "y": 580,
        "wires": [
            [
                "3ae47274abaf5e48",
                "24c0de584eef662c"
            ]
        ]
    },
    {
        "id": "build_email_fixed",
        "type": "function",
        "z": "d77c819ef730f316",
        "name": "Build Email (Fixed)",
        "func": "// Get label from preserved Frigate event\nvar label = msg.event.after.label;\n\n// Subject and body\nmsg.topic = \"Frigate Alert - \" + label + \" detected\";\nmsg.body = \"Frigate detected a \" + label + \" at \" + new Date().toLocaleString();\n\n// Visible From header\nmsg.from = \"camera@mapletree.email\";\n\n// Force SMTP envelope sender (if supported)\nmsg.envelope = {\n  from: \"camera@mapletree.email\",\n  to: [\"jkilloran@doppio.ca\"]\n};\n\n// Attach snapshot (binary buffer from HTTP Request node)\nmsg.attachments = [\n  {\n    filename: \"snapshot.jpg\",\n    content: msg.payload,   // snapshot buffer\n    encoding: \"binary\"\n  }\n];\n\n// Set payload to email body text\nmsg.payload = msg.body;\n\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1250,
        "y": 720,
        "wires": [
            [
                "0e5101a3d76bf6d4",
                "debug_after_email"
            ]
        ]
    },
    {
        "id": "debug_after_email",
        "type": "debug",
        "z": "d77c819ef730f316",
        "name": "Debug Before Send",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1490,
        "y": 680,
        "wires": []
    },
    {
        "id": "174d9cc817eabec9",
        "type": "debug",
        "z": "d77c819ef730f316",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1240,
        "y": 600,
        "wires": []
    },
    {
        "id": "24c0de584eef662c",
        "type": "debug",
        "z": "d77c819ef730f316",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1000,
        "y": 520,
        "wires": []
    }
]