Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Example of using REST API to generate employees
In release 2023.2, an API for quickly creating a large number of employees was implemented. During testing, we described the algorithm for generating new employees in ChatGPT and conducted stress testing for creating 700 random accounts in different languages. It took about 1 minute to complete the load test, and it was successful.
To perform this task, a request to ChatGPT was written with the following content.
If the result parameter in the response is true, we will take the data for creating a new user from the data parameter and make a POST request to the address http://127.0.0.1:8081/pbxcore/api/extensions/saveRecord, using the modified array of form fields in x-www-form-urlencoded format.
The script should be written in Python without using NodeJS and should allow creating 100 different employees. In the user_username field, enter the name and surname of a random person so that national alphabets are used. In the user_email field, enter any email address. In the mobile_number field, enter random mobile phone numbers, only digits, without duplicates. In the fwd_forwarding and fwd_forwardingonbusy fields, fill in with mobile_number values.
When creating an employee, print user_username, user_email, and number to the console and report the result.
If the result of the saveRecord or getRecord request is false, also print the messages parameter from the received response. If the response results in an error of another type or cannot be parsed, print the complete text received from the API server to the console.
As a result, a Python script was generated that allowed us to perform this test.
As a result of the script's execution, you will see a list of created employees in the console, and new user accounts will appear in the web interface.
It's important to note that since the system is read-only, you need to install Python libraries after each reboot, and the /tmp folder will be cleared. Development and refinement of the script should be done in an external system.
When making REST API requests from external addresses, it's necessary to authenticate with an administrative username and password or create a user with the necessary permissions in the employee rights management module and authenticate with it.
When making requests, as in this example, from the address 127.0.0.1, no authentication is required.
We have two accounts from the Zadarma provider, configured in MikoPBX following this .
Each Zadarma number needs to have its own non-working hours. For example, the number +60 17 308 9237 has working hours from 9:00 AM to 6:00 PM, while the number +60 17 308 2584 has working hours from 8:00 AM to 8:00 PM.
Go to System → System File Customization.
Open the extensions.conf configuration file for editing. Set the mode to "Append to the end of the file". In the black editing window, add the following code snippet:
In the above code fragment, you need to specify the logins for your provider accounts. In our example, the following data was used:
584611 - the login for the provider account linked to the phone number +60 17 308 9237.
The working hours are from 9:00 to 18:00. Therefore, two intervals for non-working hours need to be set: 00:00-09:00 and 18:00-23:59.
420296 - the login for the provider account linked to the phone number +60 17 308 2584.
The working hours are from 8:00 to 20:00. Therefore, two intervals for non-working hours need to be set: 00:00-08:00 and 20:00-23:59.
Below, the fragments highlighted in red are the ones you need to modify:
Let's break down the ExecIfTime command in more detail. This command executes the specified Asterisk application if the current time matches the given time specification. In our case, the command plays an audio file located in the directory /offload/asterisk/sounds/other/out_work_times in MikoPBX. Command syntax:
times - Time ranges in 24-hour format
weekdays - Days of the week (mon, tue, wed, thu, fri, sat, sun)
mdays - Days of the month (1-31)
months - Months (jan, feb, mar, apr, etc.)
appname[(appargs)] - the Asterisk command with its call parameters
In our example, a time range and a range of weekdays are specified. Instead of specifying days of the month and months, a * is used, meaning "for all other cases."
Connect providers registered on the same host as described in the instructions.
Go to System → System file customization
Open the extensions.conf configuration file for editing.
Set the "Add to end of file" mode. In the black window, add the following code snippet:
Instead of the numbers X9522140000 and X9629771111, specify the customer phone numbers as they appear in the call history.
Improving the quality of the organization's service is an extremely important component of the successful operation of the company. The mechanism for evaluating the work of an operator will be useful to any business.
In the current article, we offer an example of the implementation of the quality assessment mechanism by the client for PBX MikoPBX.
You should first upload the question/greeting record files to the PBX.
WAV (Microsoft) signed 16-bit PCM recording format. Files can be conveniently placed in the directory: /storage/usbdisk1/quality/sounds.
In dialplan, the path to the file should be specified without an extension.
To begin with, let's add the logic of processing incoming calls:
Go to "Routing" → "Telephony Providers". Open the provider's account for editing. Copy in the address bar the ID of the provider through which subscribers call you to the company. Please note that in our example, the only provider Zadarma is used. If you have configured the connection of several providers, then the following steps must be performed for each provider.
In our example, the provider ID takes the form: SIP-1687947415
Go to "System" → "System file customization".
Open the extensions.conf configuration file for editing.
Set the "Add to end of file" mode.
In the black window, add the following code snippet:
In the above code snippet, you need to make the correct context name.
Format of the created context:
PROVIDER ID is the value that you saved in the first step of this instruction. In our example, this is SIP-PROVIDER-1687947415.
chmod +x /storage/usbdisk1/quality/quality_agi.php
Implementation example quality_agi.php:
The evaluation result will be saved in files like /storage/usbdisk1/quality/<ID>.log
Example file:
Add a new dialplan application (see ).
Assign an internal number, for example, 2200110.
Insert the following code into the "Programme Code" tab:
In the code, replace '[email protected]' with your own email address.
Go to the "System file customization" section.
Open the "extensions.conf" file for editing.
Add the folowwing code to the end of file:
Replace "2200100" with the number of your application.
In the code, replace "SIP-1687941868" with your provider's ID. You can find it in the provider's card in the browser's address bar.
Open the "modules.conf" file for editing.
Add the following code to the end of the file:
In the provider's card, in the advanced settings, in additional parameters, specify:
Instructions for connecting a provider account can be found .
Many telecom operators cannot offer multiple SIP numbers in a single trunk (as one provider account) and provide separate registration details for each number. For example, when using the provider Zadarma, to connect the phone number +60(3)-2293-042, you should use the login 847706 and password XXXXXX, while to connect the phone number +60(3)-6382-584, you should use the login 847900 and password YYYYYY. The host for both accounts will be the same: sip.zadarma.com.
Task: For each number, specific incoming routing needs to be configured. For example, calls to +60(3)-2293-042 should be routed to the sales department (call queue), while calls to +60(3)-6382-584 should be routed to an IVR menu.
Potential Issue: The issue is that all incoming calls will go through the first Zadarma provider account defined in MikoPBX. Calls from the second provider will never be routed through MikoPBX.
In the Routing → Telephony Providers section, create two provider accounts from the same service provider. In our example, this is Zadarma. Enter the correct login, password, and host.
In the advanced options, specify:
In the Routing → Incoming routing section, set up an incoming call rule for each provider. In the Direct inward dialing number field, enter the login from the provider account. In the Provider field, select Provider-independent...
Instructions for setting up incoming call routing are available here.
The file should be saved to the PBX along the path /storage/usbdisk1/quality/quality_agi.php You can create a file using the file manager The file should be set to execute access rights. Connect via and run the command
Go to edit the employee account.
In the "Extra oprions" field, add:
The last registration will work. The softphone/phone that registered last and will receive calls. Outgoing calls can be made by each end device.
Paging through phones, i.e. transmitting a voice message through several phones via speakerphone. For example, a manager can quickly call a meeting.
This instruction is suitable for phones:
Linksys
Cisco
Telephone (Softphone)
Grandstream
microsip (Softphone)
Yealink
Fanvil
Snom
Go to the "System file customization" section
Open the file "/var/spool/cron/crontabs/root" for editing
Add the following code to the end of the file:
Proceed to editing the "modules.conf" file
Add the following code to the end of the file:
Go to editing the file "extensions.conf"
Add the following code to the end of the "extensions.conf" file
Go to the "Dialplan Applications" section, create a new dialplan
Assign an internal number, for example 2200110. Set the code type: "Asterisk Dialplan"
Go to the "Programme Code" tab, insert the following code:
In the application code, describe the contacts to whom you should call. Contacts are listed with a & separator.
Go to the "Modules" - "Dialplan Applications". Create a new dialplan.
Enter the name "Eavesdropping". Specify the "number to call the application", here we will use the template "911XXX" - XXX means all three-digit numeric numbers. In the "Type of code" field, specify "Dialplan Asterisk"
Further functionality you can choose from three options:
It becomes possible to eavesdrop on someone else's conversation, so that neither the operator nor the client will suspect anything
In the tab "Programme code" insert the following code:
ChanSpy(SIP/${EXTEN:3},qw) - note that the application number will be passed as EXTEN. If you dial 911101, the internal number 101 will be dialed. The first three digits are cut off.
If you change the length of the template, then you should adjust this line.
When using PJSIP, the command will look like ChanSpy(PJSIP/${EXTEN:3},qw)
In the tab "Programme code" insert the following code:
The differences are only in the parameters for ChanSpy
In the tab "Programme code" insert the following code:
The differences are only in the parameters for ChanSpy
The function can be useful if there is a need to play an advertising audio file instead of background music. You can assign your own file to each queue.
Go to the section "Telephony" -> "Sound files" -> "Music on hold"
Add media files:
After saving the media file, copy its ID from the browser address bar. For example , in a link like "http://192.168.0.41/admin-cabinet/sound-files/modify/5" the identifier is the number 5.
Go to the "System" -> "System file customization"
Open the file "/etc/asterisk/extensions.conf" for editing
Paste the following code at the end of the file:
According to this example, for the queue with the number "2001", a file with the ID 5 will be played in the background, for the queue "2002", a file with the ID 6
The "Dynamic Queue Agents" application in MikoPBX is a feature designed to enhance the flexibility and efficiency of call center operations.
From time to time there is a need to add and remove employees from the queue. Until now, this was only possible to do through the web interface of the telephone exchange.
In this article I will tell you how to implement the ability to connect and disconnect from a queue by dialing a service extension number.
Create a new queue with a four-digit extension number. For example, 2001. (see documentation “Call Queue”)
Describe the new “Dialplan Application”
Assign a “Extension to call the application” - 999XXXXX, you can redefine the first three digits with your own combination
Code type - “PHP AGI script”
In the "Programme code" tab, paste the following content:
Press "Save settings"!
Dial 99912001 to join queue 2001 .
Dial 99902001 to disconnect from queue 2001.
In some cases, employees should not see the actual phone number of a client. Here is a possible approach to solving this problem: employees will be provided with an alternative number that they can use to call back.
Go to System → System File Customization.
Open the modules.conf configuration file for editing. Set the mode to "Add to end of file".
Connect the module to calculate the hash sum:
Open the extensions.conf configuration file for editing. Set the mode to "Add to end of file".
Define the context for number substitution:
Describe the context with the numbers for which you need to replace the number:
We will provide the opportunity to call back to a replacement number:
OPNsense is a FreeBSD-based operating system designed for creating firewalls and routers. It provides powerful network management tools, including VPN, traffic filtering, monitoring, and load balancing.
OPNSense includes a certification authority (CA) and can issue SSL certificates for the MikoPBX web interface.
First, ensure that the OPNSense certification authority is configured and that the root certificate is installed on the user's workstation.
Generate a certificate: Navigate to your OPNSense server and open the certificate manager:
Issue an internal certificate: Assign a clear name, choose server as the certificate type, specify your internal certification authority as the issuer, and set the certificate validity period in days.
Specify DNS: Enter the DNS configured for MikoPBX.
Save the certificate in OPNSense.
Save the public and private keys: Locate your PBX certificate in the list and click "Download."
Download the public key (1) and private key (2).
Navigate to General Settings -> WEB-Interface.
Open the previously downloaded files using a text editor. Paste the contents into the Web interface fields.
Public Key: Enter the content starting with "BEGIN CERTIFICATE."
Private Key: Enter the content starting with "BEGIN PRIVATE KEY."
Save the settings.
Open the MikoPBX web interface in your browser's incognito mode using an HTTPS connection. Your connection is now secure.
PT1C_cdr is the table containing the call history from the telephony panel version 1 in FreePBX.
Let’s navigate to the FreePBX working directory.
Download the script to convert the MySQL table to SQLite3. If it’s not available, make sure to download it.
Run the conversion script:
The archive with the scripts is available via the provided .
The file master.db, obtained in the previous step, must be transferred to MikoPBX in the directory: /storage/usbdisk1/mikopbx/freepbx-dmp.
Navigate to the MikoPBX working directory:
Prepare the list of files for uploading, specifying the date as "2020-02-07".
Uploading call recordings and converting them to MP3.
Perform a backup of the call history database.
Copy the call history database to the current directory.
Convert the call history to the MikoPBX format. The history in cdr.db will be CLEARED.
Clear the empty recordingfile fields in the database.
There are no call recordings before "2020-02-07". Let’s clear the recordingfile field.
After moving the database file.
Done! You can now check the call history in the web interface.
In the settings you can configure routing. If an employee is not available, the call can be directed to his mobile phone number. This function is not necessary for all cases. For example, clients often ask to turn it off for internal calls.
Go to the “System” section -> “System file customization”
Select the file “/etc/asterisk/extensions.conf” to edit.
Select the “Add to end of file” mode.
Add the code to the second field:
This functionality is convenient for mobile employees. When it is important that the conversation is recorded and recorded on the PBX in the call history. When it is not possible to use a softphone / or "IP-SIM".
Add a new dialplan application (see )
Assign an internal number, for example 2200109
Paste the code into the "Programme Code" tab:
In the browser's address bar, copy the application ID. It will look like "DIALPLAN-APP-6A9902C631C5E7B5AC8F501C559FD678"
Go to the "System file customization" section
Open the file "extensions.conf" for editing
Paste the following code at the end of the file:
here "DIALPLAN-APP-6A9902C631C5E7B5AC8F501C559FD678" is the application ID.
The application will be executed for all incoming calls
It will be possible to enter an extension only if the caller's phone number is filled in the employee card, that is, the number must belong to the employee. This is done for security.
The script is not a complete product, but is open for customization
Now "Dynamic queue agents" application is ready to use .
For the case when an employee has moved away and cannot answer a call, it is convenient to put the agent on pause. For example, an employee dials a special extension number *46 and leaves for lunch.
New calls to the employee will stop coming.
When the employee returns, he dials *46 again and disables the pause. In modern phones, everything can be reduced to pressing a single button.
Go to "Modules" -> "Dialplan Applications"
Create a new dialplan.
Specify the name, as well as the dialplan number (in our case - 2200105). Specify "Dialplan Asterisk" as the code type
Go to the "Programme Code" tab. Paste the following code into the black area:
Go to the "System file customization" section
Open the file "/etc/asterisk/extensions.conf" for editing
Paste the following code at the end of the file: