{
  "_readme": "Trigger and the two guards of the S2-CaseScout-EmailIntake cloud flow, as exported from the sandbox on 26 Oct 2026. Fictional data, sandbox only. Paste the trigger parameters and the two conditions into your own flow; the mailbox address comes from an environment variable you create (Text), never from the definition.",
  "parameters": {
    "Merchant support mailbox (fpd_MerchantSupportMailbox)": {
      "defaultValue": "",
      "type": "String",
      "metadata": {
        "schemaName": "fpd_MerchantSupportMailbox",
        "description": "Queue mailbox address; the flow only processes email addressed to it"
      }
    }
  },
  "triggers": {
    "When_an_email_row_is_added": {
      "type": "OpenApiConnectionWebhook",
      "inputs": {
        "host": {
          "connectionName": "shared_commondataserviceforapps",
          "operationId": "SubscribeWebhookTrigger",
          "apiId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"
        },
        "parameters": {
          "subscriptionRequest/message": 1,
          "subscriptionRequest/entityname": "email",
          "subscriptionRequest/scope": 4,
          "subscriptionRequest/filterexpression": "directioncode eq false",
          "subscriptionRequest/runas": 1
        },
        "authentication": "@parameters('$authentication')"
      },
      "runtimeConfiguration": {
        "concurrency": {
          "runs": 5
        }
      }
    }
  },
  "actions": {
    "Guard_mailbox_and_regarding": {
      "type": "If",
      "expression": {
        "and": [
          {
            "contains": [
              "@toLower(coalesce(triggerOutputs()?['body/torecipients'], ''))",
              "@toLower(parameters('Merchant support mailbox (fpd_MerchantSupportMailbox)'))"
            ]
          },
          {
            "equals": [
              "@triggerOutputs()?['body/_regardingobjectid_value']",
              null
            ]
          }
        ]
      },
      "actions": {},
      "else": {
        "actions": {
          "Guard_note": {
            "type": "OpenApiConnection",
            "inputs": {
              "host": {
                "connectionName": "shared_commondataserviceforapps",
                "operationId": "CreateRecord",
                "apiId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"
              },
              "parameters": {
                "entityName": "annotations",
                "item/subject": "S2-CaseScout guard",
                "item/notetext": "@concat('Skipped: regarding=', coalesce(triggerOutputs()?['body/_regardingobjectid_value'], 'null'), '; mailbox match=', string(contains(toLower(coalesce(triggerOutputs()?['body/torecipients'], '')), toLower(parameters('Merchant support mailbox (fpd_MerchantSupportMailbox)')))))",
                "item/objectid_email@odata.bind": "/emails(@{triggerOutputs()?['body/activityid']})"
              },
              "authentication": "@parameters('$authentication')"
            },
            "runAfter": {}
          },
          "Terminate_guard": {
            "type": "Terminate",
            "inputs": {
              "runStatus": "Cancelled"
            },
            "runAfter": {
              "Guard_note": [
                "Succeeded"
              ]
            }
          }
        }
      },
      "runAfter": {}
    },
    "Guard_noise": {
      "type": "If",
      "expression": {
        "or": [
          {
            "startsWith": [
              "@toLower(coalesce(triggerOutputs()?['body/subject'], ''))",
              "automatic reply"
            ]
          },
          {
            "startsWith": [
              "@toLower(coalesce(triggerOutputs()?['body/subject'], ''))",
              "out of office"
            ]
          },
          {
            "contains": [
              "@toLower(coalesce(triggerOutputs()?['body/subject'], ''))",
              "undeliverable"
            ]
          },
          {
            "startsWith": [
              "@toLower(coalesce(triggerOutputs()?['body/sender'], ''))",
              "mailer-daemon"
            ]
          },
          {
            "startsWith": [
              "@toLower(coalesce(triggerOutputs()?['body/sender'], ''))",
              "postmaster"
            ]
          }
        ]
      },
      "actions": {
        "Noise_note": {
          "type": "OpenApiConnection",
          "inputs": {
            "host": {
              "connectionName": "shared_commondataserviceforapps",
              "operationId": "CreateRecord",
              "apiId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"
            },
            "parameters": {
              "entityName": "annotations",
              "item/subject": "S2-CaseScout guard",
              "item/notetext": "Skipped: auto-reply or delivery notification (loop guard); no case, no credits",
              "item/objectid_email@odata.bind": "/emails(@{triggerOutputs()?['body/activityid']})"
            },
            "authentication": "@parameters('$authentication')"
          },
          "runAfter": {}
        },
        "Terminate_noise": {
          "type": "Terminate",
          "inputs": {
            "runStatus": "Cancelled"
          },
          "runAfter": {
            "Noise_note": [
              "Succeeded"
            ]
          }
        }
      },
      "else": {
        "actions": {}
      },
      "runAfter": {
        "Guard_mailbox_and_regarding": [
          "Succeeded"
        ]
      }
    }
  }
}
