def send_sms_nexmo(mobile_number, message): if (is_phone_number(mobile_number)): req = "json" key = SMS_NEXMO_KEY secret = SMS_NEXMO_SECRET sender = settings.SMS_SENDER msg = {'reqtype': req, 'password': secret, 'from': sender, 'to': mobile_number, 'text': smart_str(message), 'username': key} sms = NexmoMessage(msg) sms.send_request() logger.info("SMS Sent. Number = {0}".format(mobile_number)) else: logger.error("SMS not sent - Invalid phone number Number = {0}".format(mobile_number))
def _sendSMS(self, message, phone): msg = { 'reqtype': 'json', 'api_key': self._NEXMO_API_KEY, 'api_secret': self._NEXMO_API_SECRET, 'from': self._NEXMO_SMS_FROM, 'to': phone, 'text': message } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) sms.send_request()
def send_sms(from_, text): for number in sms_numbers: msg = { 'reqtype': 'json', 'api_key': nexmo_key, 'api_secret': nexmo_secret, 'from': from_, 'to': number, 'text': text } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) print msg sms.send_request()
def _send_nexmo_sms(self): print 'SEND NEXMO MESSAGE' to = self.phone if to: reqtype = 'json' api_secret = settings.NEXMO_API_SECRET _from = 'truongnha sms sender' api_key = settings.NEXMO_API_KEY message = self.content msg = { 'reqtype': reqtype, 'api_secret': api_secret, 'from': _from, 'to': '+' + to, 'api_key': api_key, } temp = NexmoMessage(msg) temp.set_text_info(message) print "DETAIL: ", temp.get_details() response = temp.send_request() sms_status = response['messages'][0]['status'] print 'SMS STATUS: ', sms_status if sms_status == 0 or sms_status == '0': return '1' elif sms_status == 1 or sms_status == '1': return '0' else: return sms_status else: raise Exception('InvalidPhoneNumber')
def SendText(follow_user,tweet,phone): print follow_user print tweet message = '@'+follow_user+' just tweeted: '+tweet api_key = Config.objects.all().latest('id').nexmo_key api_secret = Config.objects.all().latest('id').nexmo_secret api_num = Config.objects.all().latest('id').nexmo_number msg = { 'reqtype': 'json', 'api_key': api_key, 'api_secret': api_secret, 'from': api_num, 'to': '1'+phone, 'text': message, } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) response = sms.send_request() if response: status = response['messages'][0]['status'] if status == '0': print 'Text Msg Sent Successfully' else: print 'Error: Problem sending text'
def SendMessageToPhone(phone_number, message): logging.debug("Sending message to phone %s with m=%s" % (phone_number, message)) msg = { "reqtype": "json", "api_secret": "8e7c547e", "from": "12069396660", "to": phone_number, "api_key": "4a08f329", } # text message msg["text"] = message sms1 = NexmoMessage(msg) print ("SMS details: %s") % sms1.get_details() sms1.set_text_info(message) print ("SMS details: %s") % sms1.get_details() print sms1.send_request()
def _register_sms(self, n): # validate phone number syntax if not n or len(n.strip()) == 0: log.debug("number empty - %s" % n) return c2s.RegistrationResponse.STATUS_INVALID_USERNAME phone = phone_num = n.strip() # exclude the initial plus to verify the digits if (phone[0] == '+'): phone_num = phone[1:] # not all digits... if not phone_num.isdigit(): log.debug("number is not all-digits - %s" % phone_num) return c2s.RegistrationResponse.STATUS_INVALID_USERNAME # replace double-zero with plus if phone[0:2] == '00': phone = '+' + phone[2:] # insert validation record # TODO do not use directly - let the storage module do it valdb = database.validations(self.broker.db) userid = utils.sha1(phone) # throttling :P if valdb.get_code(userid, True): return c2s.RegistrationResponse.STATUS_THROTTLING userid += utils.rand_str(8, utils.CHARSBOX_AZN_UPPERCASE) ret = valdb.update(userid) if ret[0] > 0: # send SMS code = ret[1] sms_from = self.config['registration']['from'] if self.config['registration']['android_emu']: # android emulation import os os.system('adb emu sms send %s %s' % (sms_from, code)) else: # send sms from nexmomessage import NexmoMessage msg = { 'reqtype' : 'json', 'username' : self.config['registration']['nx.username'], 'password': self.config['registration']['nx.password'], 'from': sms_from, 'to': phone } sms = NexmoMessage(msg) # FIXME send just the code for now sms.set_text_info(code) js = sms.send_request() log.debug("sms sent [response=%s]" % js) return c2s.RegistrationResponse.STATUS_CONTINUE else: return c2s.RegistrationResponse.STATUS_ERROR
def _register_sms(self, n): # validate phone number syntax if not n or len(n.strip()) == 0: log.debug("number empty - %s" % n) return c2s.RegistrationResponse.STATUS_INVALID_USERNAME phone = phone_num = n.strip() # exclude the initial plus to verify the digits if (phone[0] == '+'): phone_num = phone[1:] # not all digits... if not phone_num.isdigit(): log.debug("number is not all-digits - %s" % phone_num) return c2s.RegistrationResponse.STATUS_INVALID_USERNAME # replace double-zero with plus if phone[0:2] == '00': phone = '+' + phone[2:] # insert validation record # TODO do not use directly - let the storage module do it valdb = database.validations(self.broker.db) userid = utils.sha1(phone) # throttling :P if valdb.get_code(userid, True): return c2s.RegistrationResponse.STATUS_THROTTLING userid += utils.rand_str(8, utils.CHARSBOX_AZN_UPPERCASE) ret = valdb.update(userid) if ret[0] > 0: # send SMS code = ret[1] sms_from = self.config['registration']['from'] if self.config['registration']['android_emu']: # android emulation import os os.system('adb emu sms send %s %s' % (sms_from, code)) else: # send sms from nexmomessage import NexmoMessage msg = { 'reqtype': 'json', 'username': self.config['registration']['nx.username'], 'password': self.config['registration']['nx.password'], 'from': sms_from, 'to': phone } sms = NexmoMessage(msg) # FIXME send just the code for now sms.set_text_info(code) js = sms.send_request() log.debug("sms sent [response=%s]" % js) return c2s.RegistrationResponse.STATUS_CONTINUE else: return c2s.RegistrationResponse.STATUS_ERROR
def main(): r = "json" u = "changeme" p = "changeme" f = "marcuz" t = "39**********" m = "fool the reader àèìòù !!!" msg = {'reqtype': r, 'api_secret': p, 'from': f, 'to': t, 'api_key': u} tts = copy.deepcopy(msg) # account balance req = {'api_secret': p, 'api_key': u, 'type': 'balance'} print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print # my numbers req = {'api_secret': p, 'api_key': u, 'type': 'numbers'} print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print # pricing for country 'NL' req['type'] = 'pricing' req['country'] = 'NL' print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() # text message msg['text'] = m sms1 = NexmoMessage(msg) print("SMS details: %s") % sms1.get_details() m += " ktnxbye" sms1.set_text_info(m) print("SMS details: %s") % sms1.get_details() print sms1.send_request() tts['text'] = "Welcome to Nexmo T T S service." tts1 = NexmoTTS(tts) print("TTS Details: %s") % (tts1.get_details()) print tts1.send_request()
def main(): r = "json" u = "changeme" p = "changeme" f = "marcuz" t = "+39**********" m = "fool the reader àèìòù !!!" bb = "0011223344556677" bu = "06050415811581" msg = {'reqtype': r, 'api_secret': p, 'from': f, 'to': t, 'api_key': u} # account balance req = {'api_secret': p, 'api_key': u, 'type': 'balance'} print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print # my numbers req = {'api_secret': p, 'api_key': u, 'type': 'numbers'} print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print # pricing for country 'NL' req['type'] = 'pricing' req['country'] = 'NL' print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() # text message msg['text'] = m sms1 = NexmoMessage(msg) print("SMS details: %s") % sms1.get_details() m += " ktnxbye" sms1.set_text_info(m) print("SMS details: %s") % sms1.get_details() print sms1.send_request()
def sendSms(liste): print "sender sms" a="Det har kommer nye karakter på studentweb:\n\n" liste = liste[3:6] for f*g in liste: points = f*g[3].encode("iso-8859-1") if points == "": points="0,0" a = a + f*g[0].encode("iso-8859-1")+"-"+f*g[1].encode("iso-8859-1")+":\n Grade: " + f*g[2].encode("iso-8859-1") + "\n Points: " + points +"\n" text = a.decode("iso-8859-1") print text msg = { 'reqtype': 'json', 'api_key': "dinNøkkel", 'api_secret': "dinapihemmelighet", 'from': "MiSide", 'to': "mobilnummer", 'text': text } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) sms.send_request()
def send_report(self): if (self.pattern.send_sms and self.pattern.nexmo_api_key and self.pattern.nexmo_secret_key and self.pattern.sms_from_number and self.pattern.sms_report_numbers): context = {'feedback': self, 'site': Site.objects.get_current()} body = render_to_string('spicy.feedback/sms/report.txt', context) for number in self.pattern.sms_report_numbers.splitlines(): if not number.strip(): continue text = body[:140].encode('utf-8') msg = { 'reqtype': 'json', 'api_key': self.pattern.nexmo_api_key, 'api_secret': self.pattern.nexmo_secret_key, 'from': self.pattern.sms_from_number, 'to': number, 'text': text } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) sms.sms['type'] = 'unicode' sms.send_request()
def send_sms(self, number, code): msg = { 'reqtype': 'json', 'username': self.config['nx.username'], 'password': self.config['nx.password'], 'from': self.config['from'], 'to': number, } sms = NexmoMessage(msg) # FIXME send just the code for now sms.set_text_info(code) response = sms.send_request() log.debug("sms sent [response=%s]" % response) return (response and int(response['message-count']) == 1 and int(response['messages'][0]['status']) == 0)
def send_sms(self, number, code): msg = { 'reqtype' : 'json', 'username' : self.config['nx.username'], 'password': self.config['nx.password'], 'from': self.config['from'], 'to': number, } sms = NexmoMessage(msg) # FIXME send just the code for now sms.set_text_info(code) response = sms.send_request() log.debug("sms sent [response=%s]" % response) return (response and int(response['message-count']) == 1 and int(response['messages'][0]['status']) == 0)
def send(self, to, from_, body, to_country=None, from_country=None): """ Send an SMS to Nexmo. Returns true if the message was accepted, false otherwise. """ # Convert "to" to e.164 format. We always add a plus, and # libphonenumber is smart enough to sort it out from there (even if # there's already a plus). to = vbts_util.convert_to_e164("+" + to, None) msg = {'reqtype': 'json', 'password': self.pw, 'from': from_, 'to': to, 'username': self.un} sms = NexmoMessage(msg) sms.set_text_info(body) res = sms.send_request() #we're basically creating aformatting AND here for readability if (res['message-count'] == '1'): if (res['messages'][0]['status'] == '0'): return True return False
def send(self, to, from_, body, to_country=None, from_country=None): """Send an SMS to Nexmo. Returns: True if the message was accepted, False otherwise. """ # The Nexmo client can't send an empty string, so instead send a space. if len(body) == 0: body = ' ' msg = { 'username': self.username, 'password': self.password, 'reqtype': 'json', 'from': from_, 'to': to } sms = NexmoMessage(msg) sms.set_text_info(body) res = sms.send_request() return (res['message-count'] == '1' and res['messages'][0]['status'] == '0')
def send_sms(number, message, msg_type = "text"): if config.DEBUG_SMS: print("SMS DEBUG:\n%s\nfrom: %s\n===========" % (message, number)) return msg = { 'reqtype': 'json', 'api_key': config.NEXMO_API_KEY, 'api_secret': config.NEXMO_API_SECRET, 'from': config.NEXMO_PHONE_NO, 'to': number, 'text': message, 'type': msg_type } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) response = sms.send_request() if not response: logger.error("[NEXMO] Failed to send response: %s [to] %s" % (message, number)) print "Failed to send response" if config.LOG_MESSAGES: mlogger.log_message(number, message, mlogger.MessageDirection.OUTBOUND)
def send_sms(number, message, msg_type="text"): if config.DEBUG_SMS: print("SMS DEBUG:\n%s\nfrom: %s\n===========" % (message, number)) return msg = { 'reqtype': 'json', 'api_key': config.NEXMO_API_KEY, 'api_secret': config.NEXMO_API_SECRET, 'from': config.NEXMO_PHONE_NO, 'to': number, 'text': message, 'type': msg_type } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) response = sms.send_request() if not response: logger.error("[NEXMO] Failed to send response: %s [to] %s" % (message, number)) print "Failed to send response" if config.LOG_MESSAGES: mlogger.log_message(number, message, mlogger.MessageDirection.OUTBOUND)
def main(): r = "json" u = "changeme" p = "changeme" f = "marcuz" t = "+39**********" m = "fool the reader àèìòù !!!" bb = "0011223344556677" bu = "06050415811581" msg = {'reqtype': r, 'password': p, 'from': f, 'to': t, 'username': u} # account balance req = {'password': p, 'username': u, 'type': 'balance'} print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print # my numbers req = {'password': p, 'username': u, 'type': 'numbers'} print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print # pricing for country 'NL' req['type'] = 'pricing' req['country'] = 'NL' print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print sys.exit() # text message msg['text'] = m sms1 = NexmoMessage(msg) print("SMS details: %s") % sms1.get_details() m += " ktnxbye" sms1.set_text_info(m) print("SMS details: %s") % sms1.get_details() print sms1.send_request() print # bin message sms2 = NexmoMessage(msg) sms2.set_bin_info(bb, bu) print("SMS details: %s") % sms2.get_details() print sms2.send_request() print # wap message msg['title'] = "this is a test" msg['url'] = "http://twitter.com/tmarcuz" msg['text'] = False sms3 = NexmoMessage(msg) print("SMS details: %s") % sms3.get_details() print sms3.send_request()
from nexmomessage import NexmoMessage msg = { 'reqtype': 'json', 'api_key': '47bcdeb1', 'api_secret': 'd6be33eb', 'from': '19705500043', 'to': '+15803998205', 'text': 'Hello world! Michelle says hi' } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) response = sms.send_request() if response: # do something with response data print('worked') else: # handle the error print('nope')
from nexmomessage import NexmoMessage API_KEY = '67ac5f35' API_SECRET = '420b4115' DESTINATION_NUMBER = '16302071793' YOUR_NUMBER = '14844409627' msg = { 'reqtype': 'json', 'api_key': API_KEY, 'api_secret': API_SECRET, 'from': YOUR_NUMBER, 'to': DESTINATION_NUMBER, 'text': 'marshall' } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) res = sms.send_request() if res: print res print 'response' else: print res
from nexmomessage import NexmoMessage API_KEY = '67ac5f35' API_SECRET = '420b4115' DESTINATION_NUMBER = '16302071793' YOUR_NUMBER = '14844409627' msg = { 'reqtype':'json', 'api_key':API_KEY, 'api_secret':API_SECRET, 'from':YOUR_NUMBER, 'to':DESTINATION_NUMBER, 'text':'marshall' } sms = NexmoMessage(msg) sms.set_text_info(msg['text']) res = sms.send_request() if res: print res print 'response' else: print res
def main(function, args): tmp = args args = {} for arg in tmp: if (':' not in arg): print ("Malformed arg:" + arg) exit(1) s = arg.split(":") args[s[0]] = s[1] r = "json" u = "XXXXXXXX" p = "XXXXXXXX" f = "444444444444" t = "444444444444" m = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(20)) if ('key' in args): u = args['key'] if ('pass' in args): p = args['pass'] if ('to' in args): t = args['to'] if ('from' in args): f = args['from'] if ('message' in args): m = args['message'] msg = {'reqtype': r, 'password': p, 'from': f, 'to': t, 'username': u} req = {'password': p, 'username': u} if (function == "balance"): # account balance req['type'] = 'balance' print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() elif (function == "numbers"): # my numbers req['type'] = 'numbers' print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() elif (function == "pricing"): # pricing for country 'NL' req['type'] = 'pricing' req['country'] = args['country'] print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() elif (function == "search"): # searching for numbers for country 'NL' req['type'] = 'search' req['country'] = args['country'] print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() elif (function == "buy"): # buying number for country req['type'] = 'buy' req['country'] = args['country'] req['msisdn'] = args['msisdn'] print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() elif function == 'cancel': # Canceling an inbound number subscription. req['type'] = 'cancel' req['country'] = args['country'] req['msisdn'] = args['msisdn'] print("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() elif (function == "message"): # text message sms1 = NexmoMessage(msg) sms1.set_text_info(m) print("SMS details: %s") % sms1.get_details() print sms1.send_request() elif (function == "binary"): # bin message sms2 = NexmoMessage(msg) sms2.set_bin_info(bb, bu) print("SMS details: %s") % sms2.get_details() print sms2.send_request() elif (function == "wap"): # wap message msg['title'] = "this is a test" msg['url'] = "http://twitter.com/tmarcuz" msg['text'] = False sms3 = NexmoMessage(msg) print("SMS details: %s") % sms3.get_details() print sms3.send_request()
def main(): r = "json" u = "changeme" p = "changeme" f = "marcuz" t = "+39**********" m = "fool the reader àèìòù !!!" bb = "0011223344556677" bu = "06050415811581" msg = {"reqtype": r, "password": p, "from": f, "to": t, "username": u} # account balance req = {"password": p, "username": u, "type": "balance"} print ("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print # my numbers req = {"password": p, "username": u, "type": "numbers"} print ("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print # pricing for country 'NL' req["type"] = "pricing" req["country"] = "NL" print ("request details: %s") % NexmoMessage(req).get_details() print NexmoMessage(req).send_request() print sys.exit() # text message msg["text"] = m sms1 = NexmoMessage(msg) print ("SMS details: %s") % sms1.get_details() m += " ktnxbye" sms1.set_text_info(m) print ("SMS details: %s") % sms1.get_details() print sms1.send_request() print # bin message sms2 = NexmoMessage(msg) sms2.set_bin_info(bb, bu) print ("SMS details: %s") % sms2.get_details() print sms2.send_request() print # wap message msg["title"] = "this is a test" msg["url"] = "http://twitter.com/tmarcuz" msg["text"] = False sms3 = NexmoMessage(msg) print ("SMS details: %s") % sms3.get_details() print sms3.send_request()