Skip to content

Commit 92cf419

Browse files
committed
ID-3007 tweaks to chat docs
1 parent 79ceb71 commit 92cf419

1 file changed

Lines changed: 15 additions & 55 deletions

File tree

docs/API/components/chat.md

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,21 @@ Fliplet.Hooks.on('beforeChatContactsRendering', function onBeforeChatContactsRen
109109
The `beforeChatContactsRendering` hook explained above can be useful to modify the contacts list data. In the example below we will add the url from files in the File Manager, by comparing their name to the name entered in the data source's column called "Image". The code seems complex because we are also taking into consideration that the data source column can contain urls, base64 strings and file ids:
110110

111111
```js
112-
var folderId = 325;
113-
var imageColumn = 'Image';
112+
const folderId = 325;
113+
const imageColumn = 'Image';
114114

115115
Fliplet.Hooks.on('beforeChatContactsRendering', function onBeforeChatContactsRendering(data) {
116116
return Fliplet.Media.Folders.get({ folderId: folderId }).then(function(response) {
117-
var allFiles = response.files;
117+
const allFiles = response.files;
118+
118119
// Test pattern for URLS
119-
var urlPattern = /^https?:\/\//i;
120+
const urlPattern = /^https?:\/\//i;
121+
120122
// Test pattern for BASE64 images
121-
var base64Pattern = /^data:image\/[^;]+;base64,/i;
123+
const base64Pattern = /^data:image\/[^;]+;base64,/i;
124+
122125
// Test pattern for Numbers/IDs
123-
var numberPattern = /^\d+$/i;
126+
const numberPattern = /^\d+$/i;
124127

125128
allFiles.forEach(function(file) {
126129
// Add this IF statement to make the URLs to work with encrypted organizations
@@ -295,7 +298,7 @@ Use the `chat.create` method to create a new private conversation between multip
295298
You do not need to list the current user's entry ID in the list of participants, as that will be included automatically by the system.
296299

297300
```js
298-
const conversation = await return chat.create({
301+
const conversation = await chat.create({
299302
name: 'Running team', // Conversation name
300303
participants: [1, 2, 3] // List of Data source entry ID for the participants
301304
});
@@ -310,67 +313,24 @@ const conversation = await return chat.create({
310313
You can get the list of public channel for a chat using the following method:
311314

312315
```js
313-
Fliplet.Chat.get().then(function (chat) {
314-
return chat.channels.get();
315-
}).then(function (channels) {
316-
console.log(channels);
317-
});
316+
const channels = await chat.channels.get();
318317
```
319318

320319
### Create a channel
321320

322321
Channels can be created by simply running this simple snippet via custom code (or by running it in the console). Make sure to change the channel name with the actual words you want to use:
323322

324323
```js
325-
Fliplet.Chat.get().then(function (chat) {
326-
return chat.channels.create('My channel name');
327-
}).then(function (channel) {
328-
// Channel has been created
329-
});
330-
```
331-
332-
<p class="quote">Please note that <strong>the above snippet only works in a screen with a chat component</strong>. If you want to create a channel from a different screen please use the low-level JS API that follows.</p>
333-
334-
```js
335-
// Creates a chat public channel from any screen
336-
Fliplet.DataSources.create({
337-
appId: Fliplet.Env.get('masterAppId'),
338-
type: 'conversation',
339-
name: 'My channel name',
340-
definition: { participants: [], group: { public: true } },
341-
bundle: false,
342-
hooks: [{
343-
runOn: ['insert'],
344-
type: 'push-message',
345-
appId: Fliplet.Env.get('appId')
346-
}],
347-
accessRules: [
348-
{ type: ['select', 'insert', 'update', 'delete'], allow: 'all' }
349-
]
350-
});
324+
const channel = await chat.channels.create('My channel name');
351325
```
352326

353327
### Delete a channel
354328

355-
You can delete a channel by using the `delete` instance method as follows:
356-
357-
```js
358-
Fliplet.Chat.get().then(function (chat) {
359-
// Deletes a channel by its ID
360-
return chat.channels.delete(123);
361-
}).then(function () {
362-
// Channel has been deleted
363-
});
364-
```
365-
366-
Likewise, you can also delete a channel from any screen using the low-level JS API:
329+
You can delete a channel by running the following snippet. Make sure to change the channel ID with the actual ID of the channel you want to delete:
367330

368331
```js
369-
Fliplet.API.request({
370-
method: 'DELETE',
371-
url: 'v1/data-sources/123'
372-
}).then(function () {
373-
// Channel has been deleted
332+
// Deletes a channel by its ID
333+
await chat.channels.delete(123);
374334
})
375335
```
376336

0 commit comments

Comments
 (0)