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#[derive(Debug, Clone, Deserialize)]
29pub struct WorkflowTrigger {
30    pub id: crate::id::WorkflowTriggerId,
31
32    #[serde(rename = "type")]
33    pub trigger_type: WorkflowTriggerType,
34}
35
36#[derive(Debug, Clone, Deserialize)]
37pub struct WorkflowAction {
38    pub id: crate::id::WorkflowActionId,
39
40    #[serde(rename = "type")]
41    pub action_type: WorkflowActionType,
42
43    pub webhook: Option<WebhookAction>,
44}
45
46#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
47#[repr(u8)]
48pub enum WorkflowTriggerType {
49    ProcessingStarted = 1,
50    DocumentAdded = 2,
51    DocumentUpdated = 3,
52    Scheduled = 4,
53}
54
55#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
56#[repr(u8)]
57pub enum WorkflowActionType {
58    Assign = 1,
59    Remove = 2,
60    Email = 3,
61    Webhook = 4,
62}
63
64#[derive(Debug, Clone, Deserialize)]
65pub struct WebhookAction {
66    pub id: crate::id::WebhookActionId,
67    pub url: String,
68
69    pub use_params: bool,
70    pub as_json: bool,
71    pub include_document: bool,
72
73    pub body: Option<String>,
74    pub headers: HashMap<String, String>,
75    pub params: HashMap<String, String>,
76}