2017-05-18 4 views
1

J'ai script suivant AGI test_agi.py: Ce script faire la vérification est appelé le numéro est vraiment numéro ou ne pas utiliser la demande HLR (API)Comment configurer une variable AGI en Python?

import urllib.request 
import json 
from pyagi.pyagi import AGI 
agi = AGI() 

dst = agi.env["agi_dnid"] 

url = 'https://www.hlrlookup.com/api/hlr/?apikey=blabla&password=blabla&personalcache=5&msisdn=' + dst 

req = urllib.request.Request(url) 
r = urllib.request.urlopen(req).read() 
cont = json.loads(r) 


live = cont["error_text"] 
agi.set_variable('live_dst',live) 

Et avoir une extension en astérisque:

[HLR_check] 
exten => _XXXXXX.,1,Set(fname=${UNIQUEID}) 
exten => _XXXXXX.,2,AGI(/root/hlr/test_agi.py) 
exten => _XXXXXX.,3,NoOp(${live_dst}) 
exten => _XXXXXX.,4,GoToIf($["${live_dst}" != "Live"]?6:5) 
exten => _XXXXXX.,5,GoTo(agiexten,${EXTEN},1) 
exten => _XXXXXX.,6,Hangup(42) 
same => n,Hangup(42) 

Après appel je vois dans agi déboguer:

[May 18 09:02:17] VERBOSE[8194][C-00048437] netsock2.c: == Using SIP RTP CoS mark 5 
[May 18 09:02:17] VERBOSE[11945][C-00048437] pbx.c:  -- Executing [[email protected]_check:1] Set("SIP/CC-000429e6", "fname=1495098137.288333") in new stack 
[May 18 09:02:17] VERBOSE[11945][C-00048437] pbx.c:  -- Executing [[email protected]_check:2] AGI("SIP/CC-000429e6", "/root/hlr/test_agi.py") in new stack 
[May 18 09:02:17] VERBOSE[11945][C-00048437] res_agi.c:  -- Launched AGI Script /root/hlr/test_agi.py 
[May 18 09:02:17] VERBOSE[11945][C-00048437] res_agi.c:  -- <SIP/CC-000429e6>AGI Script /root/hlr/test_agi.py completed, returning 0 
[May 18 09:02:17] VERBOSE[11945][C-00048437] pbx.c:  -- Executing [[email protected]_check:3] NoOp("SIP/CC-000429e6", "") in new stack 

SO! Agi retourné 0. Je veux faire vérifier - agi doit me retourner la valeur de la variable 'live_dst' et je veux faire appel si live_dst = Live et Hangup appel si live_dst! = Live

Répondre

0

Utilisez agi debug, vous verrez ce que votre script faire.

La plupart des astérisques n'ont tout simplement pas la permission de script et script ne rien faire.

Pour activer l'utilisation AGI de débogage

asterisk -r 
agi set debug on 
+0

- AGI Script /root/test.py terminé, retour 0 et informations du AGI sur les canaux, la priorité etc. J'ai fais toutes les permissions à cette fille chmod 777 – SergeyMoroz

+0

pas de fichier. L'utilisateur d'astérisque n'a généralement pas d'accès au dossier racine. – arheops