Commit 83bd5085 authored by Valentin Samir's avatar Valentin Samir

[sip/send_sms.py] Caller id correct et delaie des IM si le compte n'est pas connecté

parent cdb556e7
......@@ -26,7 +26,7 @@ parser.add_argument('-d', '--dst', default=None,
# Attention: on a besoin d'importer le module sip de /usr/scripts
# et non celui des libs python
import lc_ldap.shortcuts
from sip.asterisk import Manager
from sip.asterisk import Manager, AsteriskError, Sms, Profile
if __name__ == '__main__':
args = parser.parse_args(sys.argv[1:])
......@@ -38,19 +38,25 @@ if __name__ == '__main__':
adh = ldap.search(u'uid=%s' % login)[0]
# rajouter @crans.org ne semble pas marcher, pourquoi ?
own = "sip:1" + str(adh['aid'][0]) + "@crans.org"
# TODO utiliser le vrai caller id
# profile_manager = Profile("dbname='django' user='crans' " +
# "host='pgsql.adm.crans.org'", "voip_profile")
# callerid = profile_manager.num_to_callerid(own)
callerid = os.path.basename(__file__)
num="1%04d" % adh['aid'][0].value
own = "sip:" + num + "@crans.org"
profile_manager = Profile("dbname='django' user='crans' " +
"host='pgsql.adm.crans.org'", "voip_profile")
callerid = profile_manager.num_to_callerid(num)
caller = '"%s" <%s>' % (callerid, own)
dst = args.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'))
# TODO mode hors ligne
ast_manager.messageSend(caller, dst, sys.stdin.read())
try:
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment