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
8use paperless_api_macros::{Item, UpdateDto};
9
10/// A workflow.
11#[derive(Debug, Clone, Deserialize, Item, UpdateDto)]
12pub struct Workflow {
13    /// Unique identifier of the workflow.
14    #[dto(skip)]
15    pub id: crate::id::WorkflowId,
16
17    /// Whether the workflow is enabled.
18    pub enabled: bool,
19
20    /// Name of the workflow.
21    pub name: String,
22
23    /// Order of the workflow in the list.
24    pub order: Option<i32>,
25
26    /// Triggers that determine when the workflow is executed.
27    #[dto(skip)] // TODO
28    pub triggers: Vec<WorkflowTrigger>,
29
30    /// Actions that are executed when the workflow is triggered.
31    #[dto(skip)] // TODO
32    pub actions: Vec<WorkflowAction>,
33}
34
35/// A trigger that determines when a workflow is executed.
36#[derive(Debug, Clone, Deserialize)]
37pub struct WorkflowTrigger {
38    /// Unique identifier of the trigger.
39    pub id: crate::id::WorkflowTriggerId,
40
41    /// The type of trigger.
42    #[serde(rename = "type")]
43    pub trigger_type: WorkflowTriggerType,
44}
45
46/// An action that can be executed when a workflow is triggered.
47#[derive(Debug, Clone, Deserialize)]
48pub struct WorkflowAction {
49    /// Unique identifier of the workflow action.
50    pub id: crate::id::WorkflowActionId,
51
52    /// The type of action.
53    #[serde(rename = "type")]
54    pub action_type: WorkflowActionType,
55
56    /// Webhook configuration, if the action type is a webhook.
57    pub webhook: Option<WebhookAction>,
58}
59
60/// The type of trigger that determines when a workflow is executed.
61#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
62#[repr(u8)]
63pub enum WorkflowTriggerType {
64    ProcessingStarted = 1,
65    DocumentAdded = 2,
66    DocumentUpdated = 3,
67    Scheduled = 4,
68}
69
70/// The type of action that is executed when a workflow is triggered.
71#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
72#[repr(u8)]
73pub enum WorkflowActionType {
74    Assign = 1,
75    Remove = 2,
76    Email = 3,
77    Webhook = 4,
78}
79
80/// A webhook action that can be executed when a workflow is triggered.
81#[derive(Debug, Clone, Deserialize)]
82pub struct WebhookAction {
83    /// Unique identifier of the webhook action.
84    pub id: crate::id::WebhookActionId,
85
86    /// URL of the webhook.
87    pub url: String,
88
89    /// Whether to use query parameters.
90    pub use_params: bool,
91
92    /// Whether to send the body as JSON.
93    pub as_json: bool,
94
95    /// Whether to include the document in the request.
96    pub include_document: bool,
97
98    /// Body of the webhook request.
99    pub body: Option<String>,
100
101    /// Headers to include in the webhook request.
102    pub headers: Option<HashMap<String, String>>,
103
104    /// Query parameters to include in the webhook request.
105    pub params: Option<HashMap<String, String>>,
106}