Commit 64b0ee04 authored by Valentin Samir's avatar Valentin Samir

[sip/sms] Methode pour envoyer des IM via la classe Sms

On adapte send_sms en conséquence
parent 83bd5085
......@@ -16,6 +16,9 @@ from datetime import datetime
sys.path.append('/usr/scripts/')
import lc_ldap.shortcuts
import lc_ldap.objets
import gestion.secrets_new as secrets
class NullRecv(EnvironmentError):
pass
......@@ -120,6 +123,32 @@ class Sms(object):
cur.close()
conn.close()
def send(self, dst, msg, src=None):
if isinstance(src, lc_ldap.objets.proprio):
# rajouter @crans.org ne semble pas marcher, pourquoi ?
num="1%04d" % src['aid'][0].value
profile_manager = Profile(self.sql_params, "voip_profile")
callerid = profile_manager.num_to_callerid(num)
caller = '"%s" <sip:%s@crans.org>' % (callerid, num)
elif src:
caller = src
else:
caller = "ServiceCenter"
to = "sip:1%04d" % dst['aid'][0].value
ast_manager = Manager('sms', secrets.get('asterisk_sms_passwd'))
try:
ast_manager.messageSend(caller, to, msg)
except AsteriskError as error:
if error.message == "Message failed to send.":
self.sms_delay(error.params['from'], error.params['to'], error.params['base64body'], error.params['to'].split(':',1)[1], body_type='base64')
else:
raise
class History(object):
def __init__(self, sql_params, database, quota_limit):
self.sql_params = sql_params
......
......@@ -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
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
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]
sms=Sms("dbname='django' user='crans' host='pgsql.adm.crans.org'", "voip_sms")
sms.send(dst, sys.stdin.read(), src)
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