rdegges / pycall

A flexible python library for creating and using Asterisk call files.
http://pycall.org/
The Unlicense
90 stars 34 forks source link

pycall validation error #19

Open pd-Shah opened 6 years ago

pd-Shah commented 6 years ago

im trying to run these lines of code in atom and python3.6 :

from pycall import CallFile, Call, Application
import sys

def call():
        c = Call('SIP/200')
        a = Application('Playback', 'hello-world')
        cf = CallFile(c, a)
        cf.spool()

if __name__ == '__main__':
        call()

and my sip.conf and extension.conf are shown below:

sip.conf


[general]
disallow=all
allow=g729
allow=ulaw
allow=alaw
context=local_test
allowguest=no
allowoverlap=no
bindport=5060
bindaddr=0.0.0.0
srvlookup=no
alwaysauthreject=yes
canreinvite=no
nat=yes
session-timers=refuse
localnet=192.168.1.0/255.255.255.0
host=dynamic
callevents=yes
notifyhold = yes
callcounter=yes

[100]
type=friend
host=dynamic
secret=123
context=local_test

[200]
type=friend
host=dynamic
secret=123
context=local_test

extension.conf

[local_test]
exten => 1234,1,Answer ; answer the call
exten => 1234,2,Playback(tt-weasels) ; play an audio file that simulates the voice of the called user
exten => 1234,3,Hangup ; hang up the call

exten => 100,1,Set(VOLUME(RX)=10) ; set the RX volume
exten => 100,2,Set(VOLUME(TX)=10) ; set the RX volume
exten => 100,hint,SIP/100; hint  '100' used for presence notification
exten => 100,3,Dial(SIP/100) ; call the user 100'

exten => 200,1,Set(VOLUME(RX)=10) ; set the RX volume
exten => 200,2,Set(VOLUME(TX)=10) ; set the RX volume
exten => 200,hint,SIP/100; hint  '200' used for presence notification
exten => 200,3,Dial(SIP/200) call the user '200' used for presence notification

main.py

from pycall import CallFile, Call, Application
import sys

def call():
        c = Call('SIP/200')
        a = Application('Playback', 'hello-world')
        cf = CallFile(c, a)
        cf.spool()

if __name__ == '__main__':
        call()

finally i faced with this error:

Traceback (most recent call last):
  File "/home/pd/gits/voiphone/main.py", line 12, in <module>
    call()
  File "/home/pd/gits/voiphone/main.py", line 9, in call
    cf.spool()
  File "/home/pd/telephonerelayEnv/lib/python3.6/site-packages/pycall/callfile.py", line 135, in spool
    self.writefile()
  File "/home/pd/telephonerelayEnv/lib/python3.6/site-packages/pycall/callfile.py", line 123, in writefile
    f.write(self.contents)
  File "/home/pd/telephonerelayEnv/lib/python3.6/site-packages/pycall/callfile.py", line 118, in contents
    return '\n'.join(self.buildfile())
  File "/home/pd/telephonerelayEnv/lib/python3.6/site-packages/pycall/callfile.py", line 100, in buildfile
    raise ValidationError
pycall.errors.ValidationError

i would appreciate if you help me solving my problem. thank you in advance

shyjuk commented 5 years ago

Run as asterisk user.

sudo su asterisk -s /bin/bash

python

from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()