Asterisk AGI 脚本未运行

问题描述 投票:0回答:1

我正在尝试创建一个 AGI Python 脚本来检查调用者是否已列入黑名单。但这始终是输出。

启动AGI脚本/usr/share/asterisk/agi-bin/script.py AGI Tx >> agi_request:/usr/share/asterisk/agi-bin/script.py AGI Tx >> agi_channel:SIP/192.168.1.10-00000000 AGI Tx >> agi_语言:en AGI Tx >> agi_type:SIP AGI Tx >> agi_uniqueid:1697353949.0 AGI Tx >> agi_版本:18.10.0~dfsg+~cs6.10.40431411-2 AGI Tx >> agi_callerid:7OO2 AGI Tx >> agi_calleridname:客户端 B AGI Tx >> agi_callingpres:0 AGI Tx >> agi_callingani2:0 AGI Tx >> agi_callington:0 AGI Tx >> agi_callingtns:0 AGI Tx >> agi_dnid:7001 AGI Tx >> agi_rdnis:未知 AGI Tx >> agi_context:传入 AGI Tx >> agi_扩展名:7001 AGI Tx >> agi_priority:2 AGI Tx >> agi_enhanced:0.0 AGI Tx >> agi_账户代码: AGI Tx >> agi_threadid:139655494649408 AGI TX >> -- AGI 脚本 /usr/share/asterisk/agi-bin/script.py 已完成,返回 0 自动失败,通道“SIP/192.168.1.10-00000000”状态为“未知” 配置:

[incoming]
exten => _X.,1,NoOp(Call from ${CALLERID(num)})
 same => n,AGI(/usr/share/asterisk/agi-bin/script.py)

代码:

#!/usr/bin/env python3
import sys
import pymysql #pip install pymysql
from asterisk.agi import AGI #pip install pyst3

agi = AGI()
agi.verbose("python agi started")

caller_id = agi.env['agi_callerid']
extension = agi.env['agi_extension']

db = pymysql.connect(host='localhost', user='asterisk', password='123', database='capstone')
cursor = db.cursor()

cursor.execute("SELECT id FROM blacklist WHERE caller_id = %s", (caller_id,))
result = cursor.fetchone()

if result:
 agi.hangup()
else:
 agi.exec("Dial", f"SIP/{extension}")

cursor.close()
db.close()
python asterisk agi
1个回答
0
投票

没关系,发现为什么它不起作用,这是我的Python库

© www.soinside.com 2019 - 2024. All rights reserved.