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.