Skip to content

Commit

Permalink
Update README.md. Closes #1
Browse files Browse the repository at this point in the history
Ignore anonymous incoming calls
  • Loading branch information
serfreeman1337 committed Oct 11, 2020
1 parent 53b0934 commit f8d55fe
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 16 deletions.
92 changes: 81 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,92 @@
Asterisk CRM Connector.
Supports FreePBX v14 integration with [Bitrix24](https://github.com/serfreeman1337/asterlink/blob/master/README_bitrix24.md) and [SuiteCRM](https://github.com/serfreeman1337/asterlink/blob/master/README_suitecrm.md).

## Asterisk
# Asterisk
You need Asterisk 13+.
To monitor how call is going this connector listens for AMI events.

There should be 4 **different** contexts to distinguish calls:
* incoming_context
* outgoing_context
* ext_context - extensions dials from queue, ring group
* dial_context - for originate
* `incoming_context` - context for incoming calls from voip trunk. inbound calls will be registred there
* `outgoing_context` - context for outgoing calls. outbound calls will be registred there
* `ext_context` - extensions dials from queue, ring group, etc. use this context to route incoming calls to your extensions
* `dial_context` - context for originating (click2dial) calls

Default configuration is tested to work with FreePBX v14 and Asterisk v13.

### CallerID Format
Here is configuration for [basic-pbx](https://github.com/asterisk/asterisk/blob/master/configs/basic-pbx/extensions.conf) asterisk dialplan:
```yml
dialplan:
incoming_context:
- DCS-Incoming
outgoing_context:
- Outbound-Dial
ext_context:
- Dial-Users
- DCS-Incoming
dial_context: Long-Distance
```
You see `DCS-Incoming` in `ext_context` because we are dialing **queue** extensions directly from incoming context. (queue memeber config `member => PJSIP/1101` and not `member => Local/1101@Dial-Users` like in freepbx).

## CallerID Format
Connector can format CallerID using regexp. This useful when your VoIP provider doesn't send desired format.

* cid_format - from PBX to CRM
* dial_format - from CRM to PBX
* *expr* - regual expression (use double blackslashes)
* *repl* - replace pattern
* `cid_format` - from PBX to CRM
* `dial_format` - from CRM to PBX
* `expr` - regual expression (use double blackslashes)
* `repl` - replace pattern

If config is set and callerid doesn't matched any of regexp, then call will be ignored.

# CRM Integration
See instructions in the following files:
* [README_bitrix24.md](https://github.com/serfreeman1337/asterlink/blob/master/README_bitrix24.md) - For [Bitrix24](https://www.bitrix24.com/) Integration
* [README_suitecrm.md](https://github.com/serfreeman1337/asterlink/blob/master/README_suitecrm.md) - For [SuiteCRM](https://suitecrm.com/) Integration

# Install
Install asterlink under **/opt/asterlink** folder.
* Create folder /opt/asterlink
```bash
mkdir /opt/asterlink; cd /opt/asterlink
```
* Download binary from releases page
```bash
wget https://github.com/serfreeman1337/asterlink/releases/latest/download/asterlink_x86_64.tar.gz
tar xvf asterlink_x86_64.tar.gz && rm asterlink_x86_64.tar.gz
chmod +x asterlink
```
* Or build it from source (assume you have go installed)
```bash
go get github.com/serfreeman1337/asterlink
go build github.com/serfreeman1337/asterlink
```
* Create configuration file. Use conf.example.yml as example.
```bash
wget https://raw.githubusercontent.com/serfreeman1337/asterlink/master/conf.example.yml
mv conf.example.yml conf.yml
nano conf.yml
```
* Test run
```bash
./asterlink
```

## Startup script example
Create **/etc/systemd/system/asterlink.service** file with following contents:
```
[Unit]
Description=AsterLink Connector
After=freepbx.service
[Install]
WantedBy=multi-user.target
If config is set and callerid doesn't matched any of regexp, then call will be ignored.
[Service]
ExecStart=/bin/sh -c 'exec /opt/asterlink/asterlink >>/opt/asterlink/app.log 2>>/opt/asterlink/err_app.log'
WorkingDirectory=/opt/asterlink
Restart=always
RestartSec=5
```
```bash
systemctl enable asterlink
systemctl start asterlink
```
19 changes: 16 additions & 3 deletions README_suitecrm.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Features:
* Forwarding calls to assigned user.

## Basic setup
First of all, you need to setup V8 API in SuiteCRM. Follow [this](https://docs.suitecrm.com/developer/api/developer-setup-guide/json-api/#_before_you_start_calling_endpoints) guide (The "Before you start calling endpoints" part).

You may get **404 API error**, if you are using SuiteCRM with **php-fcgi**. See this:
https://github.com/salesagility/SuiteCRM/pull/8486

There also may be problems with contact search. See this:
https://github.com/salesagility/SuiteCRM/pull/8492

Log calls for "Calls" module.

* Add new fields for Calls module
Expand All @@ -23,18 +31,22 @@ Log calls for "Calls" module.
| Data Type | Field Name | Display Label | Max Size |
|-----------|------------------------|---------------------|----------|
| TextField | asterlink_ext | Asterisk Extension | 64 |
* Set ***customCode*** for ***duration_hours*** in **custom\modules\Calls\metadata\detailviewdefs.php**:
* Optional: display seconds for call duration in detail view.
Set `customCode` for `duration_hours` in **custom\modules\Calls\metadata\detailviewdefs.php**:
```php
{$fields.duration_hours.value}{$MOD.LBL_HOURS_ABBREV} {$fields.duration_minutes.value}{$MOD.LBL_MINSS_ABBREV} {$fields.asterlink_call_seconds_c.value}{$MOD.LBL_ASTERLINK_CALL_SECONDS} 
```
If this file doesn't exist, click **save & deply** on Calls DetailView layout in studio.
* Update layouts as you want.
* Set **asterlink_ext** in users profiles.
* Set asterlink_ext in users profiles.
* Create new **Client Credentials Client** in Administrator -> OAuth2 Clients and Tokens
* Configure token ID and Secret in **config.yml**
* Do a test run. You should see userids from suitecrm in console.

You need to restart asterlink app evertime you change asterisk_ext for users.

## Click2Dial and Pop up card
* Configure **endpoint_addr** and **endpoint_token** in **config.yml**.
* Configure `endpoint_addr` and `endpoint_token` in **config.yml**. `endpoint_token` is just a secret word to access asterlink endpoint. It must be equal in both **conf.yml** and **config_override.php**.
* Copy [connect/suitecrm/dist/asterlink](https://github.com/serfreeman1337/asterlink/tree/master/connect/suitecrm/dist) folder to ***suitecrm*** directory.
* Add following line to the end of the **custom/modules/logic_hooks.php** file:
```php
Expand All @@ -47,6 +59,7 @@ Log calls for "Calls" module.
$sugar_config['asterlink']['endpoint_ws'] = 'ws://my_endpoint_addr:my_endpoint_port';
```
* Check "***Enable click-to-call for phone numbers Information***" in SuiteCRM System Settings.
Note: SuiteCRM will only enable this for CallerID with begining plus sign.

### Apache2 endpoint proxy
* Enable mod_proxy, mod_proxy_http and mod_proxy_wstunnel.
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ func main() {
}
}

// skip anonymous calls ?
if e["CallerIDNum"] == "<unknown>" {
log.WithFields(log.Fields{"lid": e["Linkedid"]}).Warn("Anonymous CallerID")
return
}

cID, ok := formatNum(e["CallerIDNum"], true)
if !ok {
log.WithFields(log.Fields{"lid": e["Linkedid"], "cid": e["CallerIDNum"]}).Warn("Unknown incoming CallerID")
Expand Down Expand Up @@ -319,9 +325,9 @@ func main() {
return
}

cID, ok := formatNum(e["ConnectedLineNum"], true)
cID, ok := formatNum(e["DestCallerIDNum"], true)
if !ok {
log.WithFields(log.Fields{"lid": e["Linkedid"], "cid": e["ConnectedLineNum"]}).Warn("Unknown outgoing CallerID")
log.WithFields(log.Fields{"lid": e["Linkedid"], "cid": e["DestCallerIDNum"]}).Warn("Unknown outgoing CallerID")
return
}

Expand Down

0 comments on commit f8d55fe

Please sign in to comment.