def execute(self,user,access,irc_msg): m=self.commandre.search(irc_msg.command) if not m: return 0 if access < self.level: irc_msg.reply("You do not have enough access to use this command") return 0 username = self.config.get("clickatell", "user") password = self.config.get("clickatell", "pass") api_id = self.config.get("clickatell", "api") ct = Clickatell(username, password, api_id) if not ct.auth(): irc_msg.reply("Could not authenticate with server. Super secret message not sent.") return 1 balance = ct.getbalance() if not balance: reply="Help me help you. I need the kwan. SHOW ME THE MONEY" else: reply="Current kwan balance: %d"%(float(balance),) irc_msg.reply(reply) return 1
def sms(message, subscriber='John'): ''' Sends an SMS message through ClickaTell gateway. Example: sms("Hello") Example: sms("Hello", 'Carl') @param param1: SMS Text @param param2: Subscriber. A numeric phone number or a subscriber (String) ''' log = logging.getLogger(LOG_PREFIX) ClickatellSender = '45123456789' ClickatellAPIUser = '******' ClickatellAPIPassw = 'riuyYGVTua8k' ClickatellAPIId = 1234567 phoneNumbers = { 'Anna': '467395646546', 'Veronica': '461565136511' } phoneNumber = phoneNumbers.get(subscriber, None) if phoneNumber is None: if subscriber.isdigit(): phoneNumber = subscriber else: log.error("Invalid subscriber") return gateway = Clickatell(ClickatellAPIUser, ClickatellAPIPassw, ClickatellAPIId, ClickatellSender) message = {'to': phoneNumber, 'text': message} log.info("Sending SMS to: " + str(phoneNumber)) retval, msg = gateway.sendmsg(message) if retval == True: log.info("SMS Sent: " + msg) else: log.error("Error while sending SMS: " + str(retval)) return
def execute(self,user,access,irc_msg): m=irc_msg.match_command(self.commandre) if not m: return 0 if access < self.level: irc_msg.reply("You do not have enough access to use this command") return 0 m=self.paramre.search(m.group(1)) if not m: irc_msg.reply("Usage: %s" % (self.usage,)) return 0 u=self.load_user(user,irc_msg) if not u: return 1 rec = m.group(1) public_text = m.group(2) + ' - %s' % (user,) text = public_text + '/%s' %(u.phone,) receiver=self.load_user_from_pnick(rec) if not receiver: irc_msg.reply("Who exactly is %s?" % (rec,)) return 1 if receiver.pnick.lower() == 'valle': irc_msg.reply("I refuse to talk to that Swedish clown. Use !phone show Valle and send it using your own phone.") return results=self.phone_query_builder(receiver,"AND t1.friend_id=%s",(u.id,)) if not (receiver.pubphone or len(results)>0): irc_msg.reply("%s's phone number is private or they have not chosen to share their number with you. Supersecret message not sent." % (receiver.pnick,)) return 1 phone = self.prepare_phone_number(receiver.phone) if not phone or len(phone) <= 6: irc_msg.reply("%s has no phone number or their phone number is too short to be valid (under 6 digits). Super secret message not sent." % (receiver.pnick,)) return 1 if len(text) >= 160: irc_msg.reply("Max length for a text is 160 characters. Your text was %i characters long. Super secret message not sent." % (len(text),)) return 1 username = self.config.get("clickatell", "user") password = self.config.get("clickatell", "pass") api_id = self.config.get("clickatell", "api") ct = Clickatell(username, password, api_id) if not ct.auth(): irc_msg.reply("Could not authenticate with server. Super secret message not sent.") return 1 hasher = md5() hasher.update(phone) hasher.update(text) msg_id = hasher.hexdigest() message = { 'to': str(phone), 'sender': "Munin", 'text': str(text), 'climsgid': str(msg_id), 'msg_type': 'SMS_TEXT' } ret = ct.sendmsg(message) if not ret[0]: irc_msg.reply("That wasn't supposed to happen. I don't really know what wrong. Maybe your mother dropped you.") return 1 reply="Successfully processed To: %s Message: %s" if irc_msg.chan_reply(): irc_msg.reply(reply % (receiver.pnick,public_text)) else: irc_msg.reply(reply % (receiver.pnick,text)) self.log_message(u.id,receiver.id,phone, public_text) return 0
import sys, os sys.path.append("/var/projects") os.environ["DJANGO_SETTINGS_MODULE"] = "mednet.settings" from mednet import settings from clickatell import Clickatell gateway = Clickatell(settings.CLICKATELL_USER, settings.CLICKATELL_PASS, settings.CLICKATELL_API_ID) message = {"to": "573008438443", "text": "can you send a test msg to +15597152722"} retval, msg = gateway.sendmsg(message) if retval == 0: print "ok" else: print msg