コード例 #1
0
    def get_next_avail_number(self):
        """
        Returns the next available number that we own. If none are available, buys it from Twilio.
        """
        area_code = int(self.conf['twilio_area_code'])
        numbers = [
            vbts_util.strip_number(str(n.phone_number))
            for n in self.twilio_client.phone_numbers.list()
        ]
        avail_numbers = vbts_util.get_next_avail_number(numbers)
        if (len(avail_numbers) == 0):
            # if we have none, get a new number
            new_numbers = self.twilio_client.phone_numbers.search(
                area_code=area_code)
            if not new_numbers:
                raise ValueError("No numbers available in area code %d" %
                                 area_code)
            num = new_numbers[0]
            if not num.purchase():  # this does the buy!
                raise ValueError("Purchasing number failed")
            # setup new number
            bought_num = self.twilio_client.phone_numbers.list(
                phone_number=num.phone_number)[0]
            bought_num.update(
                sms_url=self.conf['twilio_sms_url'],
                voice_url=self.conf['twilio_voice_url'],
                sms_fallback_url=self.conf['twilio_sms_fallback_url'],
                voice_method=self.conf['twilio_voice_method'],
                sms_method=self.conf['twilio_sms_method'],
                sms_fallback_method=self.conf['twilio_sms_fallback_method'])
            avail_numbers.append(
                vbts_util.strip_number(str(bought_num.phone_number)))

        return random.choice(avail_numbers)
コード例 #2
0
    def send(self, to, from_, body, to_country=None, from_country=None):
        """
        Send properly-formatted numbers to FreeSwitch
        """
	# Internally, our canonical format is E.164 without the leading plus
	# (due to OpenBTS's inability to handle the + symbol).
        if (to_country):
            to = vbts_util.convert_to_e164(to, to_country)
        if (from_country):
            from_ = vbts_util.convert_to_e164(from_, from_country)
        to = vbts_util.strip_number(to)
        from_ = vbts_util.strip_number(from_)
        return self._send_raw_to_freeswitch(to, from_, body)
コード例 #3
0
ファイル: vbts_fs.py プロジェクト: sikopet/vbts-plumbing
 def send(self, to, from_, body, to_country=None, from_country=None):
     """
     Send properly-formatted numbers to FreeSwitch
     """
     # Internally, our canonical format is E.164 without the leading plus
     # (due to OpenBTS's inability to handle the + symbol).
     if (to_country):
         to = vbts_util.convert_to_e164(to, to_country)
     if (from_country):
         from_ = vbts_util.convert_to_e164(from_, from_country)
     to = vbts_util.strip_number(to)
     from_ = vbts_util.strip_number(from_)
     return self._send_raw_to_freeswitch(to, from_, body)
コード例 #4
0
    def get_next_avail_number(self):
        """
        Returns the next available number that we own. If none are available, buys it from Twilio.
        """
        area_code = int(self.conf['twilio_area_code'])
        numbers = [vbts_util.strip_number(str(n.phone_number)) for n in self.twilio_client.phone_numbers.list()]
        avail_numbers = vbts_util.get_next_avail_number(numbers)
        if (len(avail_numbers) == 0):
            # if we have none, get a new number
            new_numbers = self.twilio_client.phone_numbers.search(area_code=area_code)
            if not new_numbers:
                raise ValueError("No numbers available in area code %d" % area_code)
            num = new_numbers[0]
            if not num.purchase(): # this does the buy!
                raise ValueError("Purchasing number failed")
            # setup new number
            bought_num = self.twilio_client.phone_numbers.list(phone_number=num.phone_number)[0]
            bought_num.update(sms_url=self.conf['twilio_sms_url'], voice_url=self.conf['twilio_voice_url'], sms_fallback_url=self.conf['twilio_sms_fallback_url'], voice_method=self.conf['twilio_voice_method'], sms_method=self.conf['twilio_sms_method'], sms_fallback_method=self.conf['twilio_sms_fallback_method'])
            avail_numbers.append(vbts_util.strip_number(str(bought_num.phone_number)))

        return random.choice(avail_numbers)
コード例 #5
0
 def get_next_avail_number(self):
     """
     Returns the next available number that we own. If none are available, buys it from nexmo.
     """
     area_code = int(self.conf['twilio_area_code'])
     numbers = [vbts_util.strip_number(str(n)) for n in self.__get_existing_numbers()]
     avail_numbers = vbts_util.get_next_avail_number(numbers)
     if (len(avail_numbers) == 0):
         target = self.__search_numbers()
         if (self.__buy_number(target)):
             avail_numbers.append(str(target))
         else:
             raise ValueError("Purchasing number failed")
     return random.choice(avail_numbers)