Skip to content

Commit a59c95c

Browse files
authored
Merge pull request #14062 from nextcloud/backport/14061/stable33
[stable33] Docs: adapt windmill docs to new integration
2 parents 4dbf1b7 + 13d3ebb commit a59c95c

File tree

5 files changed

+104
-57
lines changed

5 files changed

+104
-57
lines changed
51.5 KB
Loading
Binary file not shown.
17.2 KB
Loading
Binary file not shown.

admin_manual/windmill_workflows/index.rst

Lines changed: 104 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,37 @@
22
Windmill Workflows
33
==================
44

5-
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.
66

77
Installation
88
------------
99

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.
1112

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
1514

1615
.. code-block:: bash
1716
1817
occ app:enable webhook_listeners
1918
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.
28-
29-
.. image:: images/windmill_initial_workspace_selection.png
30-
:alt: Screenshot of the workspace selector screen when opening Windmill for the first time
31-
32-
If you wish to change to a different workspace at a later time, you can do so via the workspace selector in the left sidebar of Windmill.
33-
34-
.. image:: images/windmill_later_workspace_selection.png
35-
: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>`_
4320

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
4522

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+
-----------------------------------
4725

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.
4927

50-
`https://<your-nextcloud-base-url>/index.php/apps/app_api/proxy/flow`
28+
* 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.
5133

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.
5335

54-
`https://<your-nextcloud-base-url>/exapps/flow`
5536

5637
Building a workflow
5738
-------------------
@@ -62,20 +43,17 @@ If you are not using the ExApp-packaged windmill install then you will have to r
6243
webhooks for your workflows manually via the webhook_listeners API:
6344
see https://docs.nextcloud.com/server/33/developer_manual/_static/openapi.html#/operations/webhook_listeners-webhooks-index
6445

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
6948

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 events that your flow should react to. You can additionally fill in some parameters:
7150

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.
7354

74-
.. code-block:: typescript
7555

76-
export async function main(events: string[], filters: object) { }
77-
78-
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.
7957

8058
Nextcloud Scripts
8159
-----------------
@@ -84,8 +62,7 @@ Nextcloud makes available a variety of scripts to be used in Windmill for interf
8462
at https://hub.windmill.dev/integrations/nextcloud and https://hub.windmill.dev/integrations/nextcloud/approvals
8563
or in your windmill instance when selecting existing scripts for creating a new workflow.
8664

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.
8966

9067
You can create your own Nextcloud-related scripts by taking one of the existing ones as example.
9168
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
9471

9572
.. TODO ON RELEASE: Update version number above on release
9673
97-
All the scripts we provide have a set of common input parameters:
74+
.. code-block:: javascript
75+
76+
import * as wmill from "windmill-client";
77+
import createClient, { type Middleware } from "openapi-fetch";
78+
79+
type Nextcloud = {
80+
baseUrl: string,
81+
password: string,
82+
username: string
83+
};
84+
85+
export async function main(
86+
nextcloud: Nextcloud,
87+
$PARAMETER: $TYPE,
88+
// add any input parameters you need here
89+
) {
90+
91+
// this part is the same for any script and should not be changed
9892
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.
93+
const client = createClient<paths>({ baseUrl: nextcloud.baseUrl });
94+
const authMiddleware: Middleware = {
95+
async onRequest({ request, options }) {
96+
// fetch token, if it doesn’t exist
97+
// add Authorization header to every request
98+
request.headers.set("Authorization", `Basic ${btoa(nextcloud.username + ':' + nextcloud.password)}`);
99+
return request;
100+
},
101+
};
102+
client.use(authMiddleware);
103+
104+
//starting here you can adapt the script
105+
106+
data = await client.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.
102134

103135
Authentication
104136
~~~~~~~~~~~~~~
105137

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+
110152

111153
Passing values between blocks
112154
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113155

114156
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.
115157

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>`.
118165

119166
Each step in a workflow is automatically assigned a letter identifier.
120167
In order to reference results from previous steps in your parameters, use the ``results`` variable with the id of the step
121168
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.
123170

124171
Approval/Suspend steps
125172
~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)