Skip to main content

paperless_api/
workflow.rs

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