from twisted.internet.defer import inlineCallbacks
from twisted.python import log

from vumi.workers.smpp.transport import SmppTransport

class TopicSmppTransport(SmppTransport):
    
    @inlineCallbacks
    def esme_connected(self, client):
        log.msg("ESME Connected, adding handlers")
        self.esme_client = client
        self.esme_client.set_handler(self)

        # Start the publisher
        self.publisher = yield self.publish_to(
            routing_key = 'sms.inbound.%s' % self.config.get('TRANSPORT_NAME'),
            exchange_name = self.config.get('exchange_name'),
            exchange_type = self.config.get('exchange_type')
        )
        
        # Match on a wildcard
        self.consume(
            routing_key = 'sms.outbound.%s.*' % self.config.get('TRANSPORT_NAME'),
            callback = self.handle_outbound_sms,
            exchange_name = self.config.get('exchange_name'),
            exchange_type = self.config.get('exchange_type')
        )
    
    def handle_outbound_sms(self, message):
        # send the message via SMPP
        sequence_number = self.send_smpp(**message.payload)
        # get the sequence_number, link it back to our own internal
            # TODO This needs to be replaced with a Redis save
            #formdict = {
                    #"sent_sms":message.payload.get("id"),
                    #"sequence_number": sequence_number,
                    #}
            #log.msg("SMPPLinkForm", repr(formdict))
            #form = forms.SMPPLinkForm(formdict)
            #form.save()
        return True

@@ -1081,479 +1081,34 @@
   se
-quence_number = self.send_smpp(**message.payload)%0A        # get the sequence_number, link it back to our own internal%0A            # TODO This needs to be replaced with a Redis save%0A            #formdict = %7B%0A                    #%22sent_sms%22:message.payload.get(%22id%22),%0A                    #%22sequence_number%22: sequence_number,%0A                    #%7D%0A            #log.msg(%22SMPPLinkForm%22, repr(formdict))%0A            #form = forms.SMPPLinkForm(formdict)%0A            #form.save(
+lf.consume_message(message
 )%0A  

use the SUPER consume_message to send & redis link the outgoing message