1.2.5 • Published 5 years ago

@deepvision/dvm.js v1.2.5

Weekly downloads
-
License
-
Repository
-
Last release
5 years ago

Deepvision Messenger API Library

Installing

To install library use:

npm install @deepvision/dvm.js

Initializing

Import library into your script file and create dvm instance with constructor.

import DVMApi from '<path_to_library>';

const dvm = new DVMApi({
    endpoint: 'api-enpoint',
    getAccessToken: () => 'token',
});

Getting updates

There is one way of receiving updates for your client — the updates.list method.

Update

This object represents an incoming update.

FieldTypeDescription
idStringThe update‘s unique identifier.
dateIntegerDate the update was caused in Unix time.
typeStringType of the update. Can be new-message, edit-message, delete-message, new-chat, delete-chat.
payloadMessage or ChatAn instance of any kind - chat, message, etc. - that caused update.

List Updates

Use this method to receive incoming updates. An Array of Update objects is returned.

const { updates, meta } = await dvm.updates.list({
    since,
    limit,
});

Request:

ParameterTypeRequiredDescription
sinceIntegerOptionalValue of date of the last update you confirmed +1. By default, updates are returned starting with the earliest unconfirmed update. An update is considered confirmed as soon as dvm.updates.list method is called with a since higher than its date. All previous updates will forgotten. Defaults to 0.
limitIntegerOptionalLimits the number of updates to be returned. Values between 1—100 are accepted. Defaults to 10.

Response:

ParameterTypeDescription
updatesArray of UpdateA list of Update objects.
metaPaginationMetaPagination info.

Notes 1. In order to avoid getting duplicate updates, recalculate offset after each server response.

Available types

All types used in the Bot API responses are represented as JSON-objects.

Optional fields may be not returned when irrelevant.

Chat

FieldTypeDescription
idStringUnique identifier for this chat.
typeStringType of the chat. Can be private only.
titleStringOptional Chat's name.
membersArray of UserA list of chat's members.
lastMessageMessageOptional The last message was sent in this chat.

Message

FieldTypeDescription
idStringUnique identifier for this message.
fromUserSender.
dateIntegerDate the message was sent in Unix time.
chatChatConversation the message belongs to.
textStringText of the message.
dateEditedIntegerDate the message was last edited in Unix time.

User

FieldTypeDescription
idStringUnique identifier for this user. It should consist of two parts and look like "origin:id", where origin can be "dvm" or other name of source messenger's database, such as telegram.
firstNameStringUsers's first name.
lastNameStringUsers's surname.

User object can have more optional fields.

PaginationMeta

FieldTypeDescription
totalIntegerNumber of found items.
limitIntegerLimited number of retrieved items. Can be 1—100.
offsetIntegerSequential number of the first item among all found items.

List of fields in PaginationMeta object can be different depending on the model.

Available methods

On successful call, a JSON-object containing the result will be returned.

Create Chat

Use this method to create new chat. On success, the created Chat is returned.

This method is available for registered users only.

const chat = await dvm.chats.create({
    type,
    members,
});

Request:

ParameterTypeRequiredDescription
typeStringYesType of the chat. Can be private only.
membersArray of StringYesList of user's unique identifiers.

List Chats

Use this method to get list of chats of the current user and incomplete chats also, that can be joined.

This method is available for registered users only.

const { chats, meta } = await dvm.chats.list({
    offset,
    limit,
});

Request:

ParameterTypeRequiredDescription
offsetIntegerOptionalSequential number of the first chat to be returned. Defaults to 0.
limitIntegerOptionalLimits the number of chats to be returned. Values between 1—100 are accepted. Defaults to 10.

Response:

ParameterTypeDescription
chatsArray of ChatA list of Chat object.
metaPaginationMetaPagination info.

Get Chat

Use this method to get info about chat. On success, a Chat object is returned

This method is available for registered users only.

const chat = await dvm.chats.withId(id).get();

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the chat.

Delete Chat

Use this method to delete chat

This method is available for registered users only.

await dvm.chats.withId(id).delete();

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the chat.

Join Chat

Use this method to add current user as a new member to a chat. Chats with incomplete type can be joined only. As soon as user join chat, the last one's type will be changed to private.

This method is available for registered users only.

await dvm.chats.withId(id).join();

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the chat.

Create Chat Message

Use this method to send text messages. On success, the sent Message is returned.

This method is available for registered users only. This method is available for members of the chat only.

const message = await dvm.chats.withId(id).messages.create({
    text,
});

Request:

ParameterTypeRequiredDescription
textStringYesText of the message.

List Chat Messages

Use this method to get list of Message objects for this chat

This method is available for registered users only.

const { messages, meta } = await dvm.chats.withId(id).messages.list({
    offset,
    limit,
    text,
});

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the chat we get messages of.
offsetIntegerOptionalSequential number of the first message to be returned. Defaults to 0.
limitIntegerOptionalLimits the number of messages to be returned. Values between 1—100 are accepted. Defaults to 10.
textStringOptionalFilter. Messages contain the text will be returned. 0—100 characters.

Response:

ParameterTypeDescription
messagesArray of MessageA list of messages sorted from recent to old.
metaPaginationMetaPagination info.

Get Message

Use this method to get message. On success, a Message object is returned.

This method is available for registered users only.

const chat = await dvm.messages.withId(id).get();

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the message.

Edit Message

Use this method to edit message. On success, the new version of Message object is returned.

This method is available for registered users only.

const message = await dvm.messages.withId(id).edit({
    text,
});

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the message.
textStringYesNew text of the message.

Delete Message

Use this method to delete message

This method is available for registered users only.

await dvm.messages.withId(id).delete()

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the message.

Register User

Use this method to register user in DVM service. On success, the registered user is returned. If user with such id has already registered, throws error

const user = await dvm.users.register({
    id,
    firstName,
    lastName,
    ...
});

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the user. It should consist of two parts and look like "origin:id", where origin can be "dvm" or other name of source messenger's database, such as telegram.
firstNameStringYesUser's first name.
lastNameStringOptionalUser's surname.

It is not finished list of properties. You can pass other user's info such as email, phone, avatar etc.

Get User

Use this method to get info about registered user. If user is not registered, method throws error

const chat = await dvm.users.withId(id).get();

Request:

ParameterTypeRequiredDescription
idStringYesUnique identifier for the user. It should consist of two parts and look like "origin:id", where origin can be "dvm" or other name of source messenger's database, such as telegram.

List Users

Use this method to get list of registered users

const { users, meta } = await dvm.users.list({
    offset,
    limit,
});

Request:

ParameterTypeRequiredDescription
offsetIntegerOptionalSequential number of the first user to be returned. Defaults to 0.
limitIntegerOptionalLimits the number of users to be returned. Values between 1—100 are accepted. Defaults to 10.

Response:

ParameterTypeDescription
usersArray of UserA list of User objects.
metaPaginationMetaPagination info.

License

This project is licensed under the MIT License

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago