Installing and configuring

Authorization from Kommo side

Since we use OAuth 2.0 authorization, after creating the integration according to our step-by-step example, an authorization token will be produced, which you should exchange to get a pair of access/refresh tokens. These tokens should be saved in your database along with the time when they expire.

As indicated in our subject area, one user can install the integration in more than one account. Integrators should pay attention to protecting the information between the accounts, and prevent leaking the information between the accounts of one user.

Once the integration is installed, the settings window will appear, with fields to be filled by the administrator of the Kommo account. Kommo will only consider your integration configured successfully once the settings are saved correctly. This is implemented in the Ui/UX, by calling the onSave callback function when the administrator chooses to save the integration settings. This function should return true once the widget is successfully configured, false otherwise.

var CustomWidget = function () {
  	self.clickSaveButton = function() {
	    /*
	     * This function describes what to do when clicking on the saving button
	     */
	    var $save_button = $(document).find('.js-widget-save');
	    $save_button.click();
	};
	widget_register: function (e) {
	   /* 
	    * Registering the widget
	    */
	   self.tools.request({}, 'register_widget', function (res) {
	        self.registered = self.checked = true;
		self.clickSaveButton();
          });
	},
	
	this.callbacks = {
		//other callbacks
		//...
	      	onSave: function () {
		   /*
		    * Here you should perform your settings 
		    */
		    if(/*Here you should test if settings were successfully saved*/) {
		      alert ('Your integration settings have been successfully saved.');
		      return true;
		    }
		    alert('Kommo could not register your widget.');
		    return false;
	      }
	      //other callbacks
        }
        return this;
}

The following picture shows saving the configuration.
foto
When pressing the save button, the code in the onSave function is executed, and in our example, it shows an alert window.

foto

Please keep in mind not to use the account subdomain as the primary key for your settings since it could be changed. We also recommend not using the account id either for other considerations. You can use an auto-increment id field as the primary key, and the account ID and subdomain will simply be string properties.

For more about the configurations, please review the widget settings.

VoIP service application authorization

After the user installs the integration from the Kommo Marketplace, the integration should show a modal window for settings where the user can perform some actions, such as providing the credentials to access the VoIP service. These credentials are known only to the administrator of the VoIP account.

It is necessary to save the authorization information for further calls to the service API. The widget can be considered active.

Integration settings

The configurations might include enabling the ringing sound and providing feedback, auto-opening the client card, and rating the call quality.

You can also give the administrators the ability to choose what happens when different types of calls happen, calls from known or unknown numbers, and the call that took place or were missed.

When an unknown number calls, you can add settings like directly creating a new account and a lead or an incoming lead. Also, you can provide managers the option to accept the incoming lead, or it will be automatically accepted when answering the call.

When a call from a known contact comes, the settings might include creating a lead if there is no active lead, and adding a number to the note if the connection has many numbers. And when a manager misses a call, they can include automatically creating a task and setting the time for it, linking the task to the lead, and adding a responsible user. On outgoing calls with new numbers, you can add settings for creating a new contact and a new lead.

Data representation

An example of the information you can record in your database.

Fields of Kommo Authorization Tokens

Field Description
KommoAccountId The account id in which the integration is installed.
AccessToken The integration access token
RefreshToken The integration refresh token
ExpiresAt The expiration date for the tokens

 

Fields of widget settings

Field Description
KommoAccountId The account id in which the integration is installed.
VoIPToken The keys to accessing the VoIP service.
Active A boolean to detect the widget activity status

 

Fields of VoIP Users

Field Description
Id primary key
KommoAccountId The account id in which the integration is installed.
KommoUserId The user from the Kommo Account to which we give an extension
ExtentionId The extension number provided by VoIP service

 

Fields of VoIP calls

Field Description
CallId The call id
KommoAccountId The account id in Kommo
FromNumber The number from which the call occurred
ToNumber The number to which the call occurred
Direction Incoming( inbound) or outgoing (outbound) call
Recording Link to the call recording
ResponsibleUserId Kommo user Id of the user responsible for the call
Status Call status (Accepted, Voicemail, Missed)
CallResult The call result note added by the manager
Duration The call duration
Delivered Delivery status (COMPLETED, CREATED, UNDELIVERED, HAS_ERROR)
StartedAt The time of the beginning of the call
EntityId The entity to which the call is connected
EntityType Type of the entity to which the call is connected
CreatedAt The time of registering the call
Unsorted The id of the incoming lead if exists

 

Database scheme

foto

Entities

While programming, we need to declare some entities

Call Entity

Field Description
CallId The call id
FromNumber The number from which the call occurred
ToNumber The number to which the call occurred
Duration The call duration
RecordLink Link to the call recording
StartedAt The time of the beginning of the call
CallResult The call result note added by the manager
CallType Incoming( inbound) or outgoing (outbound) call
Status Call status (Accepted, Voicemail, Missed)
ResponsibleUser Kommo user Id of the user responsible for the call

 

FromWebhook Entity

Field Description
CallId The call id
VoIPAccountId Id of the VoIP service account
From The number from which the call happened
To Number to which the call happened
Status Call status (Accepted, Voicemail, Missed)
StartTime The time of the beginning of the call

 

User Entity

Field Description
Id Id of the user
Name Name of the user
AccountId The account id in VoIP

 

Entity diagram

foto

Next let’s move to the Call logging use case.