Skip to main content

paperless_api/
workflow.rs

1//! Types related to paperless workflows.
2
3use std::collections::HashMap;
4
5use serde::Deserialize;
6use serde_repr::{Deserialize_repr, Serialize_repr};
7
8/// A workflow
9#[derive(Debug, Clone, Deserialize)]
10pub struct Workflow {
11    /// Unique identifier of the workflow.
12    pub id: crate::id::WorkflowId,
13
14    /// Whether the workflow is enabled.
15    pub enabled: bool,
16
17    /// Name of the workflow.
18    pub name: String,
19
20    /// Order of the workflow in the list.
21    pub order: Option<i32>,
22
23    /// Triggers that determine when the workflow is executed.
24    pub triggers: Vec<WorkflowTrigger>,
25
26    /// Actions that are executed when the workflow is triggered.
27    pub actions: Vec<WorkflowAction>,
28}
29
30/// A trigger that determines when a workflow is executed.
31#[derive(Debug, Clone, Deserialize)]
32pub struct WorkflowTrigger {
33    pub id: crate::id::WorkflowTriggerId,
34
35    #[serde(rename = "type")]
36    pub trigger_type: WorkflowTriggerType,
37}
38
39/// An action that can be executed when a workflow is triggered.
40#[derive(Debug, Clone, Deserialize)]
41pub struct WorkflowAction {
42    pub id: crate::id::WorkflowActionId,
43
44    #[serde(rename = "type")]
45    pub action_type: WorkflowActionType,
46
47    pub webhook: Option<WebhookAction>,
48}
49
50/// The type of trigger that determines when a workflow is executed.
51#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
52#[repr(u8)]
53pub enum WorkflowTriggerType {
54    ProcessingStarted = 1,
55    DocumentAdded = 2,
56    DocumentUpdated = 3,
57    Scheduled = 4,
58}
59
60/// The type of action that is executed when a workflow is triggered.
61#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
62#[repr(u8)]
63pub enum WorkflowActionType {
64    Assign = 1,
65    Remove = 2,
66    Email = 3,
67    Webhook = 4,
68}
69
70/// A webhook action that can be executed when a workflow is triggered.
71#[derive(Debug, Clone, Deserialize)]
72pub struct WebhookAction {
73    pub id: crate::id::WebhookActionId,
74    pub url: String,
75
76    pub use_params: bool,
77    pub as_json: bool,
78    pub include_document: bool,
79
80    pub body: Option<String>,
81    pub headers: Option<HashMap<String, String>>,
82    pub params: Option<HashMap<String, String>>,
83}