Skip to main content
All CollectionsGetting Started
The Agent middleware
The Agent middleware

Instructions for installing an intermediate layer between Odoo and Asterisk.

Max Li avatar
Written by Max Li
Updated over 3 months ago

Introduction

The Agent is a special middleware that does the following:

  • Sends the required Asterisk AMI events and call recordings to Odoo.

  • Receives from Odoo Asterisk AMI Actions and sends them to Asterisk.

  • Implements billing function.

  • Protects Asterisk from SIP attacks (optionally, not enabled by default as many systems use alternative fail2ban system).

Requirements

The Agent is distributed as a docker image so the following applications must be installed:

  • docker

  • docker-compose

Do you want expert help to get your Asterisk PBX started on the right foot?

Save time and feel confident you are set up for long-term success with Asterisk PBX Implementation. Our experts will work as an extension of your team to ensure your telephony program is correctly set up and delivering value for your business.

AMI account configuration

Prepare an Asterisk Manager Interface (AMI) account to allow the Agent to connect to Asterisk. Vanilla Asterisk requires editing the manager.conf file, which is usually found in /etc/asterisk.

A sample configuration is provided below, which lets the Agent to connect to your Asterisk server AMI port (usually 5038) using the login asterisk_plus_agent with the password odoo.

manager.conf:

[general]
enabled = yes
webenabled = no
port = 5038
bindaddr = 127.0.0.1

[asterisk_plus_agent]
secret=odoo
allowmultiplelogin=no
displayconnects = yes
read=call,dialplan,security,user
write=originate,system,message
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.255

Set you own password!

Asterisk-based distributions such as FreePBX offer a web GUI interface for managing your AMI users.

Make sure that you applied new configuration by checking the Asterisk console:

manager show user asterisk_plus_agent

Next, configure the AMI settings in Odoo.

AMI Settings

In PBX -> Settings -> Server menu configure the AMI settings as shown on the screenshot. The only required fields are AMI access fields.

Running the Agent

The Agent is distributed in a docker image. The Agent connection procedure is automatic. You just point the Agent to your Odoo instance by its URL and the magic happens. But this can happen only one time. After the Agent is connected successfully the automatic Agent initialization procedure is closed (see below how to do it again).

So all you need to do is just run the Agent from the docker image.

Here is a compose file to run it.

version: '3.2'
services:
agent:
init: true
image: odoopbx/agent:latest
restart: unless-stopped
command: https://your.odoo.server
volumes:
- srv:/srv
# To access recordings and upload them to Odoo.
- /var/spool/asterisk:/var/spool/asterisk
privileged: true # If SIP security is enabled.
network_mode: host
environment:
- TZ=Europe/London
volumes:
srv:

Change https://your.odoo.server to your Odoo server URL. Make sure you use the proper scheme (http or https).

Make sure you specify the correct Agent version (instead of latest) that corresponds to your asterisk_plus module version. The version is displayed in PBX -> Settings -> General menu or on module's __manifest__.py file.

Now you should be able to Ping the Agent and Asterisk from Odoo Server's form.

Troubleshooting

Cannot login into Asterisk AMI

After the AMI account is created, you need to make sure that it’s updated inside Asterisk configuration. Open the Asterisk console using asterisk -r as root and see if the Odoo manager user is available.

If you don’t see the user, maybe the AMI configuration file hasn’t been read by Asterisk after being modified. This can be solved by running inside the Asterisk console the command core reload.

No docker init: true parameter

If you cannot run the above compose file due to init parameter error just remove it.

Agent connection re-initialization

Agent lost its configuration

If you run the Agent and get the error "Initialize error: Agent is already initialized" that means your docker container and volume were destroyed and the Agent configuration file was lost. To fix it you have to permit the initialization procedure as shown below.

After that run the Agent again.

Re-connect to another Odoo instance or URL

If you change your Odoo server or change your Odoo URL you need to the Agent re-connection. For this you must permit the initialization as described above, and also tell the Agent to start the initialization process by specifying the --init flag in its run command like show below:

agent:
command: --init https://your.odoo.server

Then you should apply the configuration:

docker-compose up agent

Make sure that Agent is reconnected, then stop it (CTRL+C), then edit your docker-compose.yml and remove the --init flag and again apply it:

docker-compose up -d agent
# Check the logs:
docker-compose logs agent

Did this answer your question?