def run(self, pk): received_sms = ReceivedSMS.objects.get(pk=pk) keys_and_values = received_sms.as_tuples() profile = received_sms.user.get_profile() urlcallback_set = profile.urlcallback_set.filter(name='sms_received') resp = [callback(urlcallback.url, keys_and_values) for urlcallback in urlcallback_set] return resp
def send_sms(self, smsc, sender, recipients, text): """ We mimick a FORM post to the given URL and get back an HTML table. Got this from http://site.demoru.com/?page_id=27 HTTP 200 OK Date Thu: 03 Jun 2010 18:32:15 GMT Connection Close Transfer-Encoding chunked Content-Type text/html; charset=UTF-8 <table class="widefat" border="0"> <thead> <tr> <th>from</th> <th>to</th> <th>smsc</th> <th>status</th> <th>text</th> </tr> </thead> <tbody> <tr> <td>+35566</td> <td>+44778962937</td> <td>ESC-P1Celtel</td> <td>0: Accepted for delivery</td> <td> http://www.mobi-fee.com/link/g.lnk?ID=135</td> </tr> </tbody> <tfoot> <tr> <th>from</th> <th>to</th> <th>smsc</th> <th>status</th> <th>text</th> </tr> </tfoot> </table> """ if not all([msisdn.startswith('+') for msisdn in recipients]): raise E_ScapeException, 'All msisdns should start with a +' kwargs = { 's': sender, 'r': ','.join(recipients), 'text': text, 'smsc': smsc, 'api_id': self.api_id, 'send': 'go' # apparently the form submission key } return parse_response(callback(self.gateway_url, kwargs.items()))
def call_for_json(self, MSISDN): if self.data_url['url']: params = [(self.data_url['params'][0], str(MSISDN))] url = self.data_url['url'] auth_string = '' if self.data_url['username']: auth_string += self.data_url['username'] if self.data_url['password']: auth_string += ":" + self.data_url['password'] auth_string += "@" resp_url, resp = utils.callback("http://" + auth_string + url, params) return resp return None
def post_back_json(self, MSISDN): session = getVumiSession(self.r_server, self.routing_key + '.' + MSISDN) if session and session.get_decision_tree(): json_string = json.dumps(session.get_decision_tree().get_data()) if self.post_url['url']: params = [(self.post_url['params'][0], json_string)] url = self.post_url['url'] auth_string = '' if self.post_url['username']: auth_string += self.post_url['username'] if self.post_url['password']: auth_string += ":" + self.post_url['password'] auth_string += "@" resp_url, resp = utils.callback("http://" + auth_string + url, params) return resp return None
def consume_message(self, message): dictionary = message.payload # specify a user per campaign user = User.objects.get(username=self.config['username']) profile = user.get_profile() urlcallback_set = profile.urlcallback_set.filter(name='sms_received') for urlcallback in urlcallback_set: try: params = [ ("callback_name", "sms_received"), ("to_msisdn", str(dictionary.get('destination_addr'))), ("from_msisdn", str(dictionary.get('source_addr'))), ("message", str(dictionary.get('short_message'))) ] url, resp = utils.callback(urlcallback.url, params) log.msg('RESP: %s' % repr(resp)) except Exception, e: log.err(e)
def consume_message(self, message): dictionary = message.payload to_msisdn = dictionary.get('destination_addr') from_msisdn = dictionary.get('source_addr') message = dictionary.get('short_message') log.msg('dictionary', dictionary) try: params = [ ("callback_name", "sms_received"), ("to_msisdn", str(to_msisdn)), ("from_msisdn", str(from_msisdn)), ("message", str(message)) ] url, resp = utils.callback(self.config.get('POST_TO_URL'), params) log.msg('RESP: %s' % repr(resp)) # create a new message to be sent out, it needs to be linked # to a User for accounting purposes user, created = User.objects.get_or_create( username=self.config.get('USER_ACCOUNT')) batch = SentSMSBatch.objects.create(title='', user=user) sms = batch.sentsms_set.create(user=user, to_msisdn=from_msisdn, from_msisdn=to_msisdn, transport_name=self.config.get('TRANSPORT_NAME'), message=resp, ) self.publisher.publish_message( Message( id=sms.pk, to_msisdn=sms.to_msisdn, message=sms.message, from_msisdn=sms.from_msisdn, ), routing_key='sms.outbound.%s.%s' % ( self.config.get('TRANSPORT_NAME'), sms.to_msisdn ) ) except Exception, e: log.err(e)
def list_bindings(self): try: # Note utils.callback() does a POST not a GET # which may lead to errors if the RabbitMQ Management REST api # changes url, resp = utils.callback( "http://%s:%s@localhost:55672/api/bindings" % ( self.vumi_options['username'], self.vumi_options['password']), []) bindings = json.loads(resp) bound_routing_keys = {} for b in bindings: if (b['vhost'] == self.vumi_options['vhost'] and b['source'] == self.exchange_name): bound_routing_keys[b['routing_key']] = \ bound_routing_keys.get(b['routing_key'], []) + \ [b['destination']] except: bound_routing_keys = {"bindings": "undetected"} return bound_routing_keys
def run(self, pk, receipt): sent_sms = SentSMS.objects.get(pk=pk) profile = sent_sms.user.get_profile() urlcallback_set = profile.urlcallback_set.filter(name='sms_receipt') return [callback(urlcallback.url, receipt.entries()) for urlcallback in urlcallback_set]