{ "$connections": { "value": { "azureblob": { "connectionId": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/resourceGroups/HomeMonitorRG/providers/Microsoft.Web/connections/azureblob", "connectionName": "azureblob", "id": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/providers/Microsoft.Web/locations/westus/managedApis/azureblob" }, "cognitiveservicescomputervision": { "connectionId": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/resourceGroups/HomeMonitorRG/providers/Microsoft.Web/connections/cognitiveservicescomputervision", "connectionName": "cognitiveservicescomputervision", "id": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/providers/Microsoft.Web/locations/westus/managedApis/cognitiveservicescomputervision" }, "documentdb": { "connectionId": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/resourceGroups/HomeMonitorRG/providers/Microsoft.Web/connections/documentdb", "connectionName": "documentdb", "id": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/providers/Microsoft.Web/locations/westus/managedApis/documentdb" }, "faceapi": { "connectionId": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/resourceGroups/HomeMonitorRG/providers/Microsoft.Web/connections/faceapi", "connectionName": "faceapi", "id": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/providers/Microsoft.Web/locations/westus/managedApis/faceapi" }, "gmail": { "connectionId": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/resourceGroups/HomeMonitorRG/providers/Microsoft.Web/connections/gmail", "connectionName": "gmail", "id": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/providers/Microsoft.Web/locations/westus/managedApis/gmail" }, "outlook": { "connectionId": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/resourceGroups/HomeMonitorRG/providers/Microsoft.Web/connections/outlook", "connectionName": "outlook", "id": "/subscriptions/904601cc-7d50-4b1a-8594-7327faa8b6b7/providers/Microsoft.Web/locations/westus/managedApis/outlook" } } }, "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "For_each": { "actions": { "Create_blob": { "inputs": { "body": "@base64ToBinary(items('For_each')?['ContentBytes'])", "host": { "connection": { "name": "@parameters('$connections')['azureblob']['connectionId']" } }, "method": "post", "path": "/datasets/default/files", "queries": { "folderPath": "/camera", "name": "@items('For_each')?['Name']" } }, "runAfter": { "Get_attachment": [ "Succeeded" ] }, "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } }, "type": "ApiConnection" }, "Create_or_update_document": { "inputs": { "body": { "blob": { "blobId": "@body('Create_blob')?['Id']", "size": "@body('Create_blob')?['Size']", "url": "https://storagename.blob.core.windows.net@{body('Create_blob')?['Path']}" }, "email": { "receivedDate": "@body('Get_email')?['DateTimeReceived']", "subject": "@body('Get_email')['Subject']" }, "faces": "@json(variables('faceDetectionJSON'))", "id": "@items('For_each')?['Name']", "imageVision": "@body('Tag_Image')", "isPerson": "@variables('isPerson')" }, "headers": { "x-ms-documentdb-is-upsert": true }, "host": { "connection": { "name": "@parameters('$connections')['documentdb']['connectionId']" } }, "method": "post", "path": "/dbs/@{encodeURIComponent('Camera')}/colls/@{encodeURIComponent('PictureInfo')}/docs" }, "runAfter": { "For_each_computer_vision_tag": [ "Succeeded" ] }, "type": "ApiConnection" }, "For_each_computer_vision_tag": { "actions": { "Append_to_emailTags_variable": { "inputs": { "name": "emailTags", "value": "@concat('
  • ', items('For_each_computer_vision_tag')?['name'], ' ', substring(string(items('For_each_computer_vision_tag')?['confidence']), 0, 4), ' confident
    ')" }, "runAfter": {}, "type": "AppendToStringVariable" }, "If_a_person_(confidence_over_.5)": { "actions": { "Detect_faces": { "inputs": { "body": { "url": "https://storagename.blob.core.windows.net@{body('Create_blob')?['Path']}" }, "host": { "connection": { "name": "@parameters('$connections')['faceapi']['connectionId']" } }, "method": "post", "path": "/face/v1.0/detect", "queries": { "returnFaceAttributes": "age,gender,headPose,smile,facialHair,glasses", "returnFaceId": "true", "returnFaceLandmarks": "true" } }, "runAfter": { "Set_isPerson_true": [ "Succeeded" ] }, "type": "ApiConnection" }, "For_Each_Face": { "actions": { "Append_to_emailFaceInfo": { "inputs": { "name": "emailFaceInfo", "value": "@outputs('Compose')" }, "runAfter": { "Compose": [ "Succeeded" ] }, "type": "AppendToStringVariable" }, "Compose": { "inputs": "\n
  • @{items('For_Each_Face')?['faceAttributes']?['age']} year old @{items('For_Each_Face')?['faceAttributes']?['gender']} • @{items('For_Each_Face')?['faceAttributes']?['glasses']} • @{items('For_Each_Face')?['faceAttributes']?['facialHair']}
  • \n", "runAfter": {}, "type": "Compose" } }, "foreach": "@body('Detect_faces')", "runAfter": { "Detect_faces": [ "Succeeded" ] }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } }, "type": "Foreach" }, "Set_isPerson_true": { "inputs": { "name": "isPerson", "value": true }, "runAfter": {}, "type": "SetVariable" }, "Set_variable_faceDetectionJSON": { "inputs": { "name": "faceDetectionJSON", "value": "@string(body('Detect_Faces'))" }, "runAfter": { "For_Each_Face": [ "Succeeded" ] }, "type": "SetVariable" } }, "expression": "@and(equals(items('For_each_computer_vision_tag')?['name'], 'person'), greater(float(items('For_each_computer_vision_tag')?['confidence']), 0.5))", "runAfter": { "Append_to_emailTags_variable": [ "Succeeded" ] }, "type": "If" } }, "foreach": "@body('Tag_Image')?['tags']", "runAfter": { "Reset_emailFaceInfo_null": [ "Succeeded" ] }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } }, "type": "Foreach" }, "Get_attachment": { "inputs": { "host": { "connection": { "name": "@parameters('$connections')['outlook']['connectionId']" } }, "method": "get", "path": "/Mail/@{encodeURIComponent(body('Get_email')?['Id'])}/Attachments/@{encodeURIComponent(items('For_each')?['Id'])}" }, "runAfter": {}, "type": "ApiConnection" }, "If_a_person": { "actions": { "Send_email": { "inputs": { "body": { "Attachments": [ { "ContentBytes": "@{items('For_each')?['ContentBytes']}", "ContentType": "@items('For_each')?['ContentType']", "Name": "@items('For_each')?['Name']" } ], "Body": "Objects detected:
    \n\n\nFaces detected:
    \n", "Subject": " Person detected: @{body('Get_email')['Subject']} ", "To": "someoneone@gmail.com" }, "host": { "connection": { "name": "@parameters('$connections')['gmail']['connectionId']" } }, "method": "post", "path": "/Mail" }, "runAfter": {}, "type": "ApiConnection" } }, "expression": "@equals(variables('isPerson'), true)", "runAfter": { "Create_or_update_document": [ "Succeeded" ] }, "type": "If" }, "Reset_emailFaceInfo_null": { "inputs": { "name": "emailFaceInfo", "value": "@{null}" }, "runAfter": { "Reset_emailTags_empty": [ "Succeeded" ] }, "type": "SetVariable" }, "Reset_emailTags_empty": { "inputs": { "name": "emailTags", "value": " " }, "runAfter": { "Reset_isPerson_false": [ "Succeeded" ] }, "type": "SetVariable" }, "Reset_isPerson_false": { "inputs": { "name": "isPerson", "value": false }, "runAfter": { "Tag_Image": [ "Succeeded" ] }, "type": "SetVariable" }, "Tag_Image": { "inputs": { "body": "@base64ToBinary(items('For_each')?['ContentBytes'])", "host": { "connection": { "name": "@parameters('$connections')['cognitiveservicescomputervision']['connectionId']" } }, "method": "post", "path": "/vision/v1.0/tag", "queries": { "format": "Image Content" } }, "runAfter": { "Create_blob": [ "Succeeded" ] }, "type": "ApiConnection" } }, "foreach": "@body('Get_email')?['Attachments']", "runAfter": { "Initialize_variable_emailFaceInfo": [ "Succeeded" ] }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } }, "type": "Foreach" }, "Get_email": { "inputs": { "host": { "connection": { "name": "@parameters('$connections')['outlook']['connectionId']" } }, "method": "get", "path": "/Mail/@{encodeURIComponent(triggerBody()?['Id'])}", "queries": { "includeAttachments": true } }, "runAfter": {}, "type": "ApiConnection" }, "Initialize_variable_emailFaceInfo": { "inputs": { "variables": [ { "name": "emailFaceInfo", "type": "String", "value": "@{null}" } ] }, "runAfter": { "Initialize_variable_faceDetectJSON": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_variable_emailTags": { "inputs": { "variables": [ { "name": "emailTags", "type": "String" } ] }, "runAfter": { "Initialize_variable_isPerson": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_variable_faceDetectJSON": { "inputs": { "variables": [ { "name": "faceDetectionJSON", "type": "String" } ] }, "runAfter": { "Initialize_variable_emailTags": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_variable_isPerson": { "inputs": { "variables": [ { "name": "isPerson", "type": "Boolean", "value": false } ] }, "runAfter": { "Get_email": [ "Succeeded" ] }, "type": "InitializeVariable" } }, "contentVersion": "1.0.0.0", "outputs": {}, "parameters": { "$connections": { "defaultValue": {}, "type": "Object" } }, "triggers": { "When_a_new_email_arrives": { "inputs": { "host": { "connection": { "name": "@parameters('$connections')['outlook']['connectionId']" } }, "method": "get", "path": "/Mail/OnNewEmail", "queries": { "fetchOnlyWithAttachment": true, "folderPath": "Inbox", "importance": "Any", "includeAttachments": true, "subjectFilter": "alarm" } }, "recurrence": { "frequency": "Minute", "interval": 1 }, "splitOn": "@triggerBody()?['value']", "type": "ApiConnection" } } } }