Python AGI 脚本导致 Asterisk 错误 510
Python AGI script results in Asterisk error 510
我正在尝试使用星号整合 google 对话流,以便在我的其他 agi 聊天机器人脚本中使用。但是我 运行 在使用星号执行脚本时遇到了问题。该脚本在从命令行运行时工作正常,但在通过星号运行时失败,知道为什么吗?我在 centos 服务器上使用基本安装的 Python 2.7。 运行 通过星号失败时的脚本在行:session_client = dialogflow.SessionsClient()
(通过在每个通道打印一个数字并检查何时抛出错误来检查)
脚本:
#!/usr/bin/python
import dialogflow
import sys
import json
def detect_intent_texts(project_id, session_id, texts, language_code):
"""Returns the result of detect intent with texts as inputs.
Using the same `session_id` between requests allows continuation
of the conversation."""
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
print('Session path: {}\n'.format(session))
text_input = dialogflow.types.TextInput(
text=texts, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(
session=session, query_input=query_input)
print('=' * 20)
print('Query text: {}'.format(response.query_result.query_text))
print('Detected intent: {} (confidence: {})\n'.format(
response.query_result.intent.display_name,
response.query_result.intent_detection_confidence))
print('Fulfillment text: {}\n'.format(
response.query_result.fulfillment_text))
try:
detect_intent_texts("fake-219706", 34, "hallo dit is nick vaes","nl")
except:
print("error")
在命令行上运行时的输出:
[root@stage-ai agi-bin]# ./DF.py
Session path: projects/fake-219706/agent/sessions/34
====================
Query text: hallo dit is nick vaes
Detected intent: Default Welcome Intent (confidence: 1.0)
Fulfillment text: Goedemorgen zoekt u een groep of een persoon?
星号输出:
Connected to Asterisk 16.2.1 currently running on stage-ai (pid = 3600)
== Using SIP RTP CoS mark 5
-- Executing [*9@INTERNO:1] NoOp("SIP/6004-0000003a", "called *9") in new stack
-- Executing [*9@INTERNO:2] Answer("SIP/6004-0000003a", "") in new stack
-- Executing [*9@INTERNO:3] Verbose("SIP/6004-0000003a", "the caller is: 6004") in new stack
the caller is: 6004
-- Executing [*9@INTERNO:4] Set("SIP/6004-0000003a", "caller=6004") in new stack
-- Executing [*9@INTERNO:5] AGI("SIP/6004-0000003a", "DF.py") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/DF.py
<SIP/6004-0000003a>AGI Tx >> agi_request: DF.py
<SIP/6004-0000003a>AGI Tx >> agi_channel: SIP/6004-0000003a
<SIP/6004-0000003a>AGI Tx >> agi_language: en
<SIP/6004-0000003a>AGI Tx >> agi_type: SIP
<SIP/6004-0000003a>AGI Tx >> agi_uniqueid: 1554996754.116
<SIP/6004-0000003a>AGI Tx >> agi_version: 16.2.1
<SIP/6004-0000003a>AGI Tx >> agi_callerid: 6004
<SIP/6004-0000003a>AGI Tx >> agi_calleridname: Yannick
<SIP/6004-0000003a>AGI Tx >> agi_callingpres: 0
<SIP/6004-0000003a>AGI Tx >> agi_callingani2: 0
<SIP/6004-0000003a>AGI Tx >> agi_callington: 0
<SIP/6004-0000003a>AGI Tx >> agi_callingtns: 0
<SIP/6004-0000003a>AGI Tx >> agi_dnid: *9
<SIP/6004-0000003a>AGI Tx >> agi_rdnis: unknown
<SIP/6004-0000003a>AGI Tx >> agi_context: INTERNO
<SIP/6004-0000003a>AGI Tx >> agi_extension: *9
<SIP/6004-0000003a>AGI Tx >> agi_priority: 5
<SIP/6004-0000003a>AGI Tx >> agi_enhanced: 0.0
<SIP/6004-0000003a>AGI Tx >> agi_accountcode:
<SIP/6004-0000003a>AGI Tx >> agi_threadid: 140598249563904
<SIP/6004-0000003a>AGI Tx >>
<SIP/6004-0000003a>AGI Rx << error
<SIP/6004-0000003a>AGI Tx >> 510 Invalid or unknown command
-- <SIP/6004-0000003a>AGI Script DF.py completed, returning 0
-- Executing [*9@INTERNO:6] Hangup("SIP/6004-0000003a", "") in new stack
== Spawn extension (INTERNO, *9, 6) exited non-zero on 'SIP/6004-0000003a'
stage-ai*CLI>
拨号方案:
exten => *9,1,NoOp(called *9)
same => n,Answer()
same => n,agi(DF.py)
您的脚本在某些时候将单词 "error" 打印到 STDOUT。
Asterisk AGI 规范没有"error"命令,所以它告诉你错误。
像这样的代码是非常糟糕的做法,因为你不知道你得到的是哪个异常。
except:
print("error")
我正在尝试使用星号整合 google 对话流,以便在我的其他 agi 聊天机器人脚本中使用。但是我 运行 在使用星号执行脚本时遇到了问题。该脚本在从命令行运行时工作正常,但在通过星号运行时失败,知道为什么吗?我在 centos 服务器上使用基本安装的 Python 2.7。 运行 通过星号失败时的脚本在行:session_client = dialogflow.SessionsClient() (通过在每个通道打印一个数字并检查何时抛出错误来检查)
脚本:
#!/usr/bin/python
import dialogflow
import sys
import json
def detect_intent_texts(project_id, session_id, texts, language_code):
"""Returns the result of detect intent with texts as inputs.
Using the same `session_id` between requests allows continuation
of the conversation."""
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
print('Session path: {}\n'.format(session))
text_input = dialogflow.types.TextInput(
text=texts, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(
session=session, query_input=query_input)
print('=' * 20)
print('Query text: {}'.format(response.query_result.query_text))
print('Detected intent: {} (confidence: {})\n'.format(
response.query_result.intent.display_name,
response.query_result.intent_detection_confidence))
print('Fulfillment text: {}\n'.format(
response.query_result.fulfillment_text))
try:
detect_intent_texts("fake-219706", 34, "hallo dit is nick vaes","nl")
except:
print("error")
在命令行上运行时的输出:
[root@stage-ai agi-bin]# ./DF.py
Session path: projects/fake-219706/agent/sessions/34
====================
Query text: hallo dit is nick vaes
Detected intent: Default Welcome Intent (confidence: 1.0)
Fulfillment text: Goedemorgen zoekt u een groep of een persoon?
星号输出:
Connected to Asterisk 16.2.1 currently running on stage-ai (pid = 3600)
== Using SIP RTP CoS mark 5
-- Executing [*9@INTERNO:1] NoOp("SIP/6004-0000003a", "called *9") in new stack
-- Executing [*9@INTERNO:2] Answer("SIP/6004-0000003a", "") in new stack
-- Executing [*9@INTERNO:3] Verbose("SIP/6004-0000003a", "the caller is: 6004") in new stack
the caller is: 6004
-- Executing [*9@INTERNO:4] Set("SIP/6004-0000003a", "caller=6004") in new stack
-- Executing [*9@INTERNO:5] AGI("SIP/6004-0000003a", "DF.py") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/DF.py
<SIP/6004-0000003a>AGI Tx >> agi_request: DF.py
<SIP/6004-0000003a>AGI Tx >> agi_channel: SIP/6004-0000003a
<SIP/6004-0000003a>AGI Tx >> agi_language: en
<SIP/6004-0000003a>AGI Tx >> agi_type: SIP
<SIP/6004-0000003a>AGI Tx >> agi_uniqueid: 1554996754.116
<SIP/6004-0000003a>AGI Tx >> agi_version: 16.2.1
<SIP/6004-0000003a>AGI Tx >> agi_callerid: 6004
<SIP/6004-0000003a>AGI Tx >> agi_calleridname: Yannick
<SIP/6004-0000003a>AGI Tx >> agi_callingpres: 0
<SIP/6004-0000003a>AGI Tx >> agi_callingani2: 0
<SIP/6004-0000003a>AGI Tx >> agi_callington: 0
<SIP/6004-0000003a>AGI Tx >> agi_callingtns: 0
<SIP/6004-0000003a>AGI Tx >> agi_dnid: *9
<SIP/6004-0000003a>AGI Tx >> agi_rdnis: unknown
<SIP/6004-0000003a>AGI Tx >> agi_context: INTERNO
<SIP/6004-0000003a>AGI Tx >> agi_extension: *9
<SIP/6004-0000003a>AGI Tx >> agi_priority: 5
<SIP/6004-0000003a>AGI Tx >> agi_enhanced: 0.0
<SIP/6004-0000003a>AGI Tx >> agi_accountcode:
<SIP/6004-0000003a>AGI Tx >> agi_threadid: 140598249563904
<SIP/6004-0000003a>AGI Tx >>
<SIP/6004-0000003a>AGI Rx << error
<SIP/6004-0000003a>AGI Tx >> 510 Invalid or unknown command
-- <SIP/6004-0000003a>AGI Script DF.py completed, returning 0
-- Executing [*9@INTERNO:6] Hangup("SIP/6004-0000003a", "") in new stack
== Spawn extension (INTERNO, *9, 6) exited non-zero on 'SIP/6004-0000003a'
stage-ai*CLI>
拨号方案:
exten => *9,1,NoOp(called *9)
same => n,Answer()
same => n,agi(DF.py)
您的脚本在某些时候将单词 "error" 打印到 STDOUT。
Asterisk AGI 规范没有"error"命令,所以它告诉你错误。
像这样的代码是非常糟糕的做法,因为你不知道你得到的是哪个异常。
except:
print("error")