Skip to main content

windmill_api/models/
websocket_trigger.rs

1/*
2 * Windmill API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.674.2
7 * Contact: contact@windmill.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15pub struct WebsocketTrigger {
16    /// The WebSocket URL to connect to (can be a static URL or computed by a runnable)
17    #[serde(rename = "url")]
18    pub url: String,
19    /// ID of the server currently handling this trigger (internal)
20    #[serde(rename = "server_id", skip_serializing_if = "Option::is_none")]
21    pub server_id: Option<String>,
22    /// Timestamp of last server heartbeat (internal)
23    #[serde(rename = "last_server_ping", skip_serializing_if = "Option::is_none")]
24    pub last_server_ping: Option<String>,
25    /// Last error message if the trigger failed
26    #[serde(rename = "error", skip_serializing_if = "Option::is_none")]
27    pub error: Option<String>,
28    /// Array of key-value filters to match incoming messages (only matching messages trigger the script)
29    #[serde(rename = "filters")]
30    pub filters: Vec<serde_json::Value>,
31    /// Logic to apply when evaluating filters. 'and' requires all filters to match, 'or' requires any filter to match.
32    #[serde(rename = "filter_logic", skip_serializing_if = "Option::is_none")]
33    pub filter_logic: Option<FilterLogic>,
34    /// Messages to send immediately after connecting (can be raw strings or computed by runnables)
35    #[serde(rename = "initial_messages", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
36    pub initial_messages: Option<Option<Vec<models::WebsocketTriggerInitialMessage>>>,
37    /// The arguments to pass to the script or flow
38    #[serde(rename = "url_runnable_args", skip_serializing_if = "Option::is_none")]
39    pub url_runnable_args: Option<std::collections::HashMap<String, serde_json::Value>>,
40    /// If true, the script can return a message to send back through the WebSocket
41    #[serde(rename = "can_return_message")]
42    pub can_return_message: bool,
43    /// If true, error results are sent back through the WebSocket
44    #[serde(rename = "can_return_error_result")]
45    pub can_return_error_result: bool,
46    #[serde(rename = "heartbeat", skip_serializing_if = "Option::is_none")]
47    pub heartbeat: Option<Box<models::WebsocketHeartbeat>>,
48    /// Path to a script or flow to run when the triggered job fails
49    #[serde(rename = "error_handler_path", skip_serializing_if = "Option::is_none")]
50    pub error_handler_path: Option<String>,
51    /// The arguments to pass to the script or flow
52    #[serde(rename = "error_handler_args", skip_serializing_if = "Option::is_none")]
53    pub error_handler_args: Option<std::collections::HashMap<String, serde_json::Value>>,
54    #[serde(rename = "retry", skip_serializing_if = "Option::is_none")]
55    pub retry: Option<Box<models::Retry>>,
56    /// The unique path identifier for this trigger
57    #[serde(rename = "path")]
58    pub path: String,
59    /// Path to the script or flow to execute when triggered
60    #[serde(rename = "script_path")]
61    pub script_path: String,
62    /// The user or group this trigger runs as (permissioned_as)
63    #[serde(rename = "permissioned_as")]
64    pub permissioned_as: String,
65    /// Additional permissions for this trigger
66    #[serde(rename = "extra_perms")]
67    pub extra_perms: std::collections::HashMap<String, bool>,
68    /// The workspace this trigger belongs to
69    #[serde(rename = "workspace_id")]
70    pub workspace_id: String,
71    /// Username of the last person who edited this trigger
72    #[serde(rename = "edited_by")]
73    pub edited_by: String,
74    /// Timestamp of the last edit
75    #[serde(rename = "edited_at")]
76    pub edited_at: String,
77    /// True if script_path points to a flow, false if it points to a script
78    #[serde(rename = "is_flow")]
79    pub is_flow: bool,
80    #[serde(rename = "mode")]
81    pub mode: models::TriggerMode,
82    #[serde(rename = "labels", skip_serializing_if = "Option::is_none")]
83    pub labels: Option<Vec<String>>,
84}
85
86impl WebsocketTrigger {
87    pub fn new(url: String, filters: Vec<serde_json::Value>, can_return_message: bool, can_return_error_result: bool, path: String, script_path: String, permissioned_as: String, extra_perms: std::collections::HashMap<String, bool>, workspace_id: String, edited_by: String, edited_at: String, is_flow: bool, mode: models::TriggerMode) -> WebsocketTrigger {
88        WebsocketTrigger {
89            url,
90            server_id: None,
91            last_server_ping: None,
92            error: None,
93            filters,
94            filter_logic: None,
95            initial_messages: None,
96            url_runnable_args: None,
97            can_return_message,
98            can_return_error_result,
99            heartbeat: None,
100            error_handler_path: None,
101            error_handler_args: None,
102            retry: None,
103            path,
104            script_path,
105            permissioned_as,
106            extra_perms,
107            workspace_id,
108            edited_by,
109            edited_at,
110            is_flow,
111            mode,
112            labels: None,
113        }
114    }
115}
116/// Logic to apply when evaluating filters. 'and' requires all filters to match, 'or' requires any filter to match.
117#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
118pub enum FilterLogic {
119    #[serde(rename = "and")]
120    And,
121    #[serde(rename = "or")]
122    Or,
123}
124
125impl Default for FilterLogic {
126    fn default() -> FilterLogic {
127        Self::And
128    }
129}
130