From 14eb04301adbe36fe08075b9635759605381bddb Mon Sep 17 00:00:00 2001 From: Luis Rodriguez Date: Mon, 8 Apr 2024 13:21:01 +0200 Subject: [PATCH] [MIG] asterisk_click2dial: phone icon funcionality in the top menu bar --- asterisk_click2dial/README.rst | 81 ++++++++++++++ asterisk_click2dial/__manifest__.py | 2 + .../demo/asterisk_click2dial_demo.xml | 2 +- asterisk_click2dial/models/asterisk_server.py | 20 ++-- asterisk_click2dial/readme/CONFIGURE.md | 10 ++ asterisk_click2dial/readme/USAGE.md | 58 ++++++++++ .../static/description/index.html | 102 ++++++++++++++++-- .../asterisk_click2dial.esm.js | 98 +++++++++++++++++ .../asterisk_click2dial.xml | 13 +++ 9 files changed, 366 insertions(+), 20 deletions(-) create mode 100644 asterisk_click2dial/readme/CONFIGURE.md create mode 100644 asterisk_click2dial/readme/USAGE.md create mode 100644 asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.esm.js create mode 100644 asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.xml diff --git a/asterisk_click2dial/README.rst b/asterisk_click2dial/README.rst index d6f051acf..7c56ff845 100644 --- a/asterisk_click2dial/README.rst +++ b/asterisk_click2dial/README.rst @@ -96,6 +96,87 @@ of Akretion's Web site. .. contents:: :local: +Configuration +============= + +To configure this module, you need to: + +#. Go to the user data, go to "Telephony" page and set "Resource Name" +with the name you want(can be the same as Internal Number when channel +type is SIP) and "Internal Number" with the user's phone number. Also +check that the asterisk channel type is PJSIP if the user has a regular +IP phone. + +#. Go to the asterisk server and set the ip address and port where the +asterisk server is configured and set the ARI login and ARI password +field with the username and password defined in the asterisk +configuration file ari.conf. You can edit the endpoint configuration, to +allow calls, in the asterisk configuration file pjsip.conf. You also can +see all the asterisk servers configured going to the menu entry in +Settings -> Technical -> Asterisk Servers. + +Usage +===== + +The technical name of this module is **asterisk_click2dial**, but this +module implements much more than a simple *click2dial* ! This module +adds 3 functionalities: + +1. It adds a *Dial* button in the partner form view so that users can + directly dial a phone number through Asterisk. This feature is + usually known as *click2dial*. Here is how it works : + + - In Odoo, the user clicks on the *Dial* button next to a phone + number field in the partner form view (or any form view with a + phone number). + - Odoo connects to the Asterisk Manager Interface and Asterisk makes + the user's phone ring. + - The user answers his own phone (if he doesn't, the process stops + here). + - Asterisk dials the phone number found in Odoo in place of the + user. + - If the remote party answers, the user can talk to his + correspondent. + +2. It adds the ability to show the name of the calling party on the + screen of your IP phone on incoming phone calls if the presented + phone number is present in the partner/leads/employees/... of Odoo. + Here is how it works: + + - On incoming phone calls, the Asterisk dialplan executes an AGI + script **set_name_incoming_timeout.sh**. + - The *set_name_incoming_timeout.sh* script calls the + *set_name_agi.py* script with a short timeout. + - The *set_name_agi.py* script will make an XML-RPC request on the + Odoo server to try to find the name of the person corresponding to + the phone number presented by the calling party. + - If it finds the name, it is set as the CallerID name of the call, + so as to be presented on the IP phone of the user. + + It also works on outgoing calls, so as to display the name of the + callee on the SIP phone of the caller. For that, you should use the + script *set_name_outgoing_timeout.sh*. + +3. It adds a phone icon (*Open Caller*) in the top menu bar to get the + partner/lead/candidate/event registrations corresponding to the + calling party in one click. Here is how it works : + + - When the user clicks on the phone icon, Odoo sends a query to the + Asterisk Manager Interface to get a list of the current phone + calls. + - If it finds a phone call involving the user's phone, it gets the + phone number of the calling party. + - It searches the phone number of the calling party in the + Partners/Leads/Candidates/Event Registrations of Odoo. If a record + matches, it takes you to the form view of this record. If no + record matchs, it opens a wizard which proposes to create a new + Partner with the presented phone number as *Phone* or *Mobile* + number or update an existing Partner. + + It is possible to get a pop-up of the record corresponding to the + calling party without any action from the user via the module + *base_phone_popup*. + Bug Tracker =========== diff --git a/asterisk_click2dial/__manifest__.py b/asterisk_click2dial/__manifest__.py index e5e9bfeea..ebaedab7b 100644 --- a/asterisk_click2dial/__manifest__.py +++ b/asterisk_click2dial/__manifest__.py @@ -26,6 +26,8 @@ "assets": { "web.assets_backend": [ "asterisk_click2dial/static/src/scss/*.scss", + "asterisk_click2dial/static/src/components/**/*.js", + "asterisk_click2dial/static/src/components/**/*.xml", ], }, } diff --git a/asterisk_click2dial/demo/asterisk_click2dial_demo.xml b/asterisk_click2dial/demo/asterisk_click2dial_demo.xml index f0921499f..37db906c1 100644 --- a/asterisk_click2dial/demo/asterisk_click2dial_demo.xml +++ b/asterisk_click2dial/demo/asterisk_click2dial_demo.xml @@ -9,7 +9,7 @@ Akretion Asterisk IPBX - asterisk.akretion.com + localhost odoo mypassword from-internal diff --git a/asterisk_click2dial/models/asterisk_server.py b/asterisk_click2dial/models/asterisk_server.py index 5f1175b93..968adff4b 100644 --- a/asterisk_click2dial/models/asterisk_server.py +++ b/asterisk_click2dial/models/asterisk_server.py @@ -26,7 +26,7 @@ class AsteriskServer(models.Model): port = fields.Integer( string="Port", required=True, - default=5038, + default=8088, help="TCP port on which the Asterisk REST Interface listens. " "Defined in /etc/asterisk/ari.conf on Asterisk.", ) @@ -167,12 +167,16 @@ def test_ari_connection(self): raise UserError( _("Connection Test Failed! HTTP error code: %s" % res.status_code) ) - raise UserError( - _( - "Connection Test Successfull! Odoo can successfully login to " - "the Asterisk Manager Interface." - ) - ) + + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "type": "success", + "message": _("Your request has been successfully sent"), + "next": {"type": "ir.actions.act_window_close"}, + }, + } @api.model def _get_calling_number_from_channel(self, chan, user): @@ -208,9 +212,7 @@ def _get_calling_number(self): ) return False list_chan = res_req.json() - from pprint import pprint - pprint(list_chan) _logger.debug("Result of Status ARI request:") _logger.debug(pformat(list_chan)) for chan in list_chan: diff --git a/asterisk_click2dial/readme/CONFIGURE.md b/asterisk_click2dial/readme/CONFIGURE.md new file mode 100644 index 000000000..30211a9fc --- /dev/null +++ b/asterisk_click2dial/readme/CONFIGURE.md @@ -0,0 +1,10 @@ +To configure this module, you need to: + +#. Go to the user data, go to "Telephony" page and set "Resource Name" with the name you want(can be the same as Internal Number when channel type is SIP) + and "Internal Number" with the user's phone number. Also check that the asterisk channel type is PJSIP if the user has a regular IP phone. + +#. Go to the asterisk server and set the ip address and port where the asterisk server is configured and set the ARI login and ARI password field with + the username and password defined in the asterisk configuration file ari.conf. You can edit the endpoint configuration, to allow calls, + in the asterisk configuration file pjsip.conf. You also can see all the asterisk servers configured going to the menu entry + in Settings -> Technical -> Asterisk Servers. + diff --git a/asterisk_click2dial/readme/USAGE.md b/asterisk_click2dial/readme/USAGE.md new file mode 100644 index 000000000..3ade49b60 --- /dev/null +++ b/asterisk_click2dial/readme/USAGE.md @@ -0,0 +1,58 @@ +The technical name of this module is **asterisk_click2dial**, but this +module implements much more than a simple *click2dial* ! This module +adds 3 functionalities: + +1. It adds a *Dial* button in the partner form view so that users can + directly dial a phone number through Asterisk. This feature is + usually known as *click2dial*. Here is how it works : + + - In Odoo, the user clicks on the *Dial* button next to a phone + number field in the partner form view (or any form view with a + phone number). + - Odoo connects to the Asterisk Manager Interface and Asterisk makes + the user's phone ring. + - The user answers his own phone (if he doesn't, the process stops + here). + - Asterisk dials the phone number found in Odoo in place of the + user. + - If the remote party answers, the user can talk to his + correspondent. + +2. It adds the ability to show the name of the calling party on the + screen of your IP phone on incoming phone calls if the presented + phone number is present in the partner/leads/employees/... of Odoo. + Here is how it works: + + - On incoming phone calls, the Asterisk dialplan executes an AGI + script **set_name_incoming_timeout.sh**. + - The *set_name_incoming_timeout.sh* script calls the + *set_name_agi.py* script with a short timeout. + - The *set_name_agi.py* script will make an XML-RPC request on the + Odoo server to try to find the name of the person corresponding to + the phone number presented by the calling party. + - If it finds the name, it is set as the CallerID name of the call, + so as to be presented on the IP phone of the user. + + It also works on outgoing calls, so as to display the name of the + callee on the SIP phone of the caller. For that, you should use the + script *set_name_outgoing_timeout.sh*. + +3. It adds a phone icon (*Open Caller*) in the top menu bar to get the + partner/lead/candidate/event registrations corresponding to the + calling party in one click. Here is how it works : + + - When the user clicks on the phone icon, Odoo sends a query to the + Asterisk Manager Interface to get a list of the current phone + calls. + - If it finds a phone call involving the user's phone, it gets the + phone number of the calling party. + - It searches the phone number of the calling party in the + Partners/Leads/Candidates/Event Registrations of Odoo. If a record + matches, it takes you to the form view of this record. If no + record matchs, it opens a wizard which proposes to create a new + Partner with the presented phone number as *Phone* or *Mobile* + number or update an existing Partner. + + It is possible to get a pop-up of the record corresponding to the + calling party without any action from the user via the module + *base_phone_popup*. diff --git a/asterisk_click2dial/static/description/index.html b/asterisk_click2dial/static/description/index.html index 5fc76cd7b..f1db732ab 100644 --- a/asterisk_click2dial/static/description/index.html +++ b/asterisk_click2dial/static/description/index.html @@ -437,17 +437,99 @@

Asterisk connector

Table of contents

+
+

Configuration

+

To configure this module, you need to:

+

#. Go to the user data, go to “Telephony” page and set “Resource Name” +with the name you want(can be the same as Internal Number when channel +type is SIP) and “Internal Number” with the user’s phone number. Also +check that the asterisk channel type is PJSIP if the user has a regular +IP phone.

+

#. Go to the asterisk server and set the ip address and port where the +asterisk server is configured and set the ARI login and ARI password +field with the username and password defined in the asterisk +configuration file ari.conf. You can edit the endpoint configuration, to +allow calls, in the asterisk configuration file pjsip.conf. You also can +see all the asterisk servers configured going to the menu entry in +Settings -> Technical -> Asterisk Servers.

+
+
+

Usage

+

The technical name of this module is asterisk_click2dial, but this +module implements much more than a simple click2dial ! This module +adds 3 functionalities:

+
    +
  1. It adds a Dial button in the partner form view so that users can +directly dial a phone number through Asterisk. This feature is +usually known as click2dial. Here is how it works :

    +
      +
    • In Odoo, the user clicks on the Dial button next to a phone +number field in the partner form view (or any form view with a +phone number).
    • +
    • Odoo connects to the Asterisk Manager Interface and Asterisk makes +the user’s phone ring.
    • +
    • The user answers his own phone (if he doesn’t, the process stops +here).
    • +
    • Asterisk dials the phone number found in Odoo in place of the +user.
    • +
    • If the remote party answers, the user can talk to his +correspondent.
    • +
    +
  2. +
  3. It adds the ability to show the name of the calling party on the +screen of your IP phone on incoming phone calls if the presented +phone number is present in the partner/leads/employees/… of Odoo. +Here is how it works:

    +
      +
    • On incoming phone calls, the Asterisk dialplan executes an AGI +script set_name_incoming_timeout.sh.
    • +
    • The set_name_incoming_timeout.sh script calls the +set_name_agi.py script with a short timeout.
    • +
    • The set_name_agi.py script will make an XML-RPC request on the +Odoo server to try to find the name of the person corresponding to +the phone number presented by the calling party.
    • +
    • If it finds the name, it is set as the CallerID name of the call, +so as to be presented on the IP phone of the user.
    • +
    +

    It also works on outgoing calls, so as to display the name of the +callee on the SIP phone of the caller. For that, you should use the +script set_name_outgoing_timeout.sh.

    +
  4. +
  5. It adds a phone icon (Open Caller) in the top menu bar to get the +partner/lead/candidate/event registrations corresponding to the +calling party in one click. Here is how it works :

    +
      +
    • When the user clicks on the phone icon, Odoo sends a query to the +Asterisk Manager Interface to get a list of the current phone +calls.
    • +
    • If it finds a phone call involving the user’s phone, it gets the +phone number of the calling party.
    • +
    • It searches the phone number of the calling party in the +Partners/Leads/Candidates/Event Registrations of Odoo. If a record +matches, it takes you to the form view of this record. If no +record matchs, it opens a wizard which proposes to create a new +Partner with the presented phone number as Phone or Mobile +number or update an existing Partner.
    • +
    +

    It is possible to get a pop-up of the record corresponding to the +calling party without any action from the user via the module +base_phone_popup.

    +
  6. +
+
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -455,21 +537,21 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Akretion
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose diff --git a/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.esm.js b/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.esm.js new file mode 100644 index 000000000..4b18171e6 --- /dev/null +++ b/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.esm.js @@ -0,0 +1,98 @@ +/** @odoo-module **/ + +/* + Copyright 2024 Dixmit + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +*/ + +import {Component} from "@odoo/owl"; +import {_t} from "@web/core/l10n/translation"; +import {registry} from "@web/core/registry"; +import {useService} from "@web/core/utils/hooks"; + +const systrayRegistry = registry.category("systray"); + +export class Click2DialSystray extends Component { + setup() { + this.rpc = useService("rpc"); + this.action = useService("action"); + this.notification = useService("notification"); + this.user = useService("user"); + } + + // This._rpc({ + // model: record.model, + // method: ev.data.record_action, + // args: [[record.res_id]], + // context: ev.data.context, + // }).then(function (action) { + // self.trigger_up("do_action", { + // action: action, + // }); + // }); + + async onOpenCaller() { + // Var session = require('web.session'); + + const r = await this.rpc("/asterisk_click2dial/get_record_from_my_channel", { + context: this.user.context, + }); + if (r === false) { + this.notification.add( + _t( + "Calling party number not retreived from IPBX or IPBX unreachable by Odoo" + ), + { + title: _t("IPBX error"), + } + ); + } else if (typeof r === "string" && isNaN(r)) { + this.notification.add(_t("The calling number is not a phone number!"), { + title: r, + }); + } else if (typeof r === "string") { + var action = { + name: _t("Number Not Found"), + type: "ir.actions.act_window", + res_model: "number.not.found", + view_mode: "form", + views: [[false, "form"]], + target: "new", + context: {default_calling_number: r}, + }; + this.action.doAction(action); + } else if (typeof r === "object" && r.length === 3) { + this.notification.add( + _t("Moving to form view of %s (%s ID %s)", r[2], r[0], r[1]), + { + title: _t("On the phone with '%s'", r[2]), + } + ); + var action_suc = { + type: "ir.actions.act_window", + res_model: r[0], + res_id: r[1], + view_mode: "form,tree", + views: [[false, "form"]], + /* If you want to make it work with the 'web' module + of Odoo Enterprise edition, you have to change the line + target: 'current', + to: + target: 'new', + If you want to use target: 'current', with web/enterprise, + you have to reload the Web page just after */ + target: "current", + context: {}, + }; + this.action.doAction(action_suc); + } + } +} + +Click2DialSystray.template = "asterisk_click2dial.Click2DialSystray"; + +export const systrayItem = {Component: Click2DialSystray}; + +systrayRegistry.add("asterisk_click2dial.Click2DialSystray", systrayItem, { + sequence: 99, +}); diff --git a/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.xml b/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.xml new file mode 100644 index 000000000..9d43de180 --- /dev/null +++ b/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.xml @@ -0,0 +1,13 @@ + + + + +

+ +