Hola,
Recién estoy probando realizar AGIs con python, primero intenté con la librería pyst, pero no me funcionaba y daba errores, y pues lo intenté con stdin/stdout sin librerías externas, al parecer funcionó mejor pero no del todo.
Al llamar a la extensión del AGI parece que inicia el script, pero esto se cuelga la llamada inmediatamente, esto es lo que sale en el CLI:
-- Accepting AUTHENTICATED call from 192.168.1.88:
> requested format = gsm,
> requested prefs = (),
> actual format = gsm,
> host prefs = (gsm),
> priority = mine
-- Executing [606@from-internal:1] Answer("IAX2/201-916", "") in new stack
-- Executing [606@from-internal:2] AGI("IAX2/201-916", "prueba.py") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/prueba.py
<IAX2/201-916>AGI Tx >> agi_request: prueba.py
<IAX2/201-916>AGI Tx >> agi_channel: IAX2/201-916
<IAX2/201-916>AGI Tx >> agi_language: en
<IAX2/201-916>AGI Tx >> agi_type: IAX2
<IAX2/201-916>AGI Tx >> agi_uniqueid: 1324064280.32
<IAX2/201-916>AGI Tx >> agi_version: 1.8.7.0
<IAX2/201-916>AGI Tx >> agi_callerid: 201
<IAX2/201-916>AGI Tx >> agi_calleridname: device
<IAX2/201-916>AGI Tx >> agi_callingpres: 1
<IAX2/201-916>AGI Tx >> agi_callingani2: 0
<IAX2/201-916>AGI Tx >> agi_callington: 0
<IAX2/201-916>AGI Tx >> agi_callingtns: 0
<IAX2/201-916>AGI Tx >> agi_dnid: 606
<IAX2/201-916>AGI Tx >> agi_rdnis: unknown
<IAX2/201-916>AGI Tx >> agi_context: from-internal
<IAX2/201-916>AGI Tx >> agi_extension: 606
<IAX2/201-916>AGI Tx >> agi_priority: 2
<IAX2/201-916>AGI Tx >> agi_enhanced: 0.0
<IAX2/201-916>AGI Tx >> agi_accountcode:
<IAX2/201-916>AGI Tx >> agi_threadid: -1225081968
<IAX2/201-916>AGI Tx >>
<IAX2/201-916>AGI Rx << ANSWER
<IAX2/201-916>AGI Tx >> 200 result=0
<IAX2/201-916>AGI Rx << STREAM FILE welcome ""
-- Playing 'welcome' (escape_digits=) (sample_offset 0)
-- <IAX2/201-916>AGI Script prueba.py completed, returning 0
-- Executing [606@from-internal:3] Hangup("IAX2/201-916", "") in new stack
== Spawn extension (from-internal, 606, 3) exited non-zero on 'IAX2/201-916'
-- Executing [h@from-internal:1] Macro("IAX2/201-916", "hangupcall") in new stack
-- Executing [s@macro-hangupcall:1] GotoIf("IAX2/201-916", "1?endmixmoncheck") in new stack
-- Goto (macro-hangupcall,s,9)
-- Executing [s@macro-hangupcall:9] NoOp("IAX2/201-916", "End of MIXMON check") in new stack
-- Executing [s@macro-hangupcall:10] GotoIf("IAX2/201-916", "1?nomeetmemon") in new stack
-- Goto (macro-hangupcall,s,15)
-- Executing [s@macro-hangupcall:15] NoOp("IAX2/201-916", "MEETME_RECORDINGFILE=") in new stack
-- Executing [s@macro-hangupcall:16] GotoIf("IAX2/201-916", "1?noautomon") in new stack
-- Goto (macro-hangupcall,s,18)
-- Executing [s@macro-hangupcall:18] NoOp("IAX2/201-916", "TOUCH_MONITOR_OUTPUT=") in new stack
-- Executing [s@macro-hangupcall:19] GotoIf("IAX2/201-916", "1?noautomon2") in new stack
-- Goto (macro-hangupcall,s,25)
-- Executing [s@macro-hangupcall:25] NoOp("IAX2/201-916", "MONITOR_FILENAME=") in new stack
-- Executing [s@macro-hangupcall:26] GotoIf("IAX2/201-916", "1?skiprg") in new stack
-- Goto (macro-hangupcall,s,29)
-- Executing [s@macro-hangupcall:29] GotoIf("IAX2/201-916", "1?skipblkvm") in new stack
-- Goto (macro-hangupcall,s,32)
-- Executing [s@macro-hangupcall:32] GotoIf("IAX2/201-916", "1?theend") in new stack
-- Goto (macro-hangupcall,s,34)
-- Executing [s@macro-hangupcall:34] Hangup("IAX2/201-916", "") in new stack
== Spawn extension (macro-hangupcall, s, 34) exited non-zero on 'IAX2/201-916' in macro 'hangupcall'
== Spawn extension (from-internal, h, 1) exited non-zero on 'IAX2/201-916'
-- Hungup 'IAX2/201-916'
El script solo hace Answer y Stream file, el código es este:
#!/usr/bin/env python
import sys
def prueba():
env = ""
while(env != "\n"):
env = sys.stdin.readline()
sys.stderr.write("ANSWER\n")
sys.stderr.flush()
sys.stdout.write("ANSWER\n")
sys.stdout.flush()
sys.stderr.write("STREAM FILE welcome \"\"\n")
sys.stderr.flush()
sys.stdout.write("STREAM FILE welcome \"\"\n")
sys.stdout.flush()
if __name__ == "__main__":
prueba()
Y está dado de alta correctamente en el extensions_custom.conf (uso elastix):
[from-internal-custom]
;exten => 665,1,Playback(demo-congrats) ; extensions can dial
1234
exten => 665,1,Queue(665)
exten => 665,2,Hangup()
exten => h,1,Hangup()
include => agentlogin
include => conferences
include => calendar-event
include => weather-wakeup
include => custom-agiphp
...
[custom-agiphp]
exten => 606,1,Answer
exten => 606,n,agi(prueba.py)
exten => 606,n,Hangup
No encuentro el problema, ya que el CLI me muestra cómo si todo estuviera correcto, pero no reproduce el archivo y se cuelga la llamada luego luego. Ya verifique rutas y permisos y nada de nada. He verificado que otros agis funcionen (el wakeup) y si funciona, así que creo que no es mala configuración.
¿Alguna sugerencia de que hacer?
Saludo y Gracias!!