计算一个freeswitch呼叫的持续时间,如果大于10秒没有人加入则播放IVR

时间:2014-03-10 03:51:53

标签: python freeswitch

如何计算通话时间? 当用户加入3200并等待10秒但没有人加入时,3200然后我想播放音频文件。

但我如何计算任何想法的持续时间?我试过跟随但它没有工作因为它只在呼叫挂断后触发。但我需要在呼叫开始时启动计数器。


/usr/local/freeswitch/script/wait.py

import os
from freeswitch import *
def hangup_hook(session, what):
    consoleLog("info","hangup hook for %s!!\n\n" % what)
    return
def input_callback(session, what, obj):
    if (what == "dtmf"):
        consoleLog("info", what + " " + obj.digit + "\n")
    else:
        consoleLog("info", what + " " + obj.serialize() + "\n")
    return "pause"

def handler(session, args):
    new_api_obj = API()
    new_api_obj.executeString("pyrun postprocessing " + session.getVariable('caller_id_number'))
    session.answer()
    session.setHangupHook(hangup_hook)
    session.setInputCallback(input_callback)
    session.execute("conference", "$1-${domain_name}@ultrawideband")
    session.hangup()

/usr/local/freeswitch/script/postprocessing.py

import os, sys, time
from freeswitch import *
def runtime(arg1):
    time.sleep(10)
    # is there 2 person or 1 person?
    # if 1 person after 10 second play 
    #session.streamFile("/var/tmp/ivr/sara4.wav")
    # if 2 person after 10 second do nothing
    consoleLog( "info", "Caller: %s hung up 10s ago!\n" % arg1 )

现在,当调用结束时,postprocessing.py正在运行

1 个答案:

答案 0 :(得分:1)

您可以使用 sched_api 命令。

在创建会议之前,请执行以下操作(这是Javascript示例):

    const conferenceName = "test@conference";
    apiExecute("sched_api", `+10 none jsrun /etc/freeswitch/countConferenceMembers.js 
    ${conferenceName }`);

countConferenceMembers.js 脚本中检查会议成员计数。如果小于2,请播放声音,然后挂断所有人。

    const conferenceName = argv[0];
    const count = apiExecute("conference", `${conferenceName } count`);
    if (Number(count) < 2) { 
        apiExecute("conference", `${conferenceName} play SOUND_FILE_PATH`)
        apiExecute("conference", `${conferenceName} hup all`)
    }

Freeswitch命令 [https://freeswitch.org/confluence/display/FREESWITCH/mod_commands]

Freeswitch mod_conference [https://freeswitch.org/confluence/display/FREESWITCH/mod_conference]