I've got the following Lua script working in a sense, but the InputCallback never seems to get called while the file is being streamed to the call recipient.  I've tried moving the "vmd start" command and set input callback around a bit, but to no avail.  I'm testing this against a cell phone voice mailbox (Verizon).

freeswitch.consoleLog("info","########################################################\n\n");

number_to_call = argv[1]
message_to_play = "/opt/freeswitch/recordings/messages/" .. argv[2]

voicemail_detected = false;

function onInput(s, type, obj)
    freeswitch.consoleLog("notice","*********** Type?: " .. type .. " *************\n");
    -- freeswitch.consoleLog("notice","*********** VMD?: " .. session:getVariable("vmd_detect") .. " *************\n");

    if(type == "event" and voicemail_detected == false) then
        freeswitch.consoleLog("notice","************ VOICE MAIL/ANSWERING MACHINE DETECTED *************\n");
        voicemail_detected = true;
        return "break";
    end
end

function playbackMessage()
    sleep_time = 1000;
    if(voicemail_detected) then
       sleep_time = 2500;
    end
    -- sleep a second
    session:sleep(sleep_time);
    -- play a file
    session:streamFile(message_to_play);
end

function notify()
    session = freeswitch.Session("{ignore_early_media=true}sofia/gateway/voicenetwork/1" .. number_to_call)



    if(session:ready()) then
        -- answer the call
        session:answer();
        session:setInputCallback("onInput", "");
        session:execute("vmd","start");

        playbackMessage();
        if(voicemail_detected) then
            freeswitch.consoleLog("notice","************ DOING PLAYBACK FOR VOICEMAIL/ANSWERING MACHINE *************\n");
            playbackMessage();
        end

        freeswitch.consoleLog("notice", "********* hanging up session **********\n");
        -- hangup
        session:hangup();
    end
end

notify();

freeswitch.consoleLog("info","########################################################\n\n");

--
Michael De Lorenzo