summaryrefslogtreecommitdiffstats
path: root/docs/chat.md
blob: 719161868040dee6fae3a2ab3e5f5d836fe88f11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# Chat API

Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`: since Nextcloud 13

## Receive chat messages of a conversation

!!! note

    Due to the structure of the `lastMessage.reactions` array the response is not valid in XML.
    It is therefor recommended to use `format=json` or send the `Accept: application/json` header,
    to receive a JSON response.

* Method: `GET`
* Endpoint: `/chat/{token}`
* Data:

| field                | type | Description                                                                                                                                                                                                                             |
|----------------------|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `lookIntoFuture`     | int  | `1` Poll and wait for new message or `0` get history of a conversation                                                                                                                                                                  |
| `limit`              | int  | Number of chat messages to receive (100 by default, 200 at most)                                                                                                                                                                        |
| `lastKnownMessageId` | int  | Serves as an offset for the query. The lastKnownMessageId for the next page is available in the `X-Chat-Last-Given` header.                                                                                                             |
| `lastCommonReadId`   | int  | Send the last `X-Chat-Last-Common-Read` header you got, if you are interested in updates of the common read value. A 304 response does not allow custom headers and otherwise the server can not know if your value is modified or not. |
| `timeout`            | int  | `$lookIntoFuture = 1` only, Number of seconds to wait for new messages (30 by default, 60 at most)                                                                                                                                      |
| `setReadMarker`      | int  | `1` to automatically set the read timer after fetching the messages, use `0` when your client calls `Mark chat as read` manually. (Default: `1`)                                                                                        |
| `includeLastKnown`   | int  | `1` to include the last known message as well (Default: `0`)                                                                                                                                                                            |

* Response:
    - Status code:
        + `200 OK`
        + `304 Not Modified` When there were no older/newer messages
        + `404 Not Found` When the conversation could not be found for the participant
        + `412 Precondition Failed` When the lobby is active and the user is not a moderator

    - Header:

| field                     | type | Description                                                                                                                                                                                                                                        |
|---------------------------|------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `X-Chat-Last-Given`       | int  | Offset (lastKnownMessageId) for the next page.                                                                                                                                                                                                     |
| `X-Chat-Last-Common-Read` | int  | ID of the last message read by every user that has read privacy set to public. When the user themself has it set to private the value the header is not set (only available with `chat-read-status` capability and when lastCommonReadId was sent) |

    - Data:
        Array of messages, each message has at least:

| field                  | type     | Description                                                                                                                                                            |
|------------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `id`                   | int      | ID of the comment                                                                                                                                                      |
| `token`                | string   | Conversation token                                                                                                                                                     |
| `actorType`            | string   | See [Constants - Actor types of chat messages](constants.md#actor-types-of-chat-messages)                                                                              |
| `actorId`              | string   | Actor id of the message author                                                                                                                                         |
| `actorDisplayName`     | string   | Display name of the message author                                                                                                                                     |
| `timestamp`            | int      | Timestamp in seconds and UTC time zone                                                                                                                                 |
| `systemMessage`        | string   | empty for normal chat message or the type of the system message (untranslated)                                                                                         |
| `messageType`          | string   | Currently known types are `comment`, `comment_deleted`, `system` and `command`                                                                                         |
| `isReplyable`          | bool     | True if the user can post a reply to this message (only available with `chat-replies` capability)                                                                      |
| `referenceId`          | string   | A reference string that was given while posting the message to be able to identify a sent message again (only available with `chat-reference-id` capability)           |
| `message`              | string   | Message string with placeholders (see [Rich Object String](https://github.com/nextcloud/server/issues/1706))                                                           |
| `messageParameters`    | array    | Message parameters for `message` (see [Rich Object String](https://github.com/nextcloud/server/issues/1706))                                                           |
| `expirationTimestamp`  | int      | Unix time stamp when the message expires and show be removed from the clients UI without further note or warning (only available with `message-expiration` capability) |
| `parent`               | array    | **Optional:** See `Parent data` below                                                                                                                                  |
| `reactions`            | int[]    | **Optional:** An array map with relation between reaction emoji and total count of reactions with this emoji                                                           |
| `reactionsSelf`        | string[] | **Optional:** When the user reacted this is the list of emojis the user reacted with                                                                                   |

#### Parent data

* When deleted:

| field     | type | Description                       |
|-----------|------|-----------------------------------|
| `id`      | int  | ID of the parent comment          |
| `deleted` | bool | `true` when the parent is deleted |

* Regular message:

    Full message array as shown above, but `parent` will never be set for a parent message.


## Sending a new chat message

* Method: `POST`
* Endpoint: `/chat/{token}`
* Data:

| field              | type   | Description                                                                                                                                                             |
|--------------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `message`          | string | The message the user wants to say                                                                                                                                       |
| `actorDisplayName` | string | Guest display name (ignored for logged in users)                                                                                                                        |
| `replyTo`          | int    | The message ID this message is a reply to (only allowed for messages from the same conversation and when the message type is not `system` or `command`)                 |
| `referenceId`      | string | A reference string to be able to identify the message again in a "get messages" request, should be a random sha256 (only available with `chat-reference-id` capability) |
| `silent`           | bool   | If sent silent the message will not create chat notifications even for mentions (only available with `silent-send` capability)                                          |

* Response:
    - Status code:
        + `201 Created`
        + `400 Bad Request` In case of any other error
        + `403 Forbidden` When the conversation is read-only
        + `404 Not Found` When the conversation could not be found for the participant
        + `412 Precondition Failed` When the lobby is active and the user is not a moderator
        + `413 Payload Too Large` When the message was longer than the allowed limit of 32000 characters (or 1000 until Nextcloud 16.0.1, check the `spreed => config => chat => max-length` capability for the limit)

    - Header:

| field                     | type | Description                                                                                                                                                                                                     |
|---------------------------|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `X-Chat-Last-Common-Read` | int  | ID of the last message read by every user that has read privacy set to public. When the user themself has it set to private the value the header is not set (only available with `chat-read-status` capability) |

    - Data:
        The full message array of the new message, as defined in [Receive chat messages of a conversation](#receive-chat-messages-of-a-conversation)

## Share a rich object to the chat

See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob/master/lib/public/RichObjectStrings/Definitions.php) for more details on supported rich objects and required data.

* Required capability: `rich-object-sharing`
* Method: `POST`
* Endpoint: `/chat/{token}/share`
* Data:

| field              | type   | Description                                                                                                                                                             |
|--------------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `objectType`       | string | The object type                                                                                                                                                         |
| `objectId`         | string | The object id                                                                                                                                                           |
| `metaData`         | string | JSON encoded array of the rich objects data                                                                                                                             |
| `actorDisplayName` | string | Guest display name (ignored for logged in users)                                                                                                                        |
| `referenceId`      | string | A reference string to be able to identify the message again in a "get messages" request, should be a random sha256 (only available with `chat-reference-id` capability) |

* Response:
    - Status code:
        + `201 Created`
        + `400 Bad Request` In case the meta data is invalid
        + `403 Forbidden` When the conversation is read-only
        + `404 Not Found` When the conversation could not be found for the participant
        + `412 Precondition Failed` When the lobby is active and the user is not a moderator
        + `413 Payload Too Large` When the message was longer than the allowed limit of 32000 characters (or 1000 until Nextcloud 16.0.1, check the `spreed => config => chat => max-length` capability for the limit)

    - Header:

| field                     | type | Description                                                                                                                                                                                                     |
|---------------------------|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `X-Chat-Last-Common-Read` | int  | ID of the last message read by every user that has read privacy set to public. When the user themself has it set to private the value the header is not set (only available with `chat-read-status` capability) |

    - Data:
        The full message array of the new message, as defined in [Receive chat messages of a conversation](#receive-chat-messages-of-a-conversation)

## Share a file to the chat

* Method: `POST`
* Endpoint: `ocs/v2.php/apps/files_sharing/api/v1/shares`
* Data:

| field          | type   | Description                                                                                                                                                                            |
|----------------|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `shareType`    | int    | `10` means share to a conversation                                                                                                                                                     |
| `shareWith`    | string | The token of the conversation to share the file to                                                                                                                                     |
| `path`         | string |