Skip to content

Commit 7f616d1

Browse files
Merge pull request #14052 from nextcloud/clientIntegration
Client Integration: First draft
2 parents e0fe9fb + 859f088 commit 7f616d1

File tree

4 files changed

+215
-0
lines changed

4 files changed

+215
-0
lines changed
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
.. _clientintegrationindex:
2+
3+
==================
4+
Client Integration
5+
==================
6+
7+
With Nextcloud Hub 26 Winter we are introducing a new client integration API. It allows server side apps to expose integrations on Desktop and Mobile.
8+
For now we support adding app-defined actions to a "context menu" of files and folders.
9+
10+
It allows providing easy integration of specific actions on clients without the need to write and maintain code on those platforms.
11+
12+
Supported clients
13+
-----------------
14+
15+
Android: 3.36.0 and above
16+
17+
Desktop: 4.1.0 and above
18+
19+
iOS: 7.3.0 and above
20+
21+
Supported server apps
22+
---------------------
23+
richdocuments: Convert .docx to .md
24+
25+
assistant: Transcribe audio file
26+
27+
files_zip: Zip a file or folder
28+
29+
contacts: Create new contact from vfc
30+
31+
Exposing actions via capability
32+
-------------------------------
33+
34+
Each app can add new actions via capabilities, following the syntax "app-id", "hook-name" and list of all endpoints.
35+
36+
.. code-block:: php
37+
38+
'client_integration' => [
39+
Application::APP_ID => [
40+
'version' => 0.1,
41+
'context-menu' => [
42+
// ... endpoints ...
43+
]
44+
]
45+
]
46+
47+
Hooks
48+
-----
49+
50+
Currently only "context-menu" is supported.
51+
52+
Endpoint
53+
--------
54+
The endpoint tells the client how the menu entry should look like and how the client can send a request to the server.
55+
56+
Requirements:
57+
- Every text need to be translated by the app
58+
- Current predefined params are fileId and filePath
59+
- {fileId} and {filePath} will be replaced on clients with actual values
60+
- url placeholder are always replaced
61+
- mimetype_filters is a comma-separated list of filters (matches anything that starts with the filter). If there is no filter, the action is shown for every file/folder.
62+
- all urls must be relative
63+
- params is used for body params (currently only POST)
64+
- Icons are always svgs
65+
- Method: supports POST/GET
66+
67+
.. code-block:: javascript
68+
69+
[
70+
'name' => 'translated title',
71+
'url' => '/ocs/v2.php/apps/abc',
72+
'method' => 'POST/GET',
73+
'mimetype_filters' => 'text/, application/pdf', // will match text/* and PDFs
74+
'params' => ['file_id' => '{fileId}','file_path' => '{filePath}'], // only for POST; the key can vary depending on the app
75+
'icon' => '/apps/abc/img/app.svg'
76+
],
77+
78+
Response
79+
--------
80+
When clicking on a menu entry the client sends a predefined request to the server.
81+
The app in question can then handle the request and can send two different response types:
82+
83+
Declarative UI
84+
^^^^^^^^^^^^^^
85+
The declarative UI response allows the app to send back a new UI to be rendered by the client:
86+
- version: Indicates which version it is. Clients will be backwards compatible. If server sends a newer version than the client can understand the response will be ignored.
87+
- tooltip: Translated text, which will be shown as tooltip / snackbar.
88+
89+
.. code-block:: javascript
90+
91+
{
92+
"ocs": {
93+
"meta": {
94+
"status": "ok",
95+
"statuscode": 200,
96+
"message": "OK"
97+
},
98+
"data": {
99+
"version": 0.1,
100+
"root": {
101+
"orientation": "vertical",
102+
"rows": [
103+
{
104+
"children": [
105+
{
106+
"element": "URL",
107+
"text": "Link created",
108+
"url": "/some/link/to/a/page"
109+
}
110+
]
111+
}
112+
]
113+
}
114+
}
115+
}
116+
}
117+
118+
At the moment only rows with text and url elements are supported, but in the future we will add more elements and options.
119+
120+
Tooltip Response
121+
^^^^^^^^^^^^^^^^
122+
The tooltip response is a regular DataResponse type, with payload:
123+
- version: Indicates which version it is. Clients will be backwards compatible. If server sends a newer version than the client can understand the response will be ignored.
124+
- tooltip: Translated text, which will be shown as tooltip / snackbar.
125+
126+
.. code-block:: javascript
127+
128+
{
129+
"ocs": {
130+
"meta": {
131+
"status": "ok",
132+
"statuscode": 200,
133+
"message": "OK"
134+
},
135+
"data": {
136+
"version": "0.1",
137+
"tooltip": "Task submitted successfully"
138+
}
139+
}
140+
}
141+
142+
Example:
143+
----------
144+
Here is an example of using the Assistant app.
145+
146+
**Capabilities:**
147+
148+
`ocs/v1.php/cloud/capabilities` returns the following capability:
149+
150+
.. code-block:: javascript
151+
152+
"client_integration": {
153+
"assistant": {
154+
"version": 0.1,
155+
"context-menu": [
156+
{
157+
"name": "Summarize using AI",
158+
"url": "/ocs/v2.php/apps/assistant/api/v1/file-action/{fileId}/core:text2text:summary",
159+
"method": "POST",
160+
"mimetype_filters": "text/, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.oasis.opendocument.text, application/pdf",
161+
"icon": "/apps/assistant/img/client_integration/summarize.svg"
162+
},
163+
{
164+
"name": "Transcribe audio using AI",
165+
"url": "/ocs/v2.php/apps/assistant/api/v1/file-action/{fileId}/core:audio2text",
166+
"method": "POST",
167+
"mimetype_filters": "audio/",
168+
"icon": "/apps/assistant/img/client_integration/speech_to_text.svg"
169+
},
170+
{
171+
"name": "Text-To-Speech using AI",
172+
"url": "/ocs/v2.php/apps/assistant/api/v1/file-action/{fileId}/core:text2speech",
173+
"method": "POST",
174+
"mimetype_filters": "text/, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.oasis.opendocument.text, application/pdf",
175+
"icon": "/apps/assistant/img/client_integration/text_to_speech.svg"
176+
}
177+
]
178+
},
179+
},
180+
181+
The Assistant integration has a few endpoints for the client to show and execute. They appear like this on the client side:
182+
183+
.. image:: ../images/client-integration-ios.png
184+
:alt: Client integration on iOS
185+
:scale: 50%
186+
187+
.. image:: ../images/client-integration-android.png
188+
:alt: Client integration on Android
189+
:scale: 50%
190+
191+
Looking at the "Summarize using AI" action, it will only show for files with mimetypes starting with "text/" or the specified document and PDF mimetypes, as described in `mimetype_filters`.
192+
When clicking on the action, the client will send a POST request to the specified URL, replacing {fileId} with the actual file id. The app can then handle the request and for example send a tooltip response back to the client. The client will show the tooltip to the user:
193+
194+
.. code-block:: javascript
195+
196+
{
197+
"ocs": {
198+
"meta": {
199+
"status": "ok",
200+
"statuscode": 200,
201+
"message": "OK"
202+
},
203+
"data": {
204+
"version": 0.1,
205+
"tooltip": "Summarization task submitted successfully"
206+
}
207+
}
208+
}
209+
210+
Issues/Bugs
211+
-----------
212+
213+
Please report issues, bugs or feature requests at https://github.com/nextcloud/files-clients with label "Client integration".
214+
157 KB
Loading
432 KB
Loading

developer_manual/client_apis/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ Clients and Client APIs
1515
OCS/index
1616
RemoteWipe/index
1717
WebDAV/index
18+
ClientIntegration/index
1819

0 commit comments

Comments
 (0)