Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Receive email -> Create work item -> Notify user
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"logicAppName": {
"type": "String",
"metadata": {
"description": "Name of the logic app."
}
},
"logicAppLocation": {
"defaultValue": "[resourceGroup().location]",
"allowedValues": [
"eastasia",
"southeastasia",
"centralus",
"eastus",
"eastus2",
"westus",
"northcentralus",
"southcentralus",
"northeurope",
"westeurope",
"japanwest",
"japaneast",
"brazilsouth",
"australiaeast",
"australiasoutheast",
"southindia",
"centralindia",
"westindia",
"canadacentral",
"canadaeast",
"westcentralus",
"westus2",
"[resourceGroup().location]"
],
"type": "String",
"metadata": {
"description": "Location of the logic app."
}
},
"slack_Connection_Name": {
"defaultValue": "slack",
"type": "String",
"metadata": {
"description": "Name of the connection."
}
},
"visualstudioteamservices_1_Connection_Name": {
"defaultValue": "visualstudioteamservices_1",
"type": "String",
"metadata": {
"description": "Name of the connection."
}
},
"outlook_Connection_Name": {
"defaultValue": "outlook",
"type": "String",
"metadata": {
"description": "Name of the connection."
}
},
"onedriveforbusiness_Connection_Name": {
"defaultValue": "onedriveforbusiness",
"type": "String",
"metadata": {
"description": "Name of the connection."
}
}
},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"name": "[parameters('logicAppName')]",
"apiVersion": "2016-06-01",
"location": "[parameters('logicAppLocation')]",
"properties": {
"state": "Disabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
},
"$authentication": {
"defaultValue": {},
"type": "SecureObject"
}
},
"triggers": {
"When_a_new_email_arrives": {
"recurrence": {
"interval": 1,
"frequency": "Minute"
},
"splitOn": "@triggerBody()?['value']",
"metadata": {
"flowSystemMetadata": {
"swaggerOperationId": "OnNewEmail"
}
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['outlook']['connectionId']"
}
},
"method": "get",
"path": "/Mail/OnNewEmail",
"queries": {
"folderPath": "Inbox",
"importance": "Any",
"fetchOnlyWithAttachment": false,
"includeAttachments": true
},
"authentication": "@parameters('$authentication')"
}
}
},
"actions": {
"Post_message": {
"runAfter": {
"Scope": [
"Failed"
]
},
"metadata": {
"flowSystemMetadata": {
"swaggerOperationId": "PostMessage"
}
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['slack']['connectionId']"
}
},
"method": "post",
"path": "/chat.postMessage",
"queries": {
"channel": "CE0MK78ET",
"text": "ERROR with @{triggerBody()?['Subject']}",
"username": "Microsoft Flow"
},
"authentication": "@parameters('$authentication')"
}
},
"Scope": {
"actions": {
"Is_an_incidence": {
"actions": {
"Create_BUG": {
"runAfter": {},
"metadata": {
"flowSystemMetadata": {
"swaggerOperationId": "CreateWorkItem"
}
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['visualstudioteamservices_1']['connectionId']"
}
},
"method": "patch",
"body": {
"title": "@triggerBody()?['Subject']",
"description": "@{variables('ParsedBody')}\n",
"area": "DEDALUS\\Incidences (Bugs)",
"dynamicFields": {
"System.Tags": "@{triggerBody()?['From']};@{if(triggerBody()?['HasAttachment'], 'Attachments', 'NoAttachments')}"
}
},
"path": "/@{encodeURIComponent('DEDALUS')}/_apis/wit/workitems/$Bug",
"queries": {
"account": "CEDEC"
},
"authentication": "@parameters('$authentication')"
}
}
},
"runAfter": {},
"else": {
"actions": {
"Is_a_requirement": {
"actions": {
"Create_User_Story_(Requirement)": {
"runAfter": {},
"metadata": {
"flowSystemMetadata": {
"swaggerOperationId": "CreateWorkItem"
}
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['visualstudioteamservices_1']['connectionId']"
}
},
"method": "patch",
"body": {
"title": "@triggerBody()?['Subject']",
"description": "@variables('ParsedBody')",
"area": "DEDALUS\\Requirements (Development)",
"dynamicFields": {
"System.Tags": "@{triggerBody()?['From']};@{if(triggerBody()?['HasAttachment'], 'Attachments', 'NoAttachments')}"
}
},
"path": "/@{encodeURIComponent('DEDALUS')}/_apis/wit/workitems/$@{encodeURIComponent('User Story')}",
"queries": {
"account": "CEDEC"
},
"authentication": "@parameters('$authentication')"
}
}
},
"runAfter": {},
"else": {
"actions": {
"Create_User_Story_(To_evaluate)": {
"runAfter": {},
"metadata": {
"flowSystemMetadata": {
"swaggerOperationId": "CreateWorkItem"
}
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['visualstudioteamservices_1']['connectionId']"
}
},
"method": "patch",
"body": {
"title": "@triggerBody()?['Subject']",
"description": "@variables('ParsedBody')",
"area": "DEDALUS",
"dynamicFields": {
"System.Tags": "@{triggerBody()?['From']};@{if(triggerBody()?['HasAttachment'], 'Attachments', 'NoAttachments')}"
}
},
"path": "/@{encodeURIComponent('DEDALUS')}/_apis/wit/workitems/$@{encodeURIComponent('User Story')}",
"queries": {
"account": "CEDEC"
},
"authentication": "@parameters('$authentication')"
}
}
}
},
"expression": "@contains(toUpper(triggerBody()?['Subject']), 'REQ')",
"type": "If"
}
}
},
"expression": "@contains(toUpper(triggerBody()?['Subject']), 'INC')",
"type": "If"
},
"Reply_to_user_with_confirmation_message": {
"runAfter": {
"Is_an_incidence": [
"Succeeded"
]
},
"metadata": {
"flowSystemMetadata": {
"swaggerOperationId": "ReplyToV2"
}
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['outlook']['connectionId']"
}
},
"method": "post",
"body": {
"Body": "Your ticket has been received and you will be notified as soon we start working on it.",
"IsHtml": true
},
"path": "/v2/Mail/ReplyTo/@{encodeURIComponent(triggerBody()?['Id'])}",
"authentication": "@parameters('$authentication')"
}
}
},
"runAfter": {
"Apply_to_each": [
"Succeeded"
]
},
"type": "Scope"
},
"Apply_to_each": {
"foreach": "@triggerBody()?['Attachments']",
"actions": {
"Parse_JSON": {
"runAfter": {},
"type": "ParseJson",
"inputs": {
"content": "@items('Apply_to_each')",
"schema": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"Name": {
"type": "string"
},
"ContentBytes": {
"type": "string"
},
"ContentType": {
"type": "string"
},
"Size": {
"type": "integer"
}
}
}
}
},
"Attachment_is_in_body": {
"actions": {
"Img": {
"runAfter": {},
"type": "Compose",
"inputs": "@concat('src=\"cid:', body('Parse_JSON')?['Name'])"
},
"Replacement": {
"runAfter": {
"Img": [
"Succeeded"
]
},
"type": "Compose",
"inputs": "@concat(concat('src=\"data:image/png;base64,', body('Parse_JSON')?['ContentBytes']), '\" data-id=\"')"
},
"ReplacedParsedBody": {
"runAfter": {
"Replacement": [
"Succeeded"
]
},
"type": "Compose",
"inputs": "@replace(variables('ParsedBody'), outputs('Img'), outputs('Replacement'))"
},
"Set_variable": {
"runAfter": {
"ReplacedParsedBody": [
"Succeeded"
]
},
"type": "SetVariable",
"inputs": {
"name": "ParsedBody",
"value": "@{outputs('ReplacedParsedBody')}"
}
}
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"else": {
"actions": {
"Create_file": {
"runAfter": {},
"metadata": {
"flowSystemMetadata": {
"swaggerOperationId": "CreateFile"
}
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['onedriveforbusiness']['connectionId']"
}
},
"method": "post",
"body": "@base64ToBinary(body('Parse_JSON')?['ContentBytes'])",
"path": "/datasets/default/files",
"queries": {
"folderPath": "/TicketingAttachments/@{triggerBody()?['From']}/@{triggerBody()?['Subject']}",
"name": "@body('Parse_JSON')?['Name']"
},
"authentication": "@parameters('$authentication')"
},
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
}
},
"Add_attachment_to_body": {
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "Compose",
"inputs": "@replace(variables('ParsedBody'), '</body>', concat(outputs('Compose'), '</body>'))"
},
"Set_variable_2": {
"runAfter": {
"Add_attachment_to_body": [
"Succeeded"
]
},
"type": "SetVariable",
"inputs": {
"name": "ParsedBody",
"value": "@{outputs('Add_attachment_to_body')}"
}
},
"Compose": {
"runAfter": {
"Create_share_link": [
"Succeeded"
]
},
"type": "Compose",
"inputs": "<a href=\"@{body('Create_share_link')?['WebUrl']}\" target=\"_blank\">@{body('Create_file')?['DisplayName']}</a><br>"
},
"Create_share_link": {
"runAfter": {
"Create_file": [
"Succeeded"
]
},
"metadata": {
"flowSystemMetadata": {
"swaggerOperationId": "CreateShareLink"
}
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['onedriveforbusiness']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(body('Create_file')?['Id']))}/share",
"queries": {
"type": "Direct",
"scope": "Anonymous"
},
"authentication": "@parameters('$authentication')"
}
}
}
},
"expression": "@contains(variables('ParsedBody'), concat('cid:', body('Parse_JSON')?['Name']))",
"type": "If"
}
},
"runAfter": {
"Initialize_ParsedBody": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_ParsedBody": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "ParsedBody",
"type": "String",
"value": "@triggerBody()?['Body']"
}
]
}
}
},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"slack": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'slack')]",
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('slack_Connection_Name'))]",
"connectionName": "[parameters('slack_Connection_Name')]"
},
"visualstudioteamservices_1": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'visualstudioteamservices_1')]",
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('visualstudioteamservices_1_Connection_Name'))]",
"connectionName": "[parameters('visualstudioteamservices_1_Connection_Name')]"
},
"outlook": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'outlook')]",
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('outlook_Connection_Name'))]",
"connectionName": "[parameters('outlook_Connection_Name')]"
},
"onedriveforbusiness": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'onedriveforbusiness')]",
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('onedriveforbusiness_Connection_Name'))]",
"connectionName": "[parameters('onedriveforbusiness_Connection_Name')]"
}
}
}
},
"runtimeConfiguration": {
"collections": {
"maximumItemCount": 100000
},
"performanceProfile": {
"throttles": {
"mode": "Medium"
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/connections', parameters('slack_Connection_Name'))]",
"[resourceId('Microsoft.Web/connections', parameters('visualstudioteamservices_1_Connection_Name'))]",
"[resourceId('Microsoft.Web/connections', parameters('outlook_Connection_Name'))]",
"[resourceId('Microsoft.Web/connections', parameters('onedriveforbusiness_Connection_Name'))]"
]
},
{
"type": "Microsoft.Web/connections",
"name": "[parameters('slack_Connection_Name')]",
"apiVersion": "2016-06-01",
"location": "[parameters('logicAppLocation')]",
"properties": {
"api": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'slack')]"
},
"displayName": "[parameters('slack_Connection_Name')]"
}
},
{
"type": "Microsoft.Web/connections",
"name": "[parameters('visualstudioteamservices_1_Connection_Name')]",
"apiVersion": "2016-06-01",
"location": "[parameters('logicAppLocation')]",
"properties": {
"api": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'visualstudioteamservices_1')]"
},
"displayName": "[parameters('visualstudioteamservices_1_Connection_Name')]"
}
},
{
"type": "Microsoft.Web/connections",
"name": "[parameters('outlook_Connection_Name')]",
"apiVersion": "2016-06-01",
"location": "[parameters('logicAppLocation')]",
"properties": {
"api": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'outlook')]"
},
"displayName": "[parameters('outlook_Connection_Name')]"
}
},
{
"type": "Microsoft.Web/connections",
"name": "[parameters('onedriveforbusiness_Connection_Name')]",
"apiVersion": "2016-06-01",
"location": "[parameters('logicAppLocation')]",
"properties": {
"api": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'onedriveforbusiness')]"
},
"displayName": "[parameters('onedriveforbusiness_Connection_Name')]"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.