def render(self, request): request.setResponseCode(http.OK) request.setHeader('Content-Type', 'text/plain') hxg_msg = hxg.parse(request.content.read()) text = hxg_msg.get('USSText', '').strip() if hxg_msg['EventType'] == 'Request': if text == 'REQ': event_type = 'new_session' else: event_type = 'resume_session' else: event_type = '%s_session' % hxg_msg['EventType'].lower() routing_key = 'ussd.inbound.%s.%s' % ( self.config['transport_name'], safe_routing_key(hxg_msg['ConnStr']) ) msg = Message(**{ 'transport_session_id': hxg_msg['SessionID'], 'transport_message_type': event_type, 'message': text, 'recipient': hxg_msg['ConnStr'], 'sender': hxg_msg['MSISDN'], }) log.msg('publishing', msg, routing_key) self.publisher.publish_message(msg, routing_key=routing_key) return ''
def startWorker(self): log.msg('starting worker with ', self.config) self.publisher = yield self.publish_to( 'ussd.outbound.%(transport_name)s' % self.config) self.consumer = yield self.consume('ussd.inbound.%s.%s' % ( self.config['transport_name'], safe_routing_key(self.config['ussd_code']) ), self.consume_message)
def startWorker(self): self.publisher = yield self.publish_to('ussd.outbound.%s' % self.config['transport_name']) self.sessions = {} self.consume('ussd.inbound.%s.%s' % ( self.config['transport_name'], safe_routing_key(self.config['ussd_code']), ), self.consume_message)
def startWorker(self): """docstring for startWorker""" self.publisher = yield self.publish_to( 'ussd.outbound.%(transport_name)s' % self.config) self.twitter = twitter.Twitter(self.config['username'], self.config['password']) self.consumer = yield self.consume('ussd.inbound.%s.%s' % ( self.config['transport_name'], safe_routing_key(self.config['ussd_code']), ), self.consume_message)
def startWorker(self): """docstring for startWorker""" self.games = {} self.open_game = None self.publisher = yield self.publish_to( 'ussd.outbound.%(transport_name)s' % self.config) self.consumer = yield self.consume('ussd.inbound.%s.%s' % ( self.config['transport_name'], safe_routing_key(self.config['ussd_code']) ), self.consume_message)
def render_POST(self, request): content = request.content.read() sms = utils.parse_post_event_xml(content) self.publisher.publish_message(Message(**{ 'to_msisdn': sms['Local'], 'from_msisdn': sms['Remote'], 'message': sms['Text'], 'transport_name': 'Opera', 'received_at': iso8601.parse_date(sms['ReceiveDate']) }), routing_key='sms.inbound.opera.%s' % safe_routing_key( sms['Local'])) request.setResponseCode(http.OK) request.setHeader('Content-Type', 'text/xml; charset=utf8') return content
def startWorker(self): """Start the worker""" # Connect to Redis self.r_server = redis.Redis("localhost", db=get_deploy_int(self._amqp_client.vhost)) log.msg("Connected to Redis") self.r_prefix = "hangman:%s:%s" % ( self.config['transport_name'], safe_routing_key(self.config['ussd_code'])) log.msg("r_prefix = %s" % self.r_prefix) self.random_word_url = self.config['random_word_url'] log.msg("random_word_url = %s" % self.random_word_url) yield super(HangmanWorker, self).startWorker()