{
  "$schema": "https://schema.spbx.tel/v1/structs.realm.lib",
  "description": "Fax receive: importing this preset from a realm hooks a background CNG watcher in front of every call's dial plan; on detection the fax is received into the realm storage and the on_received slot runs.",
  "params": {
    "format": {
      "type": "string",
      "description": "Stored document format: pdf or tiff.",
      "default": "pdf"
    }
  },
  "slots": {
    "on_received": {
      "description": "Runs after a fax was received (e.g. a send_email flow). The document path is in %fax_file%, page count in %fax_pages%, result in %fax_result%."
    }
  },
  "exports": {
    "receive": {
      "description": "Stop audio and receive a fax on the current call.",
      "flow": "flows/sub_flow/receive"
    }
  },
  "hooks": {
    "before_dial_plan": [
      "flows/sub_task/watch_background"
    ]
  },
  "uses": {
    "std": {
      "preset": "stdlib"
    }
  },
  "flows": {
    "detect_fax": {
      "watch": {
        "dial_plan": [
          "flows/sub_flow/receive"
        ]
      }
    },
    "sub_task": {
      "watch_background": {
        "dial_plan": [
          "flows/detect_fax/watch"
        ]
      }
    },
    "receive_fax": {
      "document": {
        "file": "faxes/%fax_id%.${format}",
        "format": "${format}"
      }
    },
    "hangup": {
      "done": {
        "reason": "fax: session ended"
      }
    },
    "sub_flow": {
      "receive": {
        "dial_plan": [
          "presets/std/stop_all",
          "flows/receive_fax/document",
          "slots/on_received",
          "flows/hangup/done"
        ]
      }
    }
  }
}
