{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "Location": { "type": "string", "defaultValue": "[resourceGroup().location]", "allowedValues": [ "[resourceGroup().location]", "eastasia", "southeastasia", "centralus", "eastus", "eastus2", "westus", "northcentralus", "southcentralus", "northeurope", "westeurope", "japanwest", "japaneast", "brazilsouth", "australiaeast", "australiasoutheast", "southindia", "centralindia", "westindia", "canadacentral", "canadaeast", "uksouth", "ukwest", "westcentralus", "westus2", "koreacentral", "koreasouth", "francecentral", "francesouth", "southafricanorth", "southafricawest" ], "metadata": { "description": "Location of the Logic Apps." } }, "ConnectorBaseName": { "type": "string", "defaultValue": "PuzzelConnectorBase" }, "ConnectorTriggeredName": { "type": "string", "defaultValue": "PuzzelConnectorEmailTriggered" }, "ConnectorManualName": { "type": "string", "defaultValue": "PuzzelConnectorManualRun" }, "Office365ConnectionName": { "type": "string", "defaultValue": "office365" }, "IntegrationAccountName": { "type": "string", "defaultValue": "PuzzelConnectorIntegrationAccount" }, "IsForOutlook": { "type": "bool", "defaultValue": false, "metadata": { "description": "Set to 'true' to enable emails to be opened in Outlook (additional settings required on agents PCs)" } }, "ClientID": { "type": "String", "metadata": { "description": "Application/Client ID. (from App registration)." } }, "Secret": { "type": "securestring", "metadata": { "description": "A secret string that the application uses to prove its identity when requesting a token. (from App registration)." } }, "TenantID": { "type": "String", "metadata": { "description": "Directory/Tenant ID. (from App registration)." } }, "Email": { "type": "String", "metadata": { "description": "The email address from which the messages will be triggered." } }, "PuzzelCustomerKey": { "type": "String", "metadata": { "description": "The Customer Key in Puzzel." } }, "PuzzelPassword": { "type": "securestring", "metadata": { "description": "The Password for Puzzel user." } }, "PuzzelUser": { "type": "String", "metadata": { "description": "The Puzzel User." } }, "PuzzelAccessPoint": { "type": "String", "metadata": { "description": "The Access Point(Email address) in Puzzel." } }, "OnErrorEmail": { "type": "String", "metadata": { "description": "Email address to which messages will be sent when an error occurs.WARNING! This Email must be different from registered for triggering." } } }, "variables": { "baseConnector": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/',resourceGroup().name,'/providers/Microsoft.Logic/workflows/',parameters('ConnectorBaseName'))]" }, "resources": [ { "type": "Microsoft.Logic/integrationAccounts", "apiVersion": "2016-06-01", "name": "[parameters('IntegrationAccountName')]", "location": "[parameters('Location')]", "sku": { "name": "Free" }, "properties": { "state": "Enabled" } }, { "type": "MICROSOFT.WEB/CONNECTIONS", "apiVersion": "2018-07-01-preview", "name": "[parameters('Office365ConnectionName')]", "location": "[parameters('Location')]", "properties": { "api": { "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('Location'), '/managedApis/', 'office365')]" }, "displayName": "[parameters('Email')]", "parameterValues": { } } }, { "name": "[parameters('ConnectorBaseName')]", "type": "Microsoft.Logic/workflows", "location": "[parameters('Location')]", "apiVersion": "2016-06-01", "dependsOn": [ "[resourceId('Microsoft.Logic/integrationAccounts', parameters('IntegrationAccountName'))]" ], "tags": { "displayName": "ConnectorBase" }, "properties": { "integrationAccount": { "id": "[resourceId(subscription().subscriptionId, resourceGroup().name, 'Microsoft.Logic/integrationAccounts', parameters('IntegrationAccountName'))]" }, "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "Condition": { "actions": { "GetOutlookIdBody": { "inputs": "@body('Get_Outlook_Id')", "runAfter": { "Get_Outlook_Id": [ "Succeeded" ] }, "type": "Compose" }, "Get_Outlook_Id": { "inputs": { "authentication": { "audience": "https://outlook.office365.com", "clientId": "@parameters('ClientID')", "secret": "@parameters('Secret')", "tenant": "@parameters('TenantID')", "type": "ActiveDirectoryOAuth" }, "body": { "InputIds": [ "@{triggerBody()?['id']}" ], "SourceIdType": "restId", "TargetIdType": "entryId" }, "method": "POST", "uri": "https://outlook.office365.com/api/v2.0/users/@{triggerBody()?['UserId']}/translateExchangeIds" }, "runAfter": {}, "type": "Http" }, "OutLinkForOutlook": { "inputs": { "code": "var obj = workflowContext.actions.GetOutlookIdBody.outputs;\r\nvar targetId = obj.value[0].TargetId;\r\nid = targetId.replace('_', '+').replace('-', '/');\r\nid = targetId.replace('_', '+').replace('-', '/');\r\nid = targetId.replace('_', '+').replace('-', '/');\r\nvar eqCount = parseInt(id.slice(-1));\r\nvar s = id.slice(0, -1)+'='.repeat(eqCount);\r\n\r\nvar e={},i,b=0,c,x,l=0,a,r='',w=String.fromCharCode,L=s.length;\r\nvar A = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\r\nfor(i=0;i<64;i++){e[A.charAt(i)]=i;}\r\nfor(x=0;x=8){((a=(b>>>(l-=8))&0xff)||(x<(L-2)))&&(r+=w(a));}\r\n}\r\nvar result = '';\r\nfor (var i = 0; i < r.length; i++) {\r\n var hex = r.charCodeAt(i).toString(16);\r\n result += (hex.length === 2 ? hex : '0' + hex);\r\n}\r\nreturn 'Outlook:'+result.toUpperCase();" }, "runAfter": { "GetOutlookIdBody": [ "Succeeded" ] }, "type": "JavaScriptCode" }, "Set_variable_2": { "inputs": { "name": "OutLink", "value": "@{outputs('OutLinkForOutlook')?['body']}" }, "runAfter": { "OutLinkForOutlook": [ "Succeeded" ] }, "type": "SetVariable" } }, "expression": { "and": [ { "equals": [ "@parameters('IsForOutlook')", true ] } ] }, "runAfter": { "Initialize_var_OutFrom": [ "Succeeded" ] }, "type": "If" }, "Get_Email_Data": { "inputs": { "authentication": { "audience": "https://outlook.office365.com", "clientId": "@parameters('ClientID')", "secret": "@parameters('Secret')", "tenant": "@parameters('TenantID')", "type": "ActiveDirectoryOAuth" }, "method": "GET", "uri": "https://outlook.office365.com/api/v2.0/users/@{triggerBody()?['UserId']}/messages/@{triggerBody()?['Id']}" }, "runAfter": {}, "type": "Http" }, "HTTP": { "inputs": { "authentication": { "type": "Raw", "value": "@concat('Bearer ',body('Puzzel_Auth_JSON')?['accessToken'])" }, "body": { "eTask": { "from": "@{variables('OutFrom')}", "subject": "@{body('Parse_Email_JSON')?['Subject']}", "to": "@{triggerBody()?['AccessPoint']}", "uri": "@{variables('OutLink')}" } }, "headers": { "Content-Type": "application/json" }, "method": "POST", "uri": "https://api.puzzel.com/contactcentre5/customers/@{parameters('PuzzelCustomerKey')}/etasks" }, "runAfter": { "Puzzel_Auth_JSON": [ "Succeeded" ] }, "type": "Http" }, "Initialize_var_OutFrom": { "inputs": { "variables": [ { "name": "OutFrom", "type": "string", "value": "@{concat(body('Parse_Email_JSON')?['Sender']?['EmailAddress']?['Name'],' <',body('Parse_Email_JSON')?['Sender']?['EmailAddress']?['Address'],'>')}" } ] }, "runAfter": { "Initialize_var_OutLink": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_var_OutLink": { "inputs": { "variables": [ { "name": "OutLink", "type": "string", "value": "@body('Parse_Email_JSON')?['WebLink']" } ] }, "runAfter": { "Parse_Email_JSON": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Parse_Email_JSON": { "inputs": { "content": "@body('Get_Email_Data')", "schema": { "properties": { "From": { "properties": { "EmailAddress": { "properties": { "Address": { "type": "string" }, "Name": { "type": "string" } }, "type": "object" } }, "type": "object" }, "Id": { "type": "string" }, "Sender": { "properties": { "EmailAddress": { "properties": { "Address": { "type": "string" }, "Name": { "type": "string" } }, "type": "object" } }, "type": "object" }, "Subject": { "type": "string" }, "ToRecipients": { "items": { "properties": { "EmailAddress": { "properties": { "Address": { "type": "string" }, "Name": { "type": "string" } }, "type": "object" } }, "required": [ "EmailAddress" ], "type": "object" }, "type": "array" }, "WebLink": { "type": "string" } }, "type": "object" } }, "runAfter": { "Get_Email_Data": [ "Succeeded" ] }, "type": "ParseJson" }, "Puzzel_Api_Call_JSON": { "inputs": { "content": "@body('HTTP')", "schema": { "properties": { "code": { "type": "integer" } }, "type": "object" } }, "runAfter": { "HTTP": [ "Succeeded" ] }, "type": "ParseJson" }, "Puzzel_Auth": { "inputs": { "body": { "customerKey": "@{parameters('PuzzelCustomerKey')}", "password": "@{parameters('PuzzelPassword')}", "userName": "@{parameters('PuzzelUser')}" }, "method": "POST", "uri": "@parameters('PuzzelAuthURL')" }, "runAfter": { "Condition": [ "Succeeded" ] }, "runtimeConfiguration": { "secureData": { "properties": [ "inputs" ] } }, "type": "Http" }, "Puzzel_Auth_JSON": { "inputs": { "content": "@body('Puzzel_Auth')", "schema": { "properties": { "accessToken": { "type": "string" }, "twoFactorRequired": { "type": "boolean" } }, "type": "object" } }, "runAfter": { "Puzzel_Auth": [ "Succeeded" ] }, "type": "ParseJson" }, "Response": { "inputs": { "statusCode": "@if(equals(body('Puzzel_Api_Call_JSON')?['code'],0),'200','500')" }, "kind": "Http", "runAfter": { "Puzzel_Api_Call_JSON": [ "Succeeded" ] }, "type": "Response" } }, "contentVersion": "1.0.0.0", "outputs": {}, "parameters": { "ClientID": { "defaultValue": "[parameters('ClientID')]", "type": "String" }, "IsForOutlook": { "defaultValue": "[parameters('IsForOutlook')]", "type": "Bool" }, "PuzzelAuthURL": { "defaultValue": "https://auth.puzzel.com/api/Authenticate/LogIn", "type": "String" }, "PuzzelCustomerKey": { "defaultValue": "[parameters('PuzzelCustomerKey')]", "type": "String" }, "PuzzelPassword": { "type": "securestring" }, "PuzzelUser": { "defaultValue": "[parameters('PuzzelUser')]", "type": "String" }, "Secret": { "type": "securestring" }, "TenantID": { "defaultValue": "[parameters('TenantID')]", "type": "String" } }, "triggers": { "manual": { "inputs": { "schema": { "properties": { "AccessPoint": { "type": "string" }, "Id": { "type": "string" }, "UserId": { "type": "string" } }, "type": "object" } }, "kind": "Http", "type": "Request" } } }, "parameters": { "PuzzelPassword": { "value": "[parameters('PuzzelPassword')]" }, "Secret": { "value": "[parameters('Secret')]" } } } }, { "name": "[parameters('ConnectorTriggeredName')]", "type": "Microsoft.Logic/workflows", "location": "[parameters('Location')]", "apiVersion": "2016-06-01", "dependsOn": [ "[resourceId('Microsoft.Web/connections', parameters('Office365ConnectionName'))]", "[resourceId('Microsoft.Logic/workflows', parameters('ConnectorBaseName'))]" ], "tags": { "displayName": "ConnectorEmailTriggered" }, "properties": { "state": "Disabled", "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "Office365ConnectorBase": { "inputs": { "body": { "AccessPoint": "@parameters('AccessPoint')", "Id": "@triggerBody()?['id']", "UserId": "@parameters('UserId')" }, "host": { "triggerName": "manual", "workflow": { "id": "[resourceId(subscription().subscriptionId, resourceGroup().name, 'Microsoft.Logic/workflows', parameters('ConnectorBaseName'))]" } }, "retryPolicy": { "count": 5, "interval": "PT5M", "maximumInterval": "PT2H", "type": "exponential" } }, "runAfter": {}, "type": "Workflow" }, "Send_an_email_(V2)_2": { "inputs": { "body": { "Body": "

Office365Connector was unable to send email to Puzzel.
\nEmail from:@{triggerBody()?['from']}
\nSubject:@{triggerBody()?['subject']}

", "Subject": "Error from Office365Connector ", "To": "@parameters('OnErrorEmail')" }, "host": { "connection": { "name": "@parameters('$connections')['office365']['connectionId']" } }, "method": "post", "path": "/v2/Mail" }, "runAfter": { "Office365ConnectorBase": [ "Failed", "Skipped", "TimedOut" ] }, "type": "ApiConnection" } }, "contentVersion": "1.0.0.0", "outputs": {}, "parameters": { "$connections": { "defaultValue": {}, "type": "Object" }, "AccessPoint": { "defaultValue": "[parameters('PuzzelAccessPoint')]", "type": "String" }, "OnErrorEmail": { "defaultValue": "[parameters('OnErrorEmail')]", "type": "String" }, "UserId": { "defaultValue": "[parameters('Email')]", "type": "String" } }, "triggers": { "When_a_new_email_arrives_(V3)": { "inputs": { "fetch": { "method": "get", "pathTemplate": { "template": "/v3/Mail/OnNewEmail" }, "queries": { "folderPath": "Inbox", "importance": "Any", "includeAttachments": false } }, "host": { "connection": { "name": "@parameters('$connections')['office365']['connectionId']" } }, "subscribe": { "body": { "NotificationUrl": "@{listCallbackUrl()}" }, "method": "post", "pathTemplate": { "template": "/GraphMailSubscriptionPoke/$subscriptions" }, "queries": { "folderPath": "Inbox", "importance": "Any" } } }, "splitOn": "@triggerBody()?['value']", "type": "ApiConnectionNotification" } } }, "parameters": { "$connections": { "value": { "office365": { "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('Location'), '/managedApis/', 'office365')]", "connectionId": "[resourceId('Microsoft.Web/connections', parameters('office365ConnectionName'))]", "connectionName": "[parameters('office365ConnectionName')]" } } } } } }, { "name": "[parameters('ConnectorManualName')]", "type": "Microsoft.Logic/workflows", "location": "[parameters('Location')]", "apiVersion": "2016-06-01", "dependsOn": [ "[resourceId('Microsoft.Logic/workflows', parameters('ConnectorBaseName'))]" ], "tags": { "displayName": "ConnectorEmailManual" }, "properties": { "state": "Disabled", "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "HTTP": { "inputs": { "authentication": { "audience": "https://outlook.office365.com", "clientId": "@parameters('ClientID')", "secret": "@parameters('Secret')", "tenant": "@parameters('TenantID')", "type": "ActiveDirectoryOAuth" }, "method": "GET", "uri": "https://outlook.office365.com/api/v2.0/users/@{parameters('UserId')}/messages/?$select=Id & top=1000 & $filter=isRead eq false and receivedDateTime gt @{getPastTime(parameters('DaysToTake'),'Day') } " }, "type": "Http" }, "For_each": { "actions": { "Office365ConnectorBase": { "inputs": { "body": { "Id": "@items('For_each')?['Id']", "AccessPoint": "@parameters('AccessPoint')", "UserId": "@parameters('UserId')" }, "host": { "triggerName": "manual", "workflow": { "id": "[resourceId(subscription().subscriptionId, resourceGroup().name, 'Microsoft.Logic/workflows', parameters('ConnectorBaseName'))]" } }, "retryPolicy": { "type": "none" } }, "runAfter": {}, "type": "Workflow" } }, "foreach": "@body('Parse_JSON')?['value']", "runAfter": { "Parse_JSON": [ "Succeeded" ] }, "type": "Foreach" }, "Parse_JSON": { "inputs": { "content": "@body('HTTP')", "schema": { "properties": { "@@odata.context": { "type": "string" }, "value": { "items": { "properties": { "Id": { "type": "string" } }, "required": [ "@@odata.id", "@@odata.etag", "Id" ], "type": "object" }, "type": "array" } }, "type": "object" } }, "runAfter": { "HTTP": [ "Succeeded" ] }, "type": "ParseJson" } }, "contentVersion": "1.0.0.0", "outputs": {}, "parameters": { "AccessPoint": { "defaultValue": "[parameters('PuzzelAccessPoint')]", "type": "String" }, "ClientID": { "defaultValue": "[parameters('ClientID')]", "type": "String" }, "DaysToTake": { "defaultValue": 5, "type": "Int" }, "GetReadEmails": { "defaultValue": false, "type": "Bool" }, "Secret": { "type": "securestring" }, "TenantID": { "defaultValue": "[parameters('TenantID')]", "type": "String" }, "UserId": { "defaultValue": "[parameters('Email')]", "type": "String" } }, "triggers": { "manual": { "inputs": { "schema": {} }, "kind": "Http", "type": "Request" } } }, "parameters": { "Secret": { "value": "[parameters('Secret')]" } } } } ], "outputs": {} }