npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lakeel-messenger-apis

v0.1.19

Published

LaKeel Messenger APIs Node.js Client

Downloads

91

Readme

Lakeel Messenger APIs

npm Status ts Status

Table of Contents

Getting Started

This package is built for Lakeel Messenger API ver1.0 in TypeScript. Any questions regarding set up and API management, please visit here. Detailed documentation is also up on the website above.

This API simplifies the process of setting up headers and string manipulations required for executing Lakeel Messenger API. Authentication set up is only needed once, and the type checks are featured to reduce any invalid requests to the server. Response type is not modified but passed as Promise object for easier error handling.

Install

npm

npm install --save lakeel-messenger-apis

And start using the API:

const lakeel = require("lakeel-messenger-apis");

const messenger = new lakeel.LM("apikey", "secretkey", "example.hostname.com");

Usage

JID is a unique identification code given to every user and room. Most functions require to input a JID and invalid code will result in an error.

All functions use the asynchronous method to process data and return value of these functions are in Promise object. Use then() and catch() to process their callbacks.

Send/Receive messages

Send

This function will send a message to the specified JID. If the API account is a bot, it must already exist in the room to post messages. Otherwise, use a user API to send messages to rooms without joining.

The API account status will change to online during the process.

messenger.sendMessage("target_JID", "Hello World!");

Request

| Type | Parameter | Content | Required | | -------- | ----------- | ------------------------------ | -------- | | string | jid | Target JID | ✅ | | string | message | Message to send | ✅ | | string[] | mentionJids | Target mention JIDs | ❌ | | bool | isFormatted | Whether message formatting in markdown notation is rendered on the receiving client | ❌ |

Response

| Type | Name | Content | | ------ | --------- | --------------------------------------- | | string | timestamp | Time of message sent in ISO 8601 format | | string | messageId | Message ID |

Receive

This function will download sent messages between an API account and a target user or room. The messages are marked as read once downloaded.

Optional settings
force: False (default) will download new messages since the last time this function is called. Setting it True will result in downloading any past 1000 messages.
include: False (default) will not download messages sent by this account.

messenger.receiveMessage("target_JID", true, false);

Request

| Type | Parameter | Content | Required | | ------ | --------- | --------------------------------------- | -------- | | string | jid | Target JID | ✅ | | bool | force | Setting for only receiving new messages | ❌ | | bool | include | Include messages sent by youself | ❌ |

Response

| Type | Name | Content | | ----- | -------- | --------------- | | array | messages | Message Objects |

Message Object

| Type | Name | Content | Required | | ----------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | string | type | Message type"text" : normal message"broadcast" : broadcast message"file" : file messageSystem message"system.replyrequest" : reply request"system.chatmail.success" : successful transmission of chat mail"system.chatmail.failure" : failed to send chat mail"system.room.enter" : participate in room"system.room.invite" : inviting room"system.room.refuse" : room refusal"system.room.disinvite" : room invitation cancellation"system.room.leave" : room exit"system.room.rename" : room name change"system.room.invite.failure" : invitation failed | ✅ | | User Object | user | User Object | ❌ | | string | body | Message | ✅ | | string | timestamp | Time of message sent in ISO 8601 format | ✅ | | string | messageId | Message ID | ✅ | | File Object | file | File Object | ❌ |

User Object

| Type | Parameter | Content | Required | | ------------------- | ------------ | ------------------- | -------- | | string | jid | Target JID | ✅ | | string | name | User name | ✅ | | Organization Object | organization | Organization Object | ✅ |

Organization Object

| Type | Parameter | Content | Required | | ------ | --------- | ----------------- | -------- | | string | id | Organization ID | ✅ | | string | name | Organization name | ✅ |

File Object

| Type | Parameter | Content | Required | | ------ | --------- | --------- | -------- | | string | id | File ID | ✅ | | string | name | File name | ✅ |

Send message with buttons

User API account will be required to join the room before posting messages. Bot API account can send messages to rooms without joining. However, the bot will join the room after sending a message.

The API account status will change to online during the process.

An array of button objects are required. Use the button() function to create the objects.

let button1 = lakeel.button("message", "Clicked!", "Button One", "success");
...

messenger.sendButton("target_JID", "It's a message!", "horizontal", [button1, button2...]);

Request

| Type | Parameter | Content | Required | | ------ | ----------- | -------------------------------------------------------------- | -------- | | string | jid | Target JID | ✅ | | string | message | Message to send | ✅ | | string | type | Button arrangement"horizontal""vertical""dropdown" | ✅ | | array | buttons | Button objects | ✅ | | bool | isFormatted | Whether message formatting in markdown notation is rendered on the receiving client | ❌ |

Response

| Type | Name | Required | | ------ | --------- | --------------------------------------- | | string | timestamp | Time of message sent in ISO 8601 format | | string | messageId | Message ID |

Button Object

| Type | Name | Content | Required | | ------ | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | string | type | Button types"message""message_argument""dialog""url""postback""postback_argument""password""location""datetimepicker""datetimepicker_range" | ✅ | | string | value | Value sent on click | ✅ | | string | label | Button label | ✅ | | string | style | Button color"default""info""success""danger" | ❌ | | string | hint | Tips displayed in the input dialog※Valid only when type is "message_argument" or "postback_argument" | ❌ | | string | token | Value added to the request header sent by the postback※Valid only when type is "postback", "postback_argument" or "password" | ❌ | | string | data | Value added to the request body sent by the postback※Valid only when type is "postback" | ❌ | | string | mode | Date format selectable in datepicker※Required if type is "datetimepicker" or "datetimepicker_range""date_calendar" (Format: yyyy-MM-dd)"date_drumroll" (Frormat: yyyy-MM-dd)"datetime" (Format: yyyy-MM-ddThh:mm, yyyy-MM-dd)"time" (Format: hh:mm)"year_month" (Format: yyyy-MM) | ❌ | | string | min | The minimum date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ | | string | max | The maximum date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ | | string | init | Default date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ | | string | textAlign | Specifies the horizontal alignment of the text displayed on the button."center""left""right"※If not specified, it's automatically set to center.※Support for windows client only. Centred on iOS and Android. | ❌ |

Send carousel message

Send a carousel message to a specified user or room.

User API account will be required to join the room before posting messages. Bot API account can send messages to rooms without joining. However, the bot will join the room after sending a message.

The API account status will change to online during the process.

An array of panel objects are required. Use the panel() function to create the objects. The panel itself will act as a button, and its behaviour is defined by a panel button object using panelButton(). Within the panel, custom buttons can be placed using an array of the button objects.

let button1 = lakeel.button("message", "Button Clicked!", "Button One");
var panelButton1 = lakeel.panelButton("message", "Panel Clicked!");
var panel = lakeel.panel("It's a panel!", panelButton1, [button1...]);

let buttonMsg = messenger.sendCarousel("target_JID", "It's a message!", [panel]);

Request

| Type | Parameter | Content | Required | | ------ | ----------- | ------------------------------ | -------- | | string | jid | Target JID | ✅ | | string | message | Message to send | ✅ | | array | panels | Panel Objects | ✅ | | bool | isFormatted | Whether message formatting in markdown notation is rendered on the receiving client | ❌ |

Response

| Type | Name | Content | | ------ | --------- | --------------------------------------- | | string | timestamp | Time of message sent in ISO 8601 format | | string | messageId | Message ID |

Panel Object

| Type | Name | Content | Required | | ------ | -------- | ------------------------------------------------------------- | -------- | | string | body | Body message for a panel | ✅ | | object | action | Panel Button Object | ✅ | | array | actions | Button Objects | ✅ | | string | imageUrl | Image URL | ❌ | | string | title | Panel Title | ❌ | | string | type | Panel arrangement"horizontal""vertical""dropdown" | ❌ |

Panel Button Object

| Type | Name | Content | Required | | ------ | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | string | type | Panel Button types"message""message_argument""dialog""url""postback""postback_argument""password""datetimepicker""datetimepicker_range" | ✅ | | string | value | Value sent on click | ✅ | | string | label | Button label | ❌ | | string | hint | Tips displayed in the input dialog※Valid only when type is "message_argument" or "postback_argument" | ❌ | | string | token | Value added to the request header sent by the postback※Valid only when type is "postback", "postback_argument" or "password" | ❌ | | string | data | Value added to the request body sent by the postback※Valid only when type is "postback" | ❌ | | string | mode | Date format selectable in datepicker※Required if type is "datetimepicker" or "datetimepicker_range""date_calendar" (Format: yyyy-MM-dd)"date_drumroll" (Frormat: yyyy-MM-dd)"datetime" (Format: yyyy-MM-ddThh:mm, yyyy-MM-dd)"time" (Format: hh:mm)"year_month" (Format: yyyy-MM) | ❌ | | string | min | The minimum date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ | | string | max | The maximum date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ | | string | init | Default date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ |

Button Object

| Type | Name | Content | Required | | ------ | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | string | type | Button types"message""message_argument""dialog""url""postback""postback_argument""password""datetimepicker""datetimepicker_range" | ✅ | | string | value | Value sent on click | ✅ | | string | label | Button label | ✅ | | string | style | Button color"default""info""success""danger" | ❌ | | string | hint | Tips displayed in the input dialog※Valid only when type is "message_argument" or "postback_argument" | ❌ | | string | token | Value added to the request header sent by the postback※Valid only when type is "postback", "postback_argument" or "password" | ❌ | | string | data | Value added to the request body sent by the postback※Valid only when type is "postback" | ❌ | | string | mode | Date format selectable in datepicker※Required if type is "datetimepicker" or "datetimepicker_range""date_calendar" (Format: yyyy-MM-dd)"date_drumroll" (Frormat: yyyy-MM-dd)"datetime" (Format: yyyy-MM-ddThh:mm, yyyy-MM-dd)"time" (Format: hh:mm)"year_month" (Format: yyyy-MM) | ❌ | | string | min | The minimum date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ | | string | max | The maximum date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ | | string | init | Default date or time value that can be selected in the datepicker※Valid only when type is "datetimepicker" or "datetimepicker_range" | ❌ | | string | textAlign | Specifies the horizontal alignment of the text displayed on the button."center""left""right"※If not specified, it's automatically set to center.※Support for windows client only. Centred on iOS and Android. | ❌ |

File

There are three ways to send a file using this API. Local file path method , binary method and base64 method.

Send file method #1 FILE PATH

Send a file to a specified user or room.

User API account will be required to join the room before sending files. Bot API account can send files to rooms without joining. However, the bot will join the room after sending a file.

The API account status will change to online during the process.

The file path must include the target file name and its file extension.

messenger.sendFileByPath("target_JID", "file_path/abc.jpg");

Request

| Type | Parameter | Content | Required | | ------ | --------- | ---------- | -------- | | string | jid | Target JID | ✅ | | string | filePath | File Path | ✅ |

Response

| Type | Name | Content | | ------ | --------- | --------------------------------------- | | string | timestamp | Time of message sent in ISO 8601 format | | string | fileId | File ID |

Send file method #2 Row

Send a file to a specified user or room.

User API account will be required to join the room before sending files. Bot API account can send files to rooms without joining. However, the bot will join the room after sending a file.

The API account status will change to online during the process.

const imgData = fs.readFilesync("file_path/abc.jpg");

messenger.sendFileByRow("target_JID", imgData, "abc.jpg");

Request

| Type | Parameter | Content | Required | | ------ | --------- | ----------- | -------- | | string | jid | Target JID | ✅ | | Buffer | data | File buffer | ✅ | | Buffer | name | File name | ✅ |

Response

| Type | Name | Content | | ------ | --------- | --------------------------------------- | | string | timestamp | Time of message sent in ISO 8601 format | | string | fileId | File ID |

Send file method #3 base64 encoded string

Send a file to a specified user or room.

User API account will be required to join the room before sending files. Bot API account can send files to rooms without joining. However, the bot will join the room after sending a file.

The API account status will change to online during the process.

const imgDataStr = "img_encoded_in_base64_string";

messenger.sendFileByBase64("target_JID", imgDataStr, "abc.jpg");

Request

| Type | Parameter | Content | Required | | ------ | --------- | ------------------------------------------ | -------- | | string | jid | Target JID | ✅ | | string | base64Str | File content encoded in base64 string form | ✅ | | string | name | File name | ✅ |

Response

| Type | Name | Content | | ------ | --------- | --------------------------------------- | | string | timestamp | Time of message sent in ISO 8601 format | | string | fileId | File ID |

Receive file

Download a file sent in a chat using File ID.

File ID can be obtained from receiveMessage() function or from the sendFile function's receipt. This function will return a File object containing a filename and binary data.

let receive = messenger.receiveFile("target_JID", "file_id");

Request

| Type | Parameter | Content | Required | | ------ | --------- | ---------- | -------- | | string | jid | Target JID | ✅ | | string | fileId | File ID | ✅ |

Response

| Type | Name | Content | | ------ | -------- | ------------------- | | string | fileName | File Name | | Buffer | body | File in binary data |

Make File

Input the response of receiveFile() function and an output file path. This will rebuild the file from downloaded binary data.

messenger.makeFile("./output", receive);

Request

| Type | Parameter | Content | Required | | ----------- | --------- | ----------- | -------- | | string | filePath | File Path | ✅ | | File Object | file | File Object | ✅ |

Response

| Type | Name | Content | | ------ | ------- | ----------------------- | | string | message | Completion message "OK" |

Get talks

Get your own talk. (Up to 1000 cases)

If the force parameter is not specified or set to false, only the talks updated since the last call of this function is downloaded.

messenger.getTalks(false);

Request

| Type | Parameter | Content | Required | | ---- | --------- | --------------------- | -------- | | bool | force | Include updated talks | ❌ |

Response

| Type | Name | Content | | ------- | ---------------- | ------------------------------- | | array | talks | Talk Objects | | integer | totalUnreadCount | Total number of unread messages |

Talk Object

| Type | Name | Content | | ------- | -------------- | ---------------------------------------- | | string | jid | Target JID | | string | type | Type"chat""room""invitation" | | string | lastUpdateTime | Last update data | | string | name | Name | | integer | unreadCount | Unread messages |

Presence

Get a presence of a specified user.

messenger.getPresence("target_JID");

Request

| Type | Parameter | Content | Required | | ------ | --------- | ---------- | -------- | | string | jid | Target JID | ✅ |

Response

| Type | Name | Content | | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | string | presence | Presence state"Online": Presence"Away": Leave temporarily"Do Not Disturb": Busy"ExtendedAway": Extended Away"Mobile": Logged in from mobile device"Offline": Not logged in | | string | imageUrl | The URL of the image showing the state of presence |

Room

Get room

Get information about a specified room.

messenger.getRoom("target_roomJID");

Request

| Type | Parameter | Content | Required | | ------ | --------- | --------------- | -------- | | string | jid | Target room JID | ✅ |

Response

| Type | Name | Content | | ------------ | ----------- | --------------------------------------------------------------------------------- | | string | name | Room name | | string | comment | Description | | Owner Object | owner | Owner Object | | array | users | User Objects | | bool | canWithdraw | Whether user can withdraw from this room.true: possiblefalse: impossioble |

Owner Object

| Type | Name | Content | Required | | ------ | ---- | --------- | -------- | | string | jid | Owner JID | ✅ |

User Object

| Type | Name | Content | Required | | ------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | string | jid | User JID | ✅ | | string | status | Status for room"enter": participating"leave": withdraw"invite": inviting"refuse": participation refused"disinvite": invitation canceled | ✅ |

Create room

Use to create a room with specified owner and users.

Use makeOwner() and makeUser() to create Owner and User objects.

※ Do not include the owner in the User array

let owner = lakeel.makeOwner("owner_JID");
let user1 = lakeel.makeUser("user_JID");

messenger.createRoom(owner, [user1...], "Room One", true);

Request

| Type | Parameter | Content | Required | | ------------ | ----------- | --------------------------------------------------------------------------------- | -------- | | Owner Object | owner | Owner Object | ✅ | | array | users | User Objects | ✅ | | string | name | Room name | ✅ | | bool | canWithdraw | Whether user can withdraw from this room.true: possiblefalse: impossioble | ❌ |

Response

| Type | Name | Content | | ------ | --------- | --------------------------------------- | | string | timestamp | Time of message sent in ISO 8601 format | | string | roomJid | Room JID |

User Object

| Type | Name | Content | Content | | ------ | ---- | -------- | ------- | | string | jid | User JID | ✅ |

Edit room

Edit an existing room.

There are two statuses for User object. Set as "enter" when adding a new user and "leave" when withdrawing an existing member.
When changing the owner, be sure to designate the member whose status is "enter".

Use makeOwner() and makeUser() to create Owner and User objects.

Previously makeUser() did not require a user status when creating a room. However, user status is required when editing room.

let owner = lakeel.makeOwner("owner_JID");
let user1 = lakeel.makeUser("user_JID", "enter");
let user2 = lakeel.makeUser("user_JID", "leave");

let room = messenger.editRoom("target_roomJID", owner, [user1, user2], "New Name", true);

Request

| Type | Parameter | Content | Required | | ------------ | ----------- | ---------------------------------------------------------------------------------- | -------- | | string | jid | Target room JID | ✅ | | Owner Object | owner | Owner Object | ✅ | | array | users | User Objects | ✅ | | string | name | Room name | ✅ | | bool | canWithdraw | Whether users can withdraw from this room.true: possiblefalse: impossioble | ❌ |

Response

| Type | Name | Content | | ------ | --------- | --------------------------------------- | | string | timestamp | Time of message sent in ISO 8601 format | | string | roomJid | Room JID |

User Object

| Type | Name | Content | Required | | ------ | ------ | -------------------------------------------------------------- | -------- | | string | jid | User JID | ✅ | | string | status | Status for room"enter": participating"leave": withdraw | ✅ |

User

Get user info

Get user info by specifying single or multiple conditions. Use UserSearchCondition class to create condition object.

const condition = new lakeel.UserSearchCondition();
condition.setIsAdmin(true)
            .setLastAccessAtAfter("2020-09-01T00:00:00.000Z")
            .setLastAccessAtBefore("2020-09-09T00:00:00.000Z")
            .setPage(2)
            .setPerPage(5);

messenger.getUsers(condition);

If you omit to pass in condition, this method will return the result with pagination of page 1 and perPage 1000.

messenger.getUsers();

Request(UserSearchCondition object)

| Argument Type | Method Name | Description | Required | | -------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | string | setJid | Add a condition of jid. | ※2 | | string | setId | Add a condition of id. | ※2 | | string | setUniqueKey | Add a condition of uniqueKey. | ※2 | | string | setName | Add a condition of user name. Partial match.※1 | ※2 | | string | setPhoneticName | Add a condition of user's Japanese kana name. Partial match.※1 | ※2 | | string | setMainOrganizationName | Add a condition of main organization name to which a user belongs. Partial match.※1 | ※2 | | bool | setIsAdmin | Add a condition of administrator flag. | ※2 | | bool | setIsMailLocked | Add a condition of chat mail lock flag. | ※2 | | bool | setIsAccountLocked | Add a condition of account lock flag. | ※2 | | bool | setIsExpired | Add a condition of logical deletion flag. | ※2 | | string(ISO8601, UTC) | setLastAccessAtAfter | Return users who accessed to LaKeel Messenger after the time that specified in this parameter. The specified time is included. Both short-form and long-form are valid as in code above. | ※2 | | string(ISO8601, UTC) | setLastAccessAtBefore | Return users who accessed to LaKeel Messenger before the time that specified in this parameter. The specified time is included. Both short-form and long-form are valid as in code above. | ※2 | | string[] | setTags | Add a condition of tags. | ※2 | | number | setPage | Page number. If you don't indicate this, default value 0 will be applied. | ※2 | | number | setPerPage | The number of user data per page. If you don't specify this, default value 1000 will be applied. | ※2 |

※1 'jo' will hit 'joe', 'john', 'johnson', 'jordan'. ※2 All conditions are optional. If you omit them all, you get first 1000 user data out of all data.

Response

| Type | Name | Description | | ------ | ----- | ------------------------------------------------------------------------------------------------------ | | array | users | User Data Objects. | | number | total | The number of matched user data. | | string | prev | URI to get user data set from the previous page. If no prev URI exists, this property will be omitted. | | string | next | URI to get user data set from next page. If no next URI exists, this property will be omitted. |

User Data Object

| Type | Name | Description | | -------------------- | -------------------- | ------------------------------------------------------------------------------------- | | string | jid | jid | | string | id | id | | string | uniqueKey | unique key | | string | name | name | | string | phoneticName | phonetic name (japanese kana) | | string | mainOrganizationId | main organization id | | string | mainOrganizationName | main organization name | | array | affiliationInfo | Affiliation info objects | | bool | isAdmin | admin flag | | string | adminRoleId | admin role id. If user does not have any admin role, this will be an empty string. | | string | adminRoleName | admin role name. If user does not have any admin role, this will be an empty string. | | bool | isMailLocked | mail lock flag | | bool | isAccountLocked | account lock flag | | bool | isExpired | logical deletion flag | | string(ISO8601, UTC) | lastAccessAt | last access date. If user has never accessed before, this property does not be shown. | | string(ISO8601, UTC) | passwordChangedAt | date when password was changed | | string[] | tags | user’s tags |

Affiliation Info Object

| Type | Name | Description | | ------ | --------------------- | ------------------------------ | | string | organizationId | organization id | | string | organizationName | organization name | | string | description | job title in this organization | | bool | isMainOrganization | main organization flag | | bool | isDisplayOrganization | display organization flag | | number | sortOrder | sort order |

Account lock status

Update an account lock status of a specified user.

messenger.changeLock("target_JID", true);

Request

| Type | Parameter | Content | Required | | ------ | --------- | ------------------------------------------ | -------- | | string | jid | Target JID | ✅ | | bool | locked | Lock statustrue: Lockfalse: Unlock | ✅ |

Response

| Type | Name | Content | | ------ | ------- | ----------------------- | | string | message | Completion message "OK" |

Change password

Change a password of a specified user.

messenger.changePassword("target_JID", "newpass", true);

Request

| Type | Parameter | Content | Required | | ------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | string | jid | Target JID | ✅ | | string | password | New password | ✅ | | bool | forced | Set whether to change the password the next time you sign in forcibly.true : forcefalse : Don’t force.If not specified, false is set. | ❌ |

Response

| Type | Name | Content | | ------ | ------- | ----------------------- | | string | message | Completion message "OK" |

Reset password

Reset an existing password of a specified user to a character string created with random number.

messenger.resetPassword("target_JID");

Request

| Type | Parameter | Content | Required | | ------ | --------- | ---------- | -------- | | string | jid | Target JID | ✅ |

Response

| Type | Name | Content | | ------ | -------- | -------------------- | | string | password | 8 digit new password |

Csv

There are two ways of uploading csv data. One is updating the whole DB data with uploaded csv data(uploadCsvAll) and another is only updating DB data with differential one(uploadCsvDiff).

Suppose we have user data A and B on DB. A's id is 1 and B's 2. You have your own user csv file, in which there's only A's data and it says its id is 3. Here you want to update user A's id from 1 to 3.

This time, you can't use uploadCsvAll because it'll result in losing B's data and not being able to keep data consistency. uploadCsvAll replace the whole DB data with uploaded one. But you can use uploadCsvDiff instead. It only updates A's data and B's doesn't change at all.

Upload Csv (All)

Select file paths and their encodings.

messenger.uploadCsvAll("some/organization/csv/file/path", "utf8", "some/user/csv/file/path", "utf8", "some/affiliation/csv/path", "utf8", "", "")

Request

| Type | Name | Description | Required | | ------ | ---------- | ------------------------------------------------- | -------- | | string | orgPath | Path to your organization csv file. | ※1 | | string | orgEncd | Encoding of your organization csv file. | ※2 | | string | userPath | Path to your user csv file. | ※1 | | string | userEncd | Encoding of your user csv file. | ※2 | | string | affPath | Path to your affiliation csv file. | ※1 | | string | affEncd | Encoding of your affiliation csv file. | ※2 | | string | orgPubPath | Path to your organization publicity csv file. | ※1 | | string | orgPubEncd | Encoding of your organization publicity csv file. | ※2 |

※1 You have to select at least one file. ※2 If you select a file, you must also specify its encoding. If not, just leave it an empty string.

Response

| Type | Name | Description | | -------- | -------- | ---------------------------------- | | string[] | messages | Messages that describe the result. |

Upload Csv (Diff)

Select file paths and their encodings.

messenger.uploadCsvDiff("some/organization/csv/file/path", "utf8", "some/user/csv/file/path", "utf8", "some/affiliation/csv/path", "utf8", "", "")

Request

| Type | Name | Description | Required | | ------ | ---------- | ------------------------------------------------- | -------- | | string | orgPath | Path to your organization csv file. | ※1 | | string | orgEncd | Encoding of your organization csv file. | ※2 | | string | userPath | Path to your user csv file. | ※1 | | string | userEncd | Encoding of your user csv file. | ※2 | | string | affPath | Path to your affiliation csv file. | ※1 | | string | affEncd | Encoding of your affiliation csv file. | ※2 | | string | orgPubPath | Path to your organization publicity csv file. | ※1 | | string | orgPubEncd | Encoding of your organization publicity csv file. | ※2 |

※1 You have to select at least one file. ※2 If you select a file, you must also specify its encoding. If not, just leave it an empty string.

Response

| Type | Name | Description | | -------- | -------- | ---------------------------------- | | string[] | messages | Messages that describe the result. |

Movie

Send movie

Send a movie to a specified user or room.

User API account will be required to join the room before sending a movie. Bot API account can send a movie to rooms without joining. However, the bot will join the room after sending a file.

The API account status will change to online during the process.

The file path must include the target file name and its file extension.

messenger.sendMovie("target_JID", "some/file/path");

Request

| Type | Parameter | Content | Required | | ------ | --------- | ------------------------------------------------------------ | -------- | | String | jid | Your file is sent to someone or some room that has this jid. | ✅ | | String | filePath | Path that indicates your movie file. | ✅ |

Response

| Type | Name | Content | | ------ | -------- | --------------------------------------- | | string | id | Your file id that is used in LM system. | | string | name | Your file name. | | string | mimeType | Your file mime type. |

Browserify

How to use it in HTML and web page using Browserify

Install Browserify globally

npm install -g browserify

Create an empty project and install Lakeel Messenger APIs.

Make sure "lakeel-messenger-apis" exists in your node_module folder.

Create a main.js at the project directory.

//main.js
'use strict';
console.log("Module Loaded");
const lakeel = require('lakeel-messenger-apis');

window.lakeel = lakeel;

Save and run

browserify main.js -o bundle.js

Now take the bundle.js and place it in your web folder. Import and done.

Sample

//index.html
<script type="text/javascript" src="bundle.js"></script>
<script type="text/javascript">
    const apiKey = "api";
    const secretKey = "secret";
    const hostname = "example.hostname.com";
    const messenger = new lakeel.LM(apiKey, secretKey, hostname);
    const jid ="[email protected]";
</script>

<form>
<h1>Message test</h1><br>
<input type="text" value="Hi" id="msg"><br>
<input type="submit" onclick="messenger.sendMessage(jid,document.getElementById('msg').value)">
</form>

Error handling

Errors can be caught using catch().

Sample

Failed to send a message.

const send = messenger.sendMessage("target_JID", "Hi!")

.then((success) => console.log("Success"))
.catch((err) => console.log(err));

Error response is in the following format

{
    "error": {
        "code": 400,
        "message": "Missing parameters.",
        "function": "sendMessage",
        "err": Error
    }
}
{
    "error": {
        "code": 400,
        "message": "Posted data has problems.",
        "invalidData": {
            "users": [
                {
                    "jid": "[email protected]",
                    "cause": "Non-existent user."
                },
                {
                    "jid": "[email protected]",
                    "cause": "Duplicated user."
                }
            ]
        }
    }
}

Help

Bugs

Known bugs

  • Error 503 page is returned when calling a receieveFile with an invalid file ID
  • Editing room does not return room JID after a successful process

Example

What does it do?

  • Sends an image
  • Downloads the sent image
  • Rebuilds the downloaded data to an output folder as an image

All using a Promise chain

const lakeel = require('lakeel-messenger-apis');

const apiKey = "api";
const secretKey = "secret";
const hostname = "example.hostname.com";
const img = fs.readFilesync("file_path/abc.jpg");
const messenger = new lakeel.LM(apiKey, secretKey, hostname);

const jid ="[email protected]";

//Send the file
messenger.sendFileByRow(jid, img, "abc.jpg")
.then((data) => {
    let fileId = data['fileId']; //Extract the file ID
    return messenger.receiveFile(jid, fileId); //Download the image
})
.then((result) => {
    //Rebuild the image to the output folder
    return messenger.makeFile("./output", result);
})
.finally(() => {
    console.log("Success :)");
})
.catch((err) => {
    console.log("Something went wrong :( " , err);
});

Author

Kamata Takashi, Ryoei Shimaura

License

ISC