You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nextcloud integrates the Windmill workflow engine (https://www.windmill.dev/) to allow advanced custom workflows interacting with your Nextcloud instance.
5
+
Nextcloud integrates the `Windmill workflow engine <https://www.windmill.dev/>` to allow advanced custom workflows interacting with your Nextcloud instance.
6
6
7
7
Installation
8
8
------------
9
9
10
-
* Install Windmill
10
+
* Set up a Windmill instance
11
+
* This should be a stand-alone instance. The External App "Flow" (see :ref:`External Apps<ai-app_api>`) made it possible to have a packaged instance installed in Nextcloud, but this is deprecated since Nextcloud 33. For more information, please check out the admin manual for Nextcloud 32.
11
12
12
-
* Either as a standalone install or via the External App "Flow" in Nextcloud (see :ref:`External Apps<ai-app_api>`)
13
-
14
-
* Enable the ``webhook_listeners`` app that comes with Nextcloud
13
+
* Enable the ``webhook_listeners`` app that comes with Nextcloud
15
14
16
15
.. code-block:: bash
17
16
18
17
occ app:enable webhook_listeners
19
18
20
-
Selecting the right Workspace
21
-
-----------------------------
22
-
23
-
With Windmill installed as an ExApp, the first time one visits Windmill's web interface,
24
-
make sure to select the right workspace on the first run:
25
-
Only the pre-existing "nextcloud" workspace is hooked up to nextcloud's internal event system,
26
-
all other workspaces will need manual webhook setups for each workflow.
27
-
If the wrong workspace is selected on the first run, it is always possible to switch workspace later in the left sidebar.
:alt:Screenshot of the workspace selector when a workspace is already opened
36
-
37
-
Setting up the Correct Nextcloud URL
38
-
------------------------------------
39
-
40
-
During the initial installation, the ExApp Flow will create a **Nextcloud Authentication Resource** for AppAPI.
41
-
42
-
This resource includes a **baseUrl** field, which specifies the URL that Windmill scripts/apps use to reach the Nextcloud instance. In most cases, this URL will be configured correctly. However, certain configurations and network topologies may result in an incorrect URL, which you will need to adjust manually.
19
+
* Install the `Windmill integration <https://apps.nextcloud.com/apps/integration_windmill>`_
43
20
44
-
To set the correct URL, navigate to the Windmill interface, go to the **Resources** tab, locate the resource labeled ``u/admin/exapp_resource``, click the three dots on the right, and select the "Edit" button.
21
+
* Enable :ref:`pretty_urls_label` in your Nextcloud instance
45
22
46
-
Next, navigate to **Settings->Instance->Core** in Windmill and check if the **Base url** for the Windmill instance is correct.
23
+
Setting up the workspace connection
24
+
-----------------------------------
47
25
48
-
If you are using DockerSocketProxy, the Base URL should be:
26
+
In Windmill, you have separate workspaces available. To enable Windmill to react to events happening on your Nextcloud instance, you need to connect a workspace to your Nextcloud connection. This is only possible for workspace admins.
* In Windmill, open the workspace settings of the workspace you want to connect to Nextcloud via Settings -> Workspace
29
+
* Go to the Native Triggers tab and choose Nextcloud -> Configure OAuth
30
+
* Follow the instructions to set up the OAuth connection
31
+
* Click on "Connect" and accept the OAuth connection **with a Nextcloud admin account** or an account that has webhook admin privileges
32
+
* If it shows "Connected", the workspace connection is successfully set up.
51
33
52
-
If you are using HaRP (as introduced in Nextcloud 32), the Base URL should be:
34
+
Every Flow configured in this workspace can now add Nextcloud triggers and scripts based on the credentials of the account you accepted the OAuth connection with.
53
35
54
-
`https://<your-nextcloud-base-url>/exapps/flow`
55
36
56
37
Building a workflow
57
38
-------------------
@@ -62,20 +43,17 @@ If you are not using the ExApp-packaged windmill install then you will have to r
62
43
webhooks for your workflows manually via the webhook_listeners API:
63
44
see https://docs.nextcloud.com/server/33/developer_manual/_static/openapi.html#/operations/webhook_listeners-webhooks-index
64
45
65
-
.. TODO ON RELEASE: Update version number above on release
66
-
67
-
The magic listener script
68
-
~~~~~~~~~~~~~~~~~~~~~~~~~
46
+
.. image:: images/windmill_add_trigger.png
47
+
:alt:Screenshot of adding a Nextcloud trigger in a workflow
69
48
70
-
The first script (after the "Input" block) in any workflow you build that should listen to a Nextcloud webhook must have "Summary" set to the exact, literal string ``CORE:LISTEN_TO_EVENT``. It must be an empty script with two parameters that you should fill statically: ``events``, which is a list of event IDs to listen to and ``filters`` a filter condition that allows more fine grained filtering for which events should be used. The filter condition as well as the available events with their payloads is documented in :ref:`the webhook_listeners documentation<webhook_listeners>`.
49
+
Now you can choose an event out of a drop-down list of eventsthat your flow should react to. You can additionally fill in some parameters:
71
50
72
-
You can copy the following Deno script for this:
51
+
* *Event filters* allows more fine grained filtering for which events should be used. The filter condition as well as the available events with their payloads is documented in the :ref:`webhook_listeners documentation<webhook_listeners>`.
52
+
* The *User ID filter* allows to define the user that can trigger a flow with their actions in Nextcloud. The webhook will only be called by requests from this user. Empty or null means no filtering.
53
+
* The *Headers* field allows to define an array of headers to be sent in a webhook call, which will mostly not be needed.
The webhook data will be made available on the flow "Input" block, **not** the ``CORE:LISTEN_TO_EVENT`` block. Updates to the webhook configuration take effect only when the flow is deployed. Consider disabling any schedule for the flow, since it will be started when a webhook is received.
56
+
You can add more than one trigger to a flow.
79
57
80
58
Nextcloud Scripts
81
59
-----------------
@@ -84,8 +62,7 @@ Nextcloud makes available a variety of scripts to be used in Windmill for interf
84
62
at https://hub.windmill.dev/integrations/nextcloud and https://hub.windmill.dev/integrations/nextcloud/approvals
85
63
or in your windmill instance when selecting existing scripts for creating a new workflow.
86
64
87
-
To synchronize the scripts with the ones provided by the Windmill hub,
88
-
you can run a flow named "Synchronize Hub Resource types with instance" in the Windmill admin workspace.
65
+
If you want to use a function that is not already represented there, you can easily write your own scripts using a skeleton script and our OCS API that provides lots of endpoints. You can check out the available endpoints in the `Nextcloud OCS API documentation <https://docs.nextcloud.com/server/latest/developer_manual/_static/openapi.html>`_ or you can install our `OCS API Viewer app <https://apps.nextcloud.com/apps/ocs_api_viewer>`_ and check it out directly in your Nextcloud.
89
66
90
67
You can create your own Nextcloud-related scripts by taking one of the existing ones as example.
91
68
In a script, when sending a request to Nextcloud, make sure that the ``EX-APP-ID`` header is set to ``flow``.
@@ -94,32 +71,102 @@ Your custom scripts can make requests to any endpoint of the
94
71
95
72
.. TODO ON RELEASE: Update version number above on release
96
73
97
-
All the scripts we provide have a set of common input parameters:
// this part is the same for any script and should not be changed
98
92
99
-
* nextcloudResource: This should be set to the path of the Windmill resource that was automatically created and contains what is necessary to authenticate against Nextcloud with the AppAPI authentication method. For example "u/wapp_user/appapi_nextcloud". You can find this path by looking at the resource list in Windmill.
100
-
* userId: This is the ID of the user you want the request to be authenticated as.
101
-
* useAppApiAuth: This is a boolean to choose between using the AppAPI authentication or basic auth. More details in the next section.
data =awaitclient.GET("/ocs/v2.php/apps/$APP/$PATH/{$PATHPARAMETER}", {
107
+
params: {
108
+
header: {
109
+
"OCS-APIRequest":true,
110
+
},
111
+
query: {
112
+
format:"json",
113
+
},
114
+
path: {
115
+
$PATHPARAMETER:"$VALUE",
116
+
},
117
+
118
+
},
119
+
body: {
120
+
$BODYPARAMETER:$VALUE,
121
+
},
122
+
});
123
+
124
+
return data;
125
+
}
126
+
127
+
The endpoint path you have to fill in is provided in the API documentation.
128
+
129
+
OCS uses two kinds of parameters: Path parameters that are part of the endpoint URL, and body parameters that are transmitted in the request body. In the example script, you can provide both kinds in the function parameters.
130
+
131
+
Remember to also adapt the HTTP method (GET, POST, PUT etc.) if needed.
132
+
133
+
The :code:`data` variable receives the response of the HTTP request, so any data or error messages coming from the Nextcloud instance is available in there.
102
134
103
135
Authentication
104
136
~~~~~~~~~~~~~~
105
137
106
-
All bricks have the option to use "AppAPI Authentication" or normal authentication using a Nextcloud resource in Windmill.
107
-
When using normal authentication you will need to provide the correct password or app password of the user
108
-
on behalf of whom you want to execute the script. When using "AppAPI Authentication" you can impersonate any Nextcloud user.
109
-
This will only work when using the ExApp-packaged version of windmill.
138
+
All the scripts we provide one input parameter in common: *nextcloud* needs to be an object of the type "Nextcloud" and contain what is necessary to authenticate against Nextcloud:
139
+
140
+
* baseUrl: the URL your instance is reachable at, e.g. :code:`https://example.cloud`
141
+
* userId: the user id of the user the script should authenticate with
142
+
* token: a password or token for that user
143
+
144
+
We advise to either add these credentials as a resource of the Nextcloud type to your workspace and refer to the resource in your script, or use the authentication credentials that are provided in the webhook callback.
145
+
For every flow that is triggered by a Nextcloud event, there are 2 sets of temporary credentials included:
146
+
147
+
* the credentials for the user account that is saved in the initial OAuth connection, available as :code:`flow_input.authentication.owner`
148
+
* the credentials for the user account that triggered the event with their action, available as :code:`flow_input.authentication.trigger`
149
+
150
+
These temporary authentication credentials are valid for one hour after triggering the event.
151
+
110
152
111
153
Passing values between blocks
112
154
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113
155
114
156
When specifying script inputs you can either fill the parameters with static values or make references to the workflow input and the previous workflow steps.
115
157
116
-
In order to reference the workflow input, use the ``flow_input`` variable.
117
-
For example, ``flow_input.event.form.hash`` will reference the hash of a form from a nextcloud Forms event.
158
+
In order to reference the workflow input (details about the event that triggered the webhook), use the ``flow_input`` variable.
159
+
For example, ``flow_input.event.form.hash`` will reference the hash of a form from a nextcloud Forms event. As it is a JavaScript expression and not a static value, you have to switch the parameter input with the button next to it.
160
+
161
+
.. image:: images/windmill_js_expression.png
162
+
:alt:Screenshot of adding a Nextcloud trigger in a workflow
163
+
164
+
The fields available for each event are listed in the :ref:`webhook_listeners documentation<webhook_listeners>`.
118
165
119
166
Each step in a workflow is automatically assigned a letter identifier.
120
167
In order to reference results from previous steps in your parameters, use the ``results`` variable with the id of the step
121
168
to reference as a sub property. For example, use ``results.e.submission.answers`` to use the answers of of a form submission
122
-
retrieved via the "Get form submission from Nextcloud Forms" script identified with the letter "e".
169
+
retrieved via the "Get form submission from Nextcloud Forms" script identified with the letter "e". You can identify the letters in the flow overview diagram.
0 commit comments