Esempio n. 1
0
 def setup_transport(self):
     log.msg("Setup yo transport %s" % self.config)
     self.web_resource = yield self.start_web_resources(
         [
             (AirtelBfHttpReceiveSMSResource(self), self.config['receive_path'])
             ],
         self.config['receive_port'])
Esempio n. 2
0
 def handle_outbound_message(self, message):
     log.msg("Outbound message to be processed %s" % repr(message))
     try:
         params = {
             'DA': message['from_addr'],
             'SOA': message['to_addr'],
             'content': (message['content'] or '').encode("utf8"),
             'u': self.config['login'],
             'p': self.config['password']}
         encoded_params = urlencode(params)
         log.msg('Hitting %s with %s' % (self.config['outbound_url'], encoded_params))
         response = yield http_request_full(
             "%s?%s" % (self.config['outbound_url'], encoded_params),
             method='GET')
         log.msg("Response: (%s) %r" % (response.code, response.delivered_body))
         content = response.delivered_body.strip()            
         
         if response.code == 200:
             yield self.publish_ack(
                 user_message_id=message['message_id'],
                 sent_message_id=message['message_id']
             )
         else:
             error = self.KNOWN_ERROR_RESPONSE_CODES.get(
                 content,
                 'Unknown response code: %s' % (content,))
             yield self.publish_nack(message['message_id'], error)
     except Exception as ex:
         log.msg("Unexpected error %s" % repr(ex))
Esempio n. 3
0
 def dispatch_inbound_message(self, msg):
     log.msg("Dispatch inbound %r" % msg)
     route_mapping = False
     try:
         names = self.config['route_mappings'][msg['transport_name']]
         for name in names:
             log.msg("Dispatch inbound to %s" % name)
             self.dispatcher.publish_outbound_message(name, msg.copy())
             route_mapping = True
     except:
         pass
     if route_mapping:
         return
     toaddr = msg['to_addr']
     for name, regex in self.toaddr_mappings:
         if regex.match(toaddr):
             log.msg("Dispatch outbound %s to %s" % (toaddr, name))
             self.dispatcher.publish_outbound_message(name, msg.copy())
             return
     if 'toaddr_fallback' in self.config and self.config[
             'toaddr_fallback'] is not None:
         log.msg("Dispatch outbound %s to fallback" % toaddr)
         self.dispatcher.publish_outbound_message(
             self.config['toaddr_fallback'], msg.copy())
         return
     log.err("No route for %s" % repr(msg))
Esempio n. 4
0
 def dispatch_inbound_message(self, msg):
     log.msg("Dispatch inbound %r" % msg)
     route_mapping = False
     try:
         names = self.config['route_mappings'][msg['transport_name']]
         for name in names:
             log.msg("Dispatch inbound to %s" % name)
             self.dispatcher.publish_outbound_message(name, msg.copy())
             route_mapping = True
     except:
         pass
     if route_mapping:
         return
     toaddr = msg['to_addr']
     for name, regex in self.toaddr_mappings:
         if regex.match(toaddr):
             log.msg("Dispatch outbound %s to %s" % (toaddr, name))
             self.dispatcher.publish_outbound_message(name, msg.copy())
             return
     if 'toaddr_fallback' in self.config and self.config['toaddr_fallback'] is not None:
         log.msg("Dispatch outbound %s to fallback" % toaddr)
         self.dispatcher.publish_outbound_message(self.config['toaddr_fallback'], msg.copy())
         return
     log.err("No route for %s" % repr(msg))
Esempio n. 5
0
 def render_GET(self, request):
     log.msg('got hit with %s' % request.args)
     self.transport.handle_raw_inbound_message(request)
     return ''