问题描述
我目前正在从事通过电子邮件发送语音呼叫"项目.我使用python提取了电子邮件&将其转换为语音并保存在WAV文件中.现在使用星号(我在ubuntu 10.10操作系统上安装了Asterisk 10.2.1),我想通过我的系统向用户的手机(例如919833000000印度的号码)生成呼叫.
我已经编写了python代码以连接到星号管理器界面.我也配置了sip.conf和extensions.conf文件以及manager.conf.我已经在voip提供商 voiceall.com 上注册,并有一个用户名密码.
现在,当我执行python代码时,该代码将被执行而没有任何错误,但是什么也没有发生.没有通话产生.谁能帮我这个忙.python代码如下:
import sys, os, socket, random
# Asterisk Manager connection details
HOST = '127.0.0.1'
PORT = 5038
# Asterisk Manager username and password
USER = 'MYUSERNAME'
SECRET = 'MYPASSWORD'
# Set the name of the SIP trunk to use for outbound calls
TRUNK = 'voiceall'
OUTBOUND = '919833000000'
# Send the call details to the Asteirsk Manager Interface
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
sleep(3)
s.send('Action: login\r\n')
s.send('Username: ' + USER + '\r\n')
s.send('Secret: ' + SECRET + '\r\n\r\n')
sleep(3)
s.send('Action: status\r\n')
data = s.recv(1024)
print data + '\n'
s.send('Events: off\r\n\r\n')
sleep(3)
s.send('Action: originate\r\n')
s.send('Channel: Sip/' + TRUNK + '/' + OUTBOUND + '\r\n')
s.send('WaitTime: 30\r\n')
s.send('CallerId: VOICEALL_USERNAME\r\n')
s.send('Application: playback\r\n')
s.send('Data: /home/Documents/newdemo1' + '\r\n') #newdemo1 is the wave file
s.send('Context: testing\r\n')
s.send('Async: true\r\n')
s.send('Priority: 1\r\n\r\n')
sleep(10)
s.send('Action: Logoff\r\n\r\n')
s.close()
我的sip.conf文件如下:
[general]
register => VOICEALL_USERNAME:VOICEALL_PASSWORD@sip.voiceall.net:5038
[voiceall]
canreinvite=no
context=mycontext
host=sip.voiceall.net
secret=VOICEALL_PASSWORD ;your password
type=peer
username=VOICEALL_USERNAME ;your account
disallow=all
allow=ulaw
fromuser=VOICEALL_USERNAME ;your account
trustrpid=yes
sendrpid=yes
insecure=invite
nat=yes
extensions.conf文件如下:
[mycontext]
include => voiceall-outbound
[voiceall-outbound]
exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@voiceall)
exten => _1NXXNXXXXXX,n,Playback(/home/Documents/demonew1)
exten => _1NXXNXXXXXX,n,Hangup()
exten => _NXXNXXXXXX,1,Dial(SIP/1${EXTEN}@voiceall)
exten => _NXXNXXXXXX,n,Playback(/home/Documents/demonew1)
exten => _NXXNXXXXXX,n,Hangup()
exten => _011.,1,Dial(SIP/${EXTEN}@voiceall)
exten => _011.,n,Playback(/home/Documents/demonew1)
exten => _011.,n,Hangup()
请帮助我,因为我是星号的新手.任何帮助将不胜感激.预先感谢.
在对您的origin命令进行评论之前,需要注意以下几点:
-
用于TCP上的AMI的python包装器库已经存在: starpy .您可能需要检查一下,因为这样可以减少重新发明轮子的数量,以使自己启动并运行.
-
通常,您可能不应该为AMI操作中的每个参数使用单独的TCP发送.相反,您应该分别发送每条消息.通常,starpy通过将每个AMI操作视为键/值对的字典来很好地处理此问题,这显然可以很好地映射到AMI的语法.如果您决定不使用starpy,您可能仍想看看它们如何将通用词典映射到AMI操作.
-
在manager.conf中是否为您的用户提供了适当的身份验证类?为了发起呼叫,您的用户将需要具有写授权的Origin类
在您的来源中,您正在尝试拨打SIP/voiceall/919833000000.这意味着Asterisk将创建一个SIP通道,并在与您指定的扩展名匹配的扩展名的VoiceAll-Outbound上下文中启动其pbx_thread(因为它是您指定的对等方的默认上下文).
首先,您要放置的扩展名是919833000000.您没有与此匹配的扩展名-最接近的扩展名是_NXXNXXXXXX.这指定了它的模式匹配,第一个字符必须是数字[2-9],后两个字符是数字[0-9],第四个字符是数字[2-9],后六个字符字符是数字[0-9],总共10个字符.您指定的扩展名是12个字符.我希望起源会失败.
让我们假设起源确实成功了,并且您具有一个模式匹配扩展名,并且具有与_NXXNXXXXXX相同的应用程序.您发起的频道将与其他内容绑定-其他上下文,扩展名,拨号方案中的优先级或应用程序.在您的情况下,您同时指定了两个:要连接到(播放)的应用程序,要传递给它的数据以及上下文和优先级(但没有扩展名).那是无效的.来自Asterisk的"manager show命令来源":
延伸 使用扩展(需要上下文"和优先级")语境 要使用的上下文(需要扩展"和优先级")优先 使用优先级(需要扩展"和上下文")
通常,您不会将应用程序/数据与Context,Exten,Priority结合使用.当您只想对拨号内容执行非常简单的操作时,可以使用应用程序/数据"选项-在您的示例中,播放一条消息符合要求,但是总的来说,我更喜欢将其连接到拨号方案中的其他内容,因此更多的控制权.我假设您要使用Context,Exten,Priority-在这种情况下,您可以执行以下操作:
[testing]
exten => internal_playback,1,NoOp()
same => n,Playback(/home/Documents/demonew1)
same => n,Hangup()
[voiceall-outbound]
exten => _9XXXXX000000,1,NoOp()
same => n,Dial(SIP/${EXTEN}@voiceall)
same => n,Hangup()
您的来源将看起来像这样:
Action: Originate
Channel: local/internal_playback@testing
Context: voiceall-outbound
Exten: 919833000000
Priority: 1
您会注意到,我们不再使用SIP频道来拨打拨号计划.您仍然可以在来源中使用SIP频道-实际上,这只是个人喜好.Dial应用程序已经为我们创建了一个SIP通道并将其桥接到我们发起的任何内容,因此我们仅使用本地通道.对于本地频道,我们将一端连接到内部播放分机,用于播放声音到被叫方,另一端连接到出站分机.
I'm currently working on a project 'email to voice call'. Using python i'v extracted the email & converted it into speech and saved in a WAV file. Now using asterisk (I'v installed Asterisk 10.2.1 on my ubuntu 10.10 os) i want to generate call to the cell phone (say 919833000000 india's no.) of the user through my system.
I have written a python code to connect to asterisk manager interface. Also i have configured the sip.conf and extensions.conf files as well as manager.conf. I have registered with voip provider voiceall.com and have a username password of it.
Now when i'm executing the python code, the code is getting executed without any error but nothing is happening. No call is getting generated. Can anyone help me out with this.The python code is as below:
import sys, os, socket, random
# Asterisk Manager connection details
HOST = '127.0.0.1'
PORT = 5038
# Asterisk Manager username and password
USER = 'MYUSERNAME'
SECRET = 'MYPASSWORD'
# Set the name of the SIP trunk to use for outbound calls
TRUNK = 'voiceall'
OUTBOUND = '919833000000'
# Send the call details to the Asteirsk Manager Interface
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
sleep(3)
s.send('Action: login\r\n')
s.send('Username: ' + USER + '\r\n')
s.send('Secret: ' + SECRET + '\r\n\r\n')
sleep(3)
s.send('Action: status\r\n')
data = s.recv(1024)
print data + '\n'
s.send('Events: off\r\n\r\n')
sleep(3)
s.send('Action: originate\r\n')
s.send('Channel: Sip/' + TRUNK + '/' + OUTBOUND + '\r\n')
s.send('WaitTime: 30\r\n')
s.send('CallerId: VOICEALL_USERNAME\r\n')
s.send('Application: playback\r\n')
s.send('Data: /home/Documents/newdemo1' + '\r\n') #newdemo1 is the wave file
s.send('Context: testing\r\n')
s.send('Async: true\r\n')
s.send('Priority: 1\r\n\r\n')
sleep(10)
s.send('Action: Logoff\r\n\r\n')
s.close()
My sip.conf file is as below:
[general]
register => VOICEALL_USERNAME:VOICEALL_PASSWORD@sip.voiceall.net:5038
[voiceall]
canreinvite=no
context=mycontext
host=sip.voiceall.net
secret=VOICEALL_PASSWORD ;your password
type=peer
username=VOICEALL_USERNAME ;your account
disallow=all
allow=ulaw
fromuser=VOICEALL_USERNAME ;your account
trustrpid=yes
sendrpid=yes
insecure=invite
nat=yes
The extensions.conf file is as below:
[mycontext]
include => voiceall-outbound
[voiceall-outbound]
exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@voiceall)
exten => _1NXXNXXXXXX,n,Playback(/home/Documents/demonew1)
exten => _1NXXNXXXXXX,n,Hangup()
exten => _NXXNXXXXXX,1,Dial(SIP/1${EXTEN}@voiceall)
exten => _NXXNXXXXXX,n,Playback(/home/Documents/demonew1)
exten => _NXXNXXXXXX,n,Hangup()
exten => _011.,1,Dial(SIP/${EXTEN}@voiceall)
exten => _011.,n,Playback(/home/Documents/demonew1)
exten => _011.,n,Hangup()
Please help me out, as i am new to asterisk.Any help will be appreciated. Thanks in advance.
A few things to note before I comment on your originate command:
A python wrapper library for AMI over TCP already exists: starpy. You may want to check that out, as it will reduce the amount of re-inventing the wheel you'll need to do in order to get yourself up and running.
In general, you probably shouldn't use separate TCP sends for each parameter in an AMI action. Instead, you should send each message separately. In general, starpy handles this quite well by treating each AMI action as a dictionary of key/value pairs, which obviously maps quite well to AMI's syntax. If you decide not to use starpy, you may still want to see how they map generic dictionaries to AMI actions.
Do you have the appropriate classes of authentication for your user in manager.conf? In order to originate a call, your user will need the originate class on the write authorization
In your origination, you're attempting to dial SIP/voiceall/919833000000. That implies that Asterisk will create a SIP channel and start its pbx_thread at context voiceall-outbound (because its the default context for the peer you specified), at the extension matching what you specified.
First, your extension that you're attempting to place is 919833000000. You don't have an extension that matches this - the closest you have is _NXXNXXXXXX. This specifies that its a pattern match, that the first character must be a number [2-9], the next two characters are numbers [0-9], the fourth character is a number [2-9], and the next six characters are numbers [0-9], for a total of 10 characters. The extension you're specifying is 12 characters. I would expect the originate to fail.
Let's assume that the originate did succeed, and you had a pattern match extension with the same applications as _NXXNXXXXXX. A channel that you're originating is going to be tied to something else - either another context,extension,priority in the dialplan, or an application. In your case, you've specified both: an application to connect to (Playback), with data you're passing to it, as well as a context and a priority (but no extension). That's not valid. From Asterisk's 'manager show command originate':
Exten Extension to use (requires 'Context' and 'Priority')Context Context to use (requires 'Exten' and 'Priority')Priority Priority to use (requires 'Exten' and 'Context')
In general, you don't combine Application/Data with Context,Exten,Priority. The Application/Data option exists when you want to only do very simple actions with what you dial - in your example, playing back a message fits the bill, but in general, I prefer to connect it to something else in the dialplan so I have more control. I'll assume you want to use Context,Exten,Priority - in which case, you could do something like the following:
[testing]
exten => internal_playback,1,NoOp()
same => n,Playback(/home/Documents/demonew1)
same => n,Hangup()
[voiceall-outbound]
exten => _9XXXXX000000,1,NoOp()
same => n,Dial(SIP/${EXTEN}@voiceall)
same => n,Hangup()
Your originate would then look something like this:
Action: Originate
Channel: local/internal_playback@testing
Context: voiceall-outbound
Exten: 919833000000
Priority: 1
You'll note that we're no longer using a SIP channel to call into the dialplan. You could still use a SIP channel in your originate - its really just a personal preference here.The Dial application will already create a SIP channel for us and bridge it to whatever we originate, so we just use a local channel. For our local channel, we connect one end to our internal playback extension that we use to play sound out to the dialed party, and the other end to our outbound extension.
这篇关于无法使用星号拨打手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!