Copy / Clone / Duplicate an IVR Script


#1

I needed to Copy an IVR script for my asterisk 1.8.6.0, and did a Google Search for the method. The best hit was a thread in the SwitchVox section that ended with “You can’t do that”. I just HAD to do that, so I figured out a way. As a proper netizen, I then posted the answer where I’d found the problem, but my answer was inappropriate there. So, the moderator removed my post. This post is a recreation (from memory - no undelete on phpBB) of my answer.

The IVR exist in MySQL, not in the asterisk database or the conf files. So, it’s easy to clone/manipulate them. For example, I have an IVR with a complicated set of actions to take during normal business hours. If they want more information, there is an expanded IVR (with the same choices) with more info. Further, after hours there are a third and forth IVR with the same choices, except all EXTENSION are VOICEMAIL. Admittedly, that is only 4 IVR, but I’m Lazy, I guess. If I need to make changes, I’ll make them in the DayTime IVR, and then run trivial commands to copy/modify them to NightTime, List-Day and List-Night.

Create all the IVR you want, using normal procedures (I use FreePBX. It doesn’t matter to this discussion).
Flesh out one of them with all the fancy routing you want/need.

Then, jump on to the console and do some simple MySQL commands.

Find out the ID numbers of the IVR you have created. (You can do this by name with subselects, but this post is for understanding the process, not learning elegant SQL).

su - mysql
mysql
connect asterisk;
select * from ivr;

+--------+----------------+
| ivr_id | displayname    |
+--------+----------------+
|      1 | __install_done |
|      3 | DayTime        |
|      4 | NightTime      |
|      8 | List-Day       |
|      9 | List-Night     |
+--------+----------------+
5 rows in set (0.00 sec)

Delete [if] any destination already exist (only the ID for the subordinate IVR, not the “master”)

delete from ivr_dests where ivr_id in (4, 8, 9);

Copy all the ivr_dests from an ivr to another.

/*                 Destination                                                    Source */
insert into ivr_dests select 4, selection, dest, ivr_ret from ivr_dests where ivr_id = 3;
insert into ivr_dests select 8, selection, dest, ivr_ret from ivr_dests where ivr_id = 3;
insert into ivr_dests select 9, selection, dest, ivr_ret from ivr_dests where ivr_id = 3;

Now, use the Web GUI to modify the destinations if trivial, or use the sql below. I don’t know if a reload is needed or not.

Note: This code replaces the “insert into” code above, but is different only for the Nighttime IVRs, 4 and 9. For them, we change the extensions (Case from-did-direct) to voicemail, otherwise, the dest is left alone.

insert into ivr_dests
  select 4,
         selection,
         case when dest regexp 'from-did-direct,.' = 1
                   then concat('ext-local,vmu', substring(dest, 17))
                   else dest
         end dest,
         ivr_ret
  from ivr_dests
  where ivr_id = 3;

insert into ivr_dests select 8, selection, dest, ivr_ret from ivr_dests where ivr_id = 3;

insert into ivr_dests
  select 9,
         selection,
         case when dest regexp 'from-did-direct,.' = 1
                   then concat('ext-local,vmu', substring(dest, 17))
                   else dest
         end dest,
         ivr_ret
  from ivr_dests
  where ivr_id = 3;

hth

Environment: FreePBX 2.9.0.7, Asterisk 1.8.6.0, Trunk provider CallCentric, Hardware ESXi 4.1 VM with 1 vCPU, 384 MB ram.


#2

You should have said you needed to copy it in FreePBX 2.9.0.7. Essentially you are describing hte workings of FreePBX, not Asterisk.


#3

Interesting comment. As a veteran of over a week of asterisk/freepbx/callcentric manipulations, I certainly don’t know which bits belong where. Obviously, my info didn’t belong on the SwitchVox forum. I saved a copy of it this time. If you know where it belongs, let me know and I’ll be happy to post there. If FreePBX did something like this in their GUI, I’d love to hear about it. As it was, I found that running the SQL seemed to make it do what I needed done, and didn’t appear to hurt anything else. However, as a noob, I’m willing to be corrected.

Are you saying that the MySQL bits are FreePBX and not asterisk? I thought it was asterisk because it was expressed by asterisk code without FreePBX seeming to know about it. Anyway, MY ivr scripts are copied/modified in this way and appear to work.


#4

Asterisk doesn’t come with any production dialplan code, and not even enabled samples using databases. Any limitation imposed by the dialplan on a fresh install comes from the GUI, or other third party code.


#5

Thank you for the helpful information.

I’ve posted the topic in FreePBX, Tips and Tricks. Hopefully, it’s third and final home. freepbx.org/forum/freepbx/ti … ivr-script