[sip/sms] Methode pour envoyer des IM via la classe Sms
On adapte send_sms en conséquence
This commit is contained in:
parent
83bd508547
commit
64b0ee0478
2 changed files with 35 additions and 21 deletions
|
@ -35,28 +35,13 @@ if __name__ == '__main__':
|
|||
if login == 'respbats':
|
||||
login = os.getenv('SUDO_USER')
|
||||
ldap = lc_ldap.shortcuts.lc_ldap_readonly()
|
||||
adh = ldap.search(u'uid=%s' % login)[0]
|
||||
|
||||
# rajouter @crans.org ne semble pas marcher, pourquoi ?
|
||||
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)
|
||||
src = ldap.search(u'uid=%s' % login)[0]
|
||||
|
||||
dst = args.dst
|
||||
if not dst:
|
||||
dst = "sip:1%04d" % adh['aid'][0].value
|
||||
dst = src
|
||||
else:
|
||||
dst = ldap.search(u"(|(uid=%(dst)s)(mailAlias=%(dst)s@crans.org)(canonicalAlias=%(dst)s@crans.org)(aid=%(dst)s)(aid=%(dst_alt)s))" % {'dst' : dst, 'dst_alt' : dst.replace('sip:','')[1:]})[0]
|
||||
|
||||
ast_manager = Manager('sms', secrets.get('asterisk_sms_passwd'))
|
||||
|
||||
# TODO mode hors ligne
|
||||
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
|
||||
sms=Sms("dbname='django' user='crans' host='pgsql.adm.crans.org'", "voip_sms")
|
||||
sms.send(dst, sys.stdin.read(), src)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue