wcs/wcs/qommon/sms.py

50 lines
1.6 KiB
Python

# w.c.s. - web application for online forms
# Copyright (C) 2005-2010 Entr'ouvert
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
from wcs.wscalls import call_webservice
from . import get_cfg
from . import get_logger
class PasserelleSMS:
TIMEOUT = 10
def __init__(self):
sms_cfg = get_cfg('sms', {})
self.sender = sms_cfg.get('sender', '')
self.url = sms_cfg.get('passerelle_url', '')
def send(self, sender, destinations, text, quality=None):
sender = sender or self.sender
payload = {
'from': sender,
'message': text,
'to': destinations,
}
data = call_webservice(self.url, method='POST', post_data=payload)[2]
get_logger().debug('sms %r sent using passerelle to %r, result: %r', text, destinations, data)
class SMS:
@classmethod
def get_sms_class(cls):
sms_cfg = get_cfg('sms', {})
if sms_cfg.get('sender') and sms_cfg.get('passerelle_url'):
return PasserelleSMS()
return None