Environment variables

If you need to interact with a client's account, you can access the global APP object which provides you with relevant data based on the user interface they are currently using.

To explore the capabilities of this tool, you can open the console and enter APP.

Name of the entity you are in

APP.getBaseEntity()

The method will return a string indicating the entity you are currently in (e.g., leads or contacts).

Check whether you are in the card

APP.isCard()

The method will return a Boolean value (true/false) indicating whether you are currently in the card.

Get the current page code

APP.getWidgetsArea()

The method will return the code of the current page.

AreaDescription
dashboardDashboard
leadsList of leads
leads-trashList of deleted leads
leads-pipelinePipeline
contactsList of contacts
contacts-trashList of deleted contacts
companiesList of companies
mailMail section
todoList of tasks
todo-trashList of deleted tasks
todo-lineKanban view of tasks list
todo-calendarCalendar view of tasks list
eventsList of events in Analytics section (Activity log)
authlogAuthorization log page (Settings ▶︎ Users ▶︎ Authorization log)
stats-humanReport by Activities in Analytics section
statsCallsCall Report in Analytics section
widget-page:{{code}}Widget page added to the left menu
settingsSettings section
advanced-settings:{{code}}Advanced settings of a widget
widgetsSettingsIntegrations section of Settings
settings-usersUsers section of Settings
settings-communicationsCommunication Tools section of Settings
catalogsCustom lists
leads_cardLead profile
contacts_cardContact profile
companies_cardCompany profile

Determine the language set in the user profile

APP.lang_id

The property stores the letter code of the language set in the user profile.

CodeLanguage
enEnglish
esSpanish
ptPortuguese

Get/set the value of a constant

Available constants

KeyDescription
userCurrent user info
user_rightsCurrent user rights info
accountAccount info
managersAccount users
groupsGroups of users
task_typesCustom task types

APP.constant(key)

The function is designed to retrieve the constant's value passed to the key.

APP.constant('user')


{
  amojo_id: "1111111-2222-3333-4444-55555555555555",
	api_key: "",
	group_mates_ids: (5) [123456, 234567, 3456789, 4567890, 0987654],
	id: 123456,
	login: "[email protected]",
	name: "Company name",
	personal_mobile: "+1234567890",
	photo: "/v3/users/some-photo/avatar/?1234567890",
	settings: 
	{layout_width: {…}, feed_filter: null, notify_time_before_task: 300, default_task_preset: '', need_msec: false, …},
	sso_auth: false,
	theme: 1,
	tour: false,
	user_rank: "master",
	uuid: "55555555-6666-7777-8888-999999999",
	[[Prototype]]: Object
}

APP.constant(key, [value])

On the other hand, if a value is passed, it will set the constant's value to that value.

🚧

  • Public integrations have specific guidelines that prohibit reassigning system constants.
  • System constants that aren't included in the list above may change or disappear at all.

Accessing data on a page

The main part of the system is implemented in the backbone.js framework. You can refer to the framework's documentation to work with environment variables.

APP.data.current_view

If you are working with any system interface apart from cards, you can access the APP.data.current_view object, which contains the root DOM element of the current interface where the user is working (APP.data.current_view.$el).

APP.data.current_list

If the user is currently working with any list interface, such as leads, contacts, companies or tasks, you can access the APP.data.current_list property within the APP object. This property contains a collection of current list items with information retrieved from the displayed columns. This data includes the id, name (entity name), and checked property (which determines whether the element in the list is selected or not).

APP.data.current_card

In case the user is working with any card, you can access the APP.data.current_card property. This property provides access to data on the current card where the user is working. While accessing this property, it is essential to check its presence, as it could be false if the user is not currently on any card. If you directly access any child value without checking the property's presence, it could result in an error.

Through APP.data.current_card you can get the following data:

  • APP.data.current_card.id

    **id** of the current card, if the card is new (being created)its id is 0.
    
  • APP.data.current_card.model

       The [ backbone](https://www.npmjs.com/package/backbone) model stores the current data at the time of entry, which means that even if the user has        made changes to a field but has not yet saved it, the entered value will still be accessible through the model.
    

APP.sdk.setCallingStatus(true/false)

When Kommo is updated, the system automatically updates the page.

However, there may be instances where this behavior needs to be temporarily stopped, such as during a phone call, to prevent any interruptions for the user. In such cases, you can use a specific method to pause the updates until the call is over, so as not to disturb the user with unnecessary updates.

Obtain the online status users

The method described allows you to easily retrieve information about the online status of users.The status can either be true (if the user is online) or false (if the user is offline).

Getting online status for all users

APP.sdk.showUserStatus() // object with all user id and status
// Example response:
{
 {
    id: 123456,
    online: true
  },
  {
    id: 123456,
    online: false
  }, ...
}

Calling the method without any parameters will return an object containing IDs of all users and their online statuses.

Getting the id of all online users

APP.sdk.showUserStatus('online')// array of all id users online
// Example response:
[123456, 123457...]

Calling this method with the “online” flag will list the ids of all online users.

Getting the status of an online user by their id

var id_user = 123456; // Unique account ID
var status_user = APP.sdk.showUserStatus(id_user) ; // online user status (true or false)

To retrieve the status of a specific user, you can call the method with the user's unique account identifier. The function will then return true if the user is online and false if they're not.

Error processing

APP.sdk.showUserStatus(1111111) // object with all users id and status

It's important to note that if an incorrect user ID is entered or an error is made while writing the flag, the function will still work by returning the ID object with the online statuses of all users.