Merlin magix integration with freepbx as secondary voicemail

Hey y’all,
Thanks for taking a look. I’m trying to use freepbx as secondary voicemail, and have it work the same as main merlin magix voicemail.

I’m using this as reference:
I’ve got 4 regular phone lines coming out of a 016 T/R card into a Wildcard TDM800P. Trying to keep things as simple and reproducible as possible, I’ve really only made two changes: changed FXO port 1 context to [from-magix], and then created the following code in extensions_custom.conf…

;00=VM?, next number is who dialed
;02=internal, next is who dialed, next is who dialing
;03=external, next is empty, next is who dialing
;Flash(),SendDTMF(#53XXXX) Message Waiting Indicater On : #*53XXXX MWI Off
exten => s,1,Answer() ;Have to Answer before magix sends DTMF
;Read() reads DTMF tones into variable. Quits whenever it sees a # sign
;expected pattern is something like: #XX#XXXX#XXXX##
same => n, Read(t) ;throwaway first #
same => n, Read(type)
same => n, Read(dialed)
same => n, Read(dialing)
;same => n, Verbose(1,Type:${type} Dialed:${dialed} Dialing:${dialing})
same => n, ExecIf($[0=${type}]?VoiceMailMain(${dialed}):VoiceMail(${dialing}))
same => n, Verbose(1,from-magix after VMSTATUS: ${VMSTATUS})
same => n, Hangup()

exten => h, 1, Verbose(1,${VMSTATUS} from-magix hungup)
;same => n, Flash
same => n, SendDTMF(#*53${dialing})

I also created one extension for testing in freepbx. So now I can call that extension from my avaya mlx-10dp phone through merlin magix and be prompted by freepbx voicemail system to leave a message… yay! However, I can’t cleanly get the MWI to turn on/off, and haven’t even tried more complex tasks (voicemail callback context).

First: can current code be better/cleaner? Is there a more current integration guide around?

Second, if I take an incoming line and Flash it, then SendDTMF MWI digits, the digits send but hangup doesn’t work - that call gets sent to the main receptionist. Is there a way to flash incoming line, sendDTMF and actually hangup?

Third, it seems like I’ll need to initiate dialing out from freepbx to magix to send dtmf digits, but every Dial command I’ve tried returns: “Caller hung up before dial” in asterisk console. What steps do I need to accomplish in order to send digits to magix? If I haven’t mentioned it here, I haven’t done it, so I currently have no outbound routes, DAHDI channel DIDs, etc., mainly due to ignorance.

I’ve also tried using voicemail external notify: externnotify=/var/lib/asterisk/agi-bin/vmnotify-newvm-mod.php, but would still need to Dial from there (or otherwise send digits to merlin magix).

Finally, is there any information I can provide to make these integration questions more clear?
Thanks again for your time and support!

Asterisk 13.9.1
FreePBX 10.13.66-13
SHMZ release 6.6

I have worked with Avaya products for many years now, including Magix, and the best advice I can give you (other than not to spend too much time on a Merlin Magix) is to focus on the DTMF. As I recall the Merlin will use in band DTMF while the FreePBX has several different options; make sure you are not sending RFC2388. There are some cheap in line DTMF decoders which may be able to assist with troubleshooting.

Thanks to fcd_3 for replying. I played with different ideas before creating a phpagi script. It catches events, then updates the MWI by creating a call file. Been a while since I played with it, here’s the code:

#!/usr/bin/php -q
function dump_event($ecode, $data, $server, $port)
  $msg= date('YmdHis') . ":Received event '$ecode' from $server:$port\n";
  echo $msg;
  $call_file= <<<EOF
Channel: DAHDI/3
Application: SendDTMF
Data: "$mailboxString"
  $fdir= '/home/asterisk/';
  file_put_contents($wf, $call_file);
require "phpagi-asmanager.php";
$as = new AGI_AsteriskManager();
$res = $as->connect("localhost:5038", "xxx", "xxx");
if($res == FALSE) {
	echo "Connection failed.\n";
elseif($res == TRUE){
	echo "Connection established.\n";
$as->add_event_handler('MessageWaiting', 'dump_event');

Hope this helps someone! Let me know if clarification is needed.