diff --git a/README.md b/README.md index b445bf0..13e57d5 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ client.set_message_sent_handler( lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler( lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id))) +client.set_message_alert_handler( + lambda pdu: sys.stdout.write('alert {}, is now {} \n'.format(pdu.source_addr, pdu.ms_availability_status))) client.connect() client.bind_transceiver(system_id='login', password='secret') diff --git a/smpplib/client.py b/smpplib/client.py index 712f2fa..8924256 100644 --- a/smpplib/client.py +++ b/smpplib/client.py @@ -254,6 +254,10 @@ def set_message_sent_handler(self, func): """Set new function to handle message sent event""" self.message_sent_handler = func + def set_message_alert_handler(self, func): + """Set new function to handle message alert event""" + self.message_alert_handler = func + @staticmethod def message_received_handler(pdu, **kwargs): """Custom handler to process received message. May be overridden""" @@ -266,6 +270,13 @@ def message_sent_handler(pdu, **kwargs): May be overridden""" logger.warning('Message sent handler (Override me)') + @staticmethod + def message_alert_handler(pdu, **kwargs): + """Called when SMPP server notify us about a MS changed it's state + May be overridden""" + logger.warning('Message alert handler (Override me)') + + def listen(self, ignore_error_codes=None): """Listen for PDUs and act""" @@ -291,6 +302,8 @@ def listen(self, ignore_error_codes=None): self.message_sent_handler(pdu=p) elif p.command == 'deliver_sm': self._message_received(p) + elif p.command == 'alert_notification': + self.message_alert_handler(p) elif p.command == 'enquire_link': self._enquire_link_received() elif p.command == 'enquire_link_resp': diff --git a/smpplib/command.py b/smpplib/command.py index ba318ac..4cb224b 100644 --- a/smpplib/command.py +++ b/smpplib/command.py @@ -38,6 +38,7 @@ def factory(command_name, **kwargs): try: return { + 'alert_notification': AlertNotification, 'bind_transmitter': BindTransmitter, 'bind_transmitter_resp': BindTransmitterResp, 'bind_receiver': BindReceiver, @@ -577,6 +578,42 @@ def __init__(self, command, **kwargs): super(GenericNAck, self).__init__(command, need_sequence=False, **kwargs) +class AlertNotification(Command): + """Notify about a MC which become available and has a delivery pending flag.""" + + _defs = [] + + params = { + 'source_addr_ton': Param(type=int, size=1), + 'source_addr_npi': Param(type=int, size=1), + 'source_addr': Param(type=str, max=65), + 'esme_addr_ton': Param(type=int, size=1), + 'esme_addr_npi': Param(type=int, size=1), + 'esme_addr': Param(type=str, max=65), + + # Optional params + 'ms_availability_status': Param(type=int, size=1), + } + + params_order = ( + 'source_addr_ton', + 'source_addr_npi', + 'source_addr', + 'esme_addr_ton', + 'esme_addr_npi', + 'esme_addr', + + # Optional TLV + 'ms_availability_status', + ) + + def __init__(self, command, **kwargs): + """Initialize""" + + super(AlertNotification, self).__init__(command, need_sequence=False, + **kwargs) + + self._set_vars(**(dict.fromkeys(self.params))) class SubmitSM(Command): """submit_sm command class