I've moved this here from the RobsList? page.

Bugs

Stuff that is broken with my current implementation:

  • Should be using handler=file to serve js and css - remove .htaccess hack.
  • Inline the gif's - they're 50 bytes. MUCH faster to have them defined in the document itself.

Operational Issues

This is now in production.. Issues:

  • Far too easy to accidently create duplicates. There needs to be a sanity check on the GUI if you try to add an entry that already exists. Possibly mark the exchange as used in the 'area' dropdown box, and just not add them. Let them remove them from the inuse group before they can be added elsewhhere.

Whiteboarding the AGIs

cidroute.agi

  • Grab the CID number (== $cid)
    • If unsset($cid) exit (no CID, bad luck..)
  • Connect to DB
  • select dest from cidroute_override where cid = $cid
    • If isset($dest) agi->goto($dest)
  • select dest from cidroute_matches where min_numb >= $cid and max_numb <= $cid
    • if isset($dest) agi->goto($dest)
  • exit (it didn't match, continue on..)

cidoverride.agi

  • Grab the ID of this call.
  • Get the previous calls CallerID (DB->Exten/CallTrace)
  • Check to make sure it's not an internal call
  • Say "The previous call from (number) was not found/was found in (tts->localarea)
  • Say "This call would be sent to (tts->cidroute_matches.name)/would be ignored"
  • Say "To update this, press 1."
  • If 1, then:
    • If found in an existing group,
      • prompt to send all numbers in that group to the destination selected
      • If yes, say number range
    • Say "Please select the destination from the following"
    • If count(cidroute_dests.name) > 8
      • Say 'More than 10 destinations. Press * and # to forward and back 10'
    • Say 'You may key the number at any time'
    • Read out all the names
    • Loop if needed for more than 10
    • Read number
    • Now we have a dest.
    • If they're picking a range, update cid_matches
    • If they're picking a number, update cid_override
    • Say Update Complete, Thank you, goodbye

Description

Stuff I _am_ doing is CID based routing, aka caller location routing. The idea is that you have a huge list of exchanges, phone number prefixes, and locations.

I've been thinking of various ways to present this.

The current way I'm thinking of is Ajaxing this. When you select the Country, it propogates the State and Area Code boxes. Selecting either one of those propagates the Region. The reason this may cause grief is that some area codes in Australia span states. I think this is probably the only country that does this.

Country:  [au - Australia]    (db -> cidroute_country (isocode, name))
State: [QLD]  (db -> cidroute_exchanges [see commit] col 'state' where country=cidroute_country.isocode)
Region: [Gladstone] (db -> cidroute_exchanges previous query + region='gladstone')
Exchanges [...about 12 of them in a multi-select box...]

Now. If I'm _really_ clever, I'd like some way to have the Exchanges select box somehow signify the exchange is already marked in use by an existing dest.

cidroute main page:

                                  Add Destination
                                  Dest 1
                                  Dest 2
                                  Dest 3
                                  Manage Overrides
Managing Dest 1

Country [au]
State [QLD]
Area Code [07]
Region [Gladstone]
Exchanges[
   au/QLD/Gladstone/Gladstone (In Use - Dest 1)
   au/QLD/Gladstone/Tannum Sands (749723000-749723999)
   au/QLD/Gladstone/Calliope (In Use - Dest 2)
   au/QLD/Gladstone/Biloela (In Use - Dest 2)
]

(Add Button)

Currently Selected Exchanges [
   au/QLD/Gladstone/Gladstone (749724000-749724999)
..various others..
..possibly many MANY lines here..
]

(Remove Button)

handy things - an 'Add' button next to 'Region', 'Area Code' or 'State' that adds ALL the matches from the DB into currently selected. 'Remove' might be a bit dangerous. If someone spends 4 hours painfully selecting a swath of exchanges and then accidently clicks on 'remove' next to state, it'll blow away all their changes.

Overrides. For things like regular customers that call from a Mobile/Cell phone, you need a way to automatically route to their preferred destination. So there needs to be an cidroute_overrides database, probably just (cid, dest).

On the subject of Overrides, there also needs to be a feature code 'The last call that came in should have gone somewhere else' .. which will need a way to SAY the destination.. Festival, or record the names yourself?

This probably means a new select box on the page, too:

Specifically selected CID's:[
   0402077XXX
   ...
]

I think it's safer to NOT let people remove stuff in huge chunks. The Currently Selected box should allow you to multi-select and click remove though.

Stuff this could be reasonably easily hacked to do - is stuff like #54 -- Did TryExten? actually make it into Asterisk 1.4?

Database Defintions:

This table is used by the AGI to actually match. It's propogated by the web interface.

CREATE TABLE IF NOT EXISTS cidroute_matches (
  country varchar(2) NOT NULL default '',
  areacode int(11) unsigned NOT NULL,
  min_numb int(11) unsigned NOT NULL,
  max_numb int(11) unsigned NOT NULL,
  destid int(11) unsigned NOT NULL default 0,
  KEY idx_country (country),
  KEY idx_numb (min_numb,max_numb) )

destid links to this, which is just a display of the available maps. Be aware that SQLlite does auto_increment as autoincrememt, I believe.

CREATE TABLE IF NOT EXISTS cidroute_dests (
   destid int not null auto_increment,    
   name varchar(50) NOT NULL default '',    
   dest varchar(50) NOT NULL default '',    
   primary key (destid) 
);

This table contains the stuff to search on, and the actual numbers to match. It's propogated on install.

CREATE TABLE IF NOT EXISTS cidroute_cidlist (
  country varchar(2) NOT NULL default '',
  state varchar(10) NOT NULL default '',
  region varchar(50) NOT NULL default '',
  localarea varchar(50) NOT NULL default '',
  areacode int(11) unsigned NOT NULL,
  min_numb int(11) unsigned NOT NULL,
  max_numb int(11) unsigned NOT NULL,
  postcode varchar(12) default '',
  KEY idx_country (country),
  KEY idx_numb (min_numb,max_numb)

This table lets users specify an override, the AGI will check this database first before searching cidroute_matches. Should be a feature code to update this, as well as manageable through the GUI.

CREATE TABLE IF NOT EXISTS cidroute_override (
  name varchar(20) NOT NULL default '',
  number int(11) unsigned NOT NULL,
  dest varchar(12) default ''

There's also a cidroute_config table. When you enable CIDrouting on a trunk, it propogates that. This is used when generating the dialplan.