I'm trying to run a Python script using "mod_python" in my freeswitch server in order to check a local REDIS db. So far i was able to run the script from the dialplan like this:
<condition field="destination_number" expression="^(.*)$" break="on-true">
<action application="log" data="ORIGIN : ${caller_id_number}"/>
<action application="set" data="did=$1"/>
<action application="log" data="DID = $1"/>
<action application="python" data="test"/>
<action application="bridge" data="sofia/external/$1@10.X.X.1"/>
</condition>
The python script is something like this:
import redis
from datetime import timedelta
import freeswitch
def handler(session, args):
did = session.getVariable("did")
llave = "k"+did
cliente = redis.Redis(host='localhost', port=6379, db=0)
resultado = cliente.get(llave)
if resultado is None:
freeswitch.consoleLog("INFO","DID no esta en cache, agregando a la BD + TTL 10 minutos")
cliente.set(llave,did)
cliente.expire(llave, timedelta(minutes=20))
else:
ttl = cliente.ttl(llave)
freeswitch.consoleLog("INFO","DID en cache, TTL= %s segs\n" % ttl)
freeswitch.consoleLog("INFO","Colgando llamada")
session.hangup("21")
It is working ok. What i need to do is "check/capture" if the call is answered to make changes in the REDIS DB. So far i have tried adding to the script something like this:
if session.ready():
// some work to do in REDIS
else:
// no changes in REDIS DB
without any luck. Is there a way to capture if the call is answered in the python script?