[sip/send_sms.py] Caller id correct et delaie des IM si le compte n'est pas connecté
This commit is contained in:
parent
cdb556e74e
commit
83bd508547
1 changed files with 15 additions and 9 deletions
|
@ -26,7 +26,7 @@ parser.add_argument('-d', '--dst', default=None,
|
||||||
# Attention: on a besoin d'importer le module sip de /usr/scripts
|
# Attention: on a besoin d'importer le module sip de /usr/scripts
|
||||||
# et non celui des libs python
|
# et non celui des libs python
|
||||||
import lc_ldap.shortcuts
|
import lc_ldap.shortcuts
|
||||||
from sip.asterisk import Manager
|
from sip.asterisk import Manager, AsteriskError, Sms, Profile
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parser.parse_args(sys.argv[1:])
|
args = parser.parse_args(sys.argv[1:])
|
||||||
|
@ -38,19 +38,25 @@ if __name__ == '__main__':
|
||||||
adh = ldap.search(u'uid=%s' % login)[0]
|
adh = ldap.search(u'uid=%s' % login)[0]
|
||||||
|
|
||||||
# rajouter @crans.org ne semble pas marcher, pourquoi ?
|
# rajouter @crans.org ne semble pas marcher, pourquoi ?
|
||||||
own = "sip:1" + str(adh['aid'][0]) + "@crans.org"
|
num="1%04d" % adh['aid'][0].value
|
||||||
# TODO utiliser le vrai caller id
|
own = "sip:" + num + "@crans.org"
|
||||||
# profile_manager = Profile("dbname='django' user='crans' " +
|
profile_manager = Profile("dbname='django' user='crans' " +
|
||||||
# "host='pgsql.adm.crans.org'", "voip_profile")
|
"host='pgsql.adm.crans.org'", "voip_profile")
|
||||||
# callerid = profile_manager.num_to_callerid(own)
|
callerid = profile_manager.num_to_callerid(num)
|
||||||
callerid = os.path.basename(__file__)
|
|
||||||
caller = '"%s" <%s>' % (callerid, own)
|
caller = '"%s" <%s>' % (callerid, own)
|
||||||
|
|
||||||
dst = args.dst
|
dst = args.dst
|
||||||
if not dst:
|
if not dst:
|
||||||
dst = "sip:1" + str(adh['aid'][0])
|
dst = "sip:1%04d" % adh['aid'][0].value
|
||||||
|
|
||||||
ast_manager = Manager('sms', secrets.get('asterisk_sms_passwd'))
|
ast_manager = Manager('sms', secrets.get('asterisk_sms_passwd'))
|
||||||
|
|
||||||
# TODO mode hors ligne
|
# TODO mode hors ligne
|
||||||
|
try:
|
||||||
ast_manager.messageSend(caller, dst, sys.stdin.read())
|
ast_manager.messageSend(caller, dst, sys.stdin.read())
|
||||||
|
except AsteriskError as error:
|
||||||
|
if error.message == "Message failed to send.":
|
||||||
|
sms=Sms("dbname='django' user='crans' host='pgsql.adm.crans.org'", "voip_sms")
|
||||||
|
sms.sms_delay(error.params['from'], error.params['to'], error.params['base64body'], error.params['to'].split(':',1)[1], body_type='base64')
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue