Skip to content

Yurba.js / yurba.js / DialogResource

Class: DialogResource

Dialog Core

create()

create(payload): Promise<DialogInfo>

Creates a new dialog

Parameters

payload

CreateDialogPayload

CreateDialogPayload Dialog creation data

Returns

Promise<DialogInfo>

CreateDialogResponse Created dialog response

Since

0.1.10

Throws

If name or description is invalid

Example

javascript
const dialog = await rest.dialogs.create({
  name: "My Dialog",
  description: "Discussion place",
  type: "public"
});

createPrivate()

createPrivate(userId): Promise<Dialog>

Creates a private dialog with a user

Parameters

userId

number

User identifier to create private dialog with

Returns

Promise<Dialog>

Dialog Created private dialog

Since

0.1.10

Throws

If user ID is invalid or user not found

Example

javascript
const privateDialog = await rest.dialogs.createPrivate(12345);

find()

find(query, payload, page?): Promise<Dialog[]>

Find dialogs

Parameters

query

string

Search mask

payload

FindDialogPayload

Search data

page?

number

Page number (default 0)

Returns

Promise<Dialog[]>

Dialog list

Since

1.0.0

Deprecated

Use rest.search.dialogs() instead

Example

javascript
// Use rest.search.dialogs() instead
const results = await rest.search.dialogs('programming', {
  sort: 0,    // by relevance
  type: 0,    // all types
  country: 0, // all countries
  topic: 0    // all topics
});

get()

get(id, code?): Promise<Dialog>

Gets a dialog by identifier

Parameters

id

number

Dialog identifier

code?

string

Invitation code (optional)

Returns

Promise<Dialog>

Dialog object

Since

0.1.10

Throws

If dialog not found

Example

javascript
const dialog = await rest.dialogs.get(123);
const privateDialog = await rest.dialogs.get(456, 'invite123');

getAll()

getAll(): Promise<Dialog[]>

Gets all dialogs where the client is a member

Returns

Promise<Dialog[]>

Array of Dialog objects

Since

0.1.10

Throws

If dialogs cannot be retrieved

Example

javascript
const dialogs = await rest.dialogs.getAll();

join()

join(dialogId): Promise<response>

Join to dialog

Parameters

dialogId

number

Dialog identifier

Returns

Promise<response>

Operation result

Since

1.0.0

Throws

If parameters are invalid

Example

javascript
await rest.dialogs.join(123);

leave()

leave(dialogId): Promise<response>

Leave dialog

Parameters

dialogId

number

Dialog identifier

Returns

Promise<response>

Operation result

Since

1.0.0

Throws

If parameters are invalid

Example

javascript
await rest.dialogs.leave(123);

mute()

mute(dialogId): Promise<responseMute>

Mute/unmute dialog

Parameters

dialogId

number

Dialog identifier

Returns

Promise<responseMute>

Mute status response

Since

1.0.0

Example

javascript
const result = await rest.dialogs.mute(123);

update()

update(dialogId, payload): Promise<response>

Update dialog

Parameters

dialogId

number

Dialog identifier

payload

UpdateDialogPayload

UpdateDialogPayload Dialog data

Returns

Promise<response>

Operation result

Since

1.0.0

Throws

If parameters are invalid

Example

javascript
await rest.dialogs.update(123, { name: 'New Name' });
await rest.dialogs.update(123, { description: 'Updated description' });

Dialog Members

addMember()

addMember(dialogId, userId, code?): Promise<response>

Add user to dialog

Parameters

dialogId

number

Dialog identifier

userId

number

User identifier

code?

string

Returns

Promise<response>

Operation result

Since

0.1.10

Throws

If parameters are invalid

Example

javascript
await rest.dialogs.addMember(123, 456);

getMembers()

getMembers(dialogId, page?): Promise<DialogMember[]>

Get dialog members

Parameters

dialogId

number

Dialog identifier

page?

number

Page number (default 0)

Returns

Promise<DialogMember[]>

Array of DialogMember objects

Since

0.1.10

Throws

If parameters are invalid

Example

javascript
const members = await rest.dialogs.getMembers(123);
const nextPage = await rest.dialogs.getMembers(123, 1);

removeMember()

removeMember(dialogId, userId): Promise<response>

Remove user from dialog

Parameters

dialogId

number

Dialog identifier

userId

number

User identifier

Returns

Promise<response>

Operation result

Since

0.1.10

Throws

If parameters are invalid

Example

javascript
await rest.dialogs.removeMember(123, 456);

Dialog Messages

deleteMessage()

deleteMessage(messageId): Promise<response>

Delete message

Parameters

messageId

number

Message identifier

Returns

Promise<response>

Operation result

Since

0.1.10

Example

javascript
const deleted = await rest.dialogs.deleteMessage(12345);

getMessage()

getMessage(dialogId): Promise<Message>

Get message (by id)

Parameters

dialogId

number

Returns

Promise<Message>

Array of messages

Since

1.0.0

Deprecated

This method may not work due to restricted access to view all messages

Example

javascript
const messages = await rest.dialogs.getMessage(123);

getMessages()

getMessages(dialogId, lastId?): Promise<Message[]>

Get messages from dialog

Parameters

dialogId

number

Dialog identifier

lastId?

number

Last message ID for pagination (optional)

Returns

Promise<Message[]>

Array of messages

Since

0.1.10

Example

javascript
const messages = await rest.dialogs.getMessages(123);
const older_messages = await rest.dialogs.getMessages(123, 999);

sendMessage()

sendMessage(dialogId, payload): Promise<Message>

Send message to dialog

Parameters

dialogId

number

Dialog identifier

payload

SendMessagePayload

SendMessagePayload Message data

Returns

Promise<Message>

Message Sent message

Since

0.1.10

Example

javascript
// Text message
await rest.dialogs.sendMessage(123, { text: "Hello!" });

// With photos and reply
await rest.dialogs.sendMessage(123, {
  text: "Check this",
  photos_list: [-1112],
  replyTo: 48561
});

// With attachments
await rest.dialogs.sendMessage(123, {
  text: "Media",
  attachments: [
    { Type: "video", Item: 28 },
    { Type: "track", Item: 6422 },
    { Type: "file", Item: 684 },
    { Type: "post", Item: 3201 }
  ]
});

// With new attachments
import { File, Audio, Video, Photo } from '@yurbajs/utils'

await rest.dialogs.sendMessage(123, {
  text: "Media",
  attachments: [
    New File('/path/to/file.txt'),
    New Photo('/path/to/photo.png', { caption: "the file" }),
    New Audio('/path/to/audio.mp3', { name: '', author: '', release: '', cover: '', mode: ''}),
    New Video('/path/to/video.mp4')
  ]
});

// Edit message
await rest.dialogs.sendMessage(123, {
  text: "Updated",
  edit: 12345
});