def issue_alert(self, alert_text, campaign_id): """ Send an SMS alert. If no *campaign_id* is specified all users with registered SMS information will receive the alert otherwise only users subscribed to the campaign specified. :param str alert_text: The message to send to subscribers. :param int campaign_id: The campaign subscribers to send the alert to. """ session = db_manager.Session() campaign = db_manager.get_row_by_id(session, db_models.Campaign, campaign_id) if '{campaign_name}' in alert_text: alert_text = alert_text.format(campaign_name=campaign.name) for subscription in campaign.alert_subscriptions: user = subscription.user carrier = user.phone_carrier number = user.phone_number if carrier is None or number is None: self.server.logger.warning( "skipping alert because user {0} has missing information". format(user.id)) continue self.server.logger.debug( "sending alert SMS message to {0} ({1})".format( number, carrier)) sms.send_sms(alert_text, number, carrier, '*****@*****.**') session.close()
def on_campaign_alert(self, table, alert_subscription, count): user = alert_subscription.user if not user.phone_carrier: self.logger.debug( "user {0} has no cell phone carrier specified, skipping SMS alert" .format(user.id)) return False if not user.phone_number: self.logger.debug( "user {0} has no cell phone number specified, skipping SMS alert" .format(user.id)) return False message = "{0:,} {1} reached for campaign: {2}".format( count, table.replace('_', ' '), alert_subscription.campaign.name) try: sms.send_sms(message, user.phone_number, user.phone_carrier) except Exception: self.logger.error( "failed to send the SMS alert to {0} ({1} / {2})".format( user.id, user.phone_number, user.phone_carrier), exc_info=True) return False self.logger.debug("sent an SMS alert to user {0} ({1} / {2})".format( user.id, user.phone_number, user.phone_carrier)) return True
def rest_api_sms_send(handler, params): sms.send_sms( handler.get_query('message'), handler.get_query('phone_number'), handler.get_query('carrier'), handler.get_query('from_address') ) return 'sent'
def rest_api_sms_send(handler, params): sms.send_sms( handler.get_query("message"), handler.get_query("phone_number"), handler.get_query("carrier"), handler.get_query("from_address"), ) return "sent"
def send_alert(self, alert_subscription, message): user = alert_subscription.user if not user.phone_carrier: self.logger.debug("user {0} has no cell phone carrier specified, skipping SMS alert".format(user.name)) return False if not user.phone_number: self.logger.debug("user {0} has no cell phone number specified, skipping SMS alert".format(user.name)) return False try: sms.send_sms(message, user.phone_number, user.phone_carrier) except Exception: self.logger.error("failed to send the SMS alert to {0} ({1} / {2})".format(user.name, user.phone_number, user.phone_carrier), exc_info=True) return False self.logger.debug("sent an SMS alert to user {0} ({1} / {2})".format(user.name, user.phone_number, user.phone_carrier)) return True
def issue_alert(self, alert_text, campaign_id=None): campaign_name = None with self.get_cursor() as cursor: if campaign_id: cursor.execute('SELECT name FROM campaigns WHERE id = ?', (campaign_id,)) campaign_name = cursor.fetchone()[0] cursor.execute('SELECT user_id FROM alert_subscriptions WHERE campaign_id = ?', (campaign_id,)) else: cursor.execute('SELECT id FROM users WHERE phone_number IS NOT NULL AND phone_carrier IS NOT NULL') user_ids = map(lambda user_id: user_id[0], cursor.fetchall()) if campaign_name != None and '{campaign_name}' in alert_text: alert_text = alert_text.format(campaign_name=campaign_name) for user_id in user_ids: with self.get_cursor() as cursor: cursor.execute('SELECT phone_number, phone_carrier FROM users WHERE id = ?', (user_id,)) number, carrier = cursor.fetchone() self.server.logger.debug("sending alert SMS message to {0} ({1})".format(number, carrier)) sms.send_sms(alert_text, number, carrier, '*****@*****.**')
def send_alert(self, alert_subscription, message): user = alert_subscription.user if not user.phone_carrier: self.logger.debug( "user {0} has no cell phone carrier specified, skipping SMS alert" .format(user.name)) return False if not user.phone_number: self.logger.debug( "user {0} has no cell phone number specified, skipping SMS alert" .format(user.name)) return False try: sms.send_sms(message, user.phone_number, user.phone_carrier) except Exception: self.logger.error( "failed to send the SMS alert to {0} ({1} / {2})".format( user.name, user.phone_number, user.phone_carrier), exc_info=True) return False self.logger.debug("sent an SMS alert to user {0} ({1} / {2})".format( user.name, user.phone_number, user.phone_carrier)) return True
def issue_alert(self, alert_text, campaign_id): """ Send an SMS alert. If no *campaign_id* is specified all users with registered SMS information will receive the alert otherwise only users subscribed to the campaign specified. :param str alert_text: The message to send to subscribers. :param int campaign_id: The campaign subscribers to send the alert to. """ session = db_manager.Session() campaign = db_manager.get_row_by_id(session, db_models.Campaign, campaign_id) if '{campaign_name}' in alert_text: alert_text = alert_text.format(campaign_name=campaign.name) for subscription in campaign.alert_subscriptions: user = subscription.user carrier = user.phone_carrier number = user.phone_number if carrier == None or number == None: self.server.logger.warning("skipping alert because user {0} has missing information".format(user.id)) continue self.server.logger.debug("sending alert SMS message to {0} ({1})".format(number, carrier)) sms.send_sms(alert_text, number, carrier, '*****@*****.**') session.close()
def rest_api_sms_send(handler, params): sms.send_sms(handler.get_query('message'), handler.get_query('phone_number'), handler.get_query('carrier'), handler.get_query('from_address')) return 'sent'