README.md 2.73 KB
Newer Older
Citronalco's avatar
Citronalco committed
1
2
# CardDAV-to-Asterisk import

Citronalco's avatar
Citronalco committed
3
This script reads all contacts from a CardDAV address book and puts them into Asterisk's internal caller id database.
Citronalco's avatar
Citronalco committed
4
5
6
That way Asterisk can show a caller's name instead of just the number.

If there's already an entry in Asterisk's caller database for a specific number, this script updates the number with the new name.
Citronalco's avatar
Citronalco committed
7

Bernhard Geier's avatar
Bernhard Geier committed
8
So far I have run this script successfully with OwnCloud 9 to Nextcloud 21 and DAViCal 1.1.10.
Citronalco's avatar
Citronalco committed
9

Citronalco's avatar
Citronalco committed
10
### Requirements
Citronalco's avatar
Citronalco committed
11
12
13
14
* Python 3
* Additional Python 3 modules: requests, vobjects, panoramisk, lxml
  (Install in Debian/Ubuntu/Mint: `apt-get install python3-requests python3-vobject python3-panoramisk python3-lxml`)

Citronalco's avatar
Citronalco committed
15

Citronalco's avatar
Citronalco committed
16
### Usage
Citronalco's avatar
Citronalco committed
17

Citronalco's avatar
Citronalco committed
18
#### Configuration
Citronalco's avatar
Citronalco committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

1. This script uses Asterisk Manager Interface (AMI) to write to the caller id database, so you need to set up an user with "write" permissions to "system":
To add such an user, create a file `/etc/asterisk/manager.d/carddav2asterisk.conf` like this:

        [carddavimport]
        secret = TopSecret
        permit = 127.0.0.1/255.255.255.0
        write = system
   After creating the file reload Asterisk.


2. Create an ini file like this (you may use the included `example.ini` as a starting point):

        [ami]
        user = carddavimport
        pass = TopSecret
        host = localhost
        port = 5038

        [carddav]
        url = https://nextcloud.example.com/remote.php/dav/addressbooks/users/russmeyer/contacts/
        user = russmeyer
        pass = Evelyn1928

        [phone]
        nationalprefix = 0049
        domesticprefix = 089

   The **[ami]** section must contain the connection parameters to Asterisk Manager Interface.

   The **[carddav]** section must contain the connection parameters to your CardDAV server.

   The **[phone]** section is optional. You may use this to clean up the phone numbers before they get written into Asterisk's database.
   Set ***nationalprefix*** to your national prefix to _remove_ it from phone numbers.
   Set ***domesticprefix*** to your local area code to _add_ it to phone numbers without domestic prefix.
   If in doubt simply omit the **[phone]** section.


Bernhard Geier's avatar
Bernhard Geier committed
57
3. If you haven't configured CID lookup (means: "Caller ID lookup", so that your phone shows the callers' names instead of their phone numbers) in Asterisk yet, you may want to add something like this somewhere at the beginning of your dialplan in `extensions.conf`:
Citronalco's avatar
Citronalco committed
58
``exten => <yourExtension>,n,Set(CALLERID(name)=${IF(${DB_EXISTS(cidname/${CALLERID(num)})}?${DB(cidname/${CALLERID(num)})}:${CALLERID(name)})})``
Citronalco's avatar
Citronalco committed
59

Citronalco's avatar
Citronalco committed
60

Citronalco's avatar
Citronalco committed
61
#### How to run the script
Citronalco's avatar
Citronalco committed
62
63
64
65
66
67
``./carddav2asterisk.py [--no-update] <ini file>``

**Example:**
``./carddav2asterisk.py example.ini``

If you use the `--no-update` switch, the script will not write anything to Asterisk but only show what would be done.
Citronalco's avatar
Citronalco committed
68