def _send_fax(self, subject, body, comm): """Send the message as a fax""" api = PhaxioApi( settings.PHAXIO_KEY, settings.PHAXIO_SECRET, raise_errors=True, ) files = [f.ffile for f in comm.files.all()] callback_url = 'https://%s%s' % ( settings.MUCKROCK_URL, reverse('phaxio-callback'), ) api.send(to=self.email, header_text=subject[:50], string_data=body, string_data_type='text', files=files, batch=True, batch_delay=settings.PHAXIO_BATCH_DELAY, batch_collision_avoidance=True, callback_url=callback_url, **{'tag[comm_id]': comm.pk}) comm.delivered = 'fax'
def send_fax(comm_id, subject, body, **kwargs): """Send a fax using the Phaxio API""" api = PhaxioApi( settings.PHAXIO_KEY, settings.PHAXIO_SECRET, raise_errors=True, ) try: comm = FOIACommunication.objects.get(pk=comm_id) except FOIACommunication.DoesNotExist as exc: send_fax.retry( countdown=300, args=[comm_id, subject, body], kwargs=kwargs, exc=exc, ) files = [f.ffile for f in comm.files.all()] callback_url = 'https://%s%s' % ( settings.MUCKROCK_URL, reverse('phaxio-callback'), ) try: results = api.send(to=comm.foia.email, header_text=subject[:45], string_data=body, string_data_type='text', files=files, batch=True, batch_delay=settings.PHAXIO_BATCH_DELAY, batch_collision_avoidance=True, callback_url=callback_url, **{'tag[comm_id]': comm.pk}) except PhaxioError as exc: logger.error( 'Send fax error, will retry: %s', exc, exc_info=sys.exc_info(), ) send_fax.retry( countdown=300, args=[comm_id, subject, body], kwargs=kwargs, exc=exc, ) comm.delivered = 'fax' comm.fax_id = results['faxId'] comm.save()
def setUp(self): self.client = PhaxioApi('TEST_API_KEY', 'TEST_API_SECRET') self.request = None # this will cause all API requests to get routed to request_callback, which just returns empty reponses # and saves the request in self.request so it can be validated url_re = re.compile(r'/v2/.*', flags=re.UNICODE) responses_urllib.add_callback('GET', url_re, callback=self.request_callback) responses_urllib.add_callback('POST', url_re, callback=self.request_callback) responses_urllib.add_callback('DELETE', url_re, callback=self.request_callback) responses_requests.add_callback('POST', url_re, callback=self.request_callback) responses_requests.add_callback('GET', url_re, callback=self.request_callback) responses_requests.add_callback('DELETE', url_re, callback=self.request_callback)
def sendfax(): user_obj=session.get('user', None) username = ''.join(random.choice('0123456789ABCDEF') for i in range(16)) token = getVidyoIOToken(username) user_obj[u'token'] = token api = PhaxioApi("9ypqp9sv1nwwmrq7hn7u3ou26ljoi4xzoavsp74o", "lkpmjrcv730w4m3w7pitaowp6copk77gudi0jyhq") response = api.Fax.send(to=['4412345671'], files='app/send.doc') return render_template('index.html',user=user_obj)
def send_fax(phone_number: str, filename: str) -> SendFaxResponse: api_key_dict = None if not os.path.exists("phaxio_key.json"): print("phaxio_key.json is not found!") exit(1) else: with open("phaxio_key.json", "r") as phaxio_key_obj: api_key_dict = json.loads(phaxio_key_obj.read()) phaxio = PhaxioApi(api_key_dict["api_key"], api_key_dict["api_secret"]) return phaxio.Fax.send(to=phone_number, files=filename)
def send_fax(comm_id, subject, body, error_count, **kwargs): """Send a fax using the Phaxio API""" api = PhaxioApi( settings.PHAXIO_KEY, settings.PHAXIO_SECRET, raise_errors=True, ) try: comm = FOIACommunication.objects.get(pk=comm_id) except FOIACommunication.DoesNotExist as exc: send_fax.retry( countdown=300, args=[comm_id, subject, body, error_count], kwargs=kwargs, exc=exc, ) files = [f.ffile for f in comm.files.all()] callback_url = '{}{}'.format( settings.MUCKROCK_URL, reverse('phaxio-callback'), ) fax = FaxCommunication.objects.create( communication=comm, sent_datetime=timezone.now(), to_number=comm.foia.fax, ) try: results = api.send(to=comm.foia.fax.as_e164, header_text=subject[:45], string_data=body, string_data_type='text', files=files, batch=True, batch_delay=settings.PHAXIO_BATCH_DELAY, batch_collision_avoidance=True, callback_url=callback_url, **{ 'tag[fax_id]': fax.pk, 'tag[error_count]': error_count, }) fax.fax_id = results['faxId'] fax.save() except PhaxioError as exc: FaxError.objects.create( fax=fax, datetime=timezone.now(), recipient=comm.foia.fax, error_type='apiError', error_code=exc.args[0], ) fatal_errors = { ('Phone number is not formatted correctly or invalid. ' 'Please check the number and try again.'), } if exc.args[0] in fatal_errors: comm.foia.fax.status = 'error' comm.foia.fax.save() ReviewAgencyTask.objects.ensure_one_created( agency=comm.foia.agency, resolved=False, ) else: logger.error( 'Send fax error, will retry: %s', exc, exc_info=sys.exc_info(), ) send_fax.retry( countdown=300, args=[comm_id, subject, body, error_count], kwargs=kwargs, exc=exc, )
def send_fax(key, secret, fax_number, filename): #The Phaxio rate limit is 1 request per second #See https://www.phaxio.com/faq time.sleep(1.5) api = PhaxioApi(key, secret) response = api.Fax.send(to=fax_number, files=filename)
from phaxio import PhaxioApi import os import uuid phaxio_api_key = os.environ.get('PHAXIO_API_KEY') phaxio_api_secret = os.environ.get('PHAXIO_API_SECRET') health_fax_number = os.environ.get('HEALTH_FAX_NUMBER') api = PhaxioApi(phaxio_api_key, phaxio_api_secret) api.health_fax_number = health_fax_number def create_header_string(): return ("Youth Application for Vaccination Records") def create_intro_string(): return ("This is a fax generated by VaxFax, " "a service built by Code for America " "Fellows for the Kansas City, Missouri " "Health Department. If you have any " "questions, please contact us at " "[email protected]. Additionally, " "if you have any feedback, we'd love to " "hear from you.\n\nRequest Information:\n") def create_legal_string(requestor_name: str, child_name: str) -> str: return ("\n\n\nThis confirms that the requestor, " "{0}, has agreed to the terms and conditions "
#GOOD JOB IT LOOKS LIKE YOUR RATINGS ARE GOING UP! :) --- OH NO - IT SEEMS THAT YOUR AVERAGE STAR RATING IS FALLING :'( import csv, urllib, time, json, datetime from phaxio import PhaxioApi from bs4 import BeautifulSoup import ap, numpy as np import yelp_scraper with open('credentials.json') as cfile: credentials = json.load(cfile) fax_api = PhaxioApi(credentials['key'], credentials['secret']) def send_fax(number, reviews, testing=False): """Concatenates and faxes reviews""" reviews = ["RATING: {0}/5.0\n{1}".format(r['rating'], r['content'].encode('utf-8')) for r in reviews] content = "CONGRATULATIONS YOU HAVE" if len(reviews) > 1: content += " NEW REVIEWS" else: content += " A NEW REVIEW" content += "\n\n" + "\n\n".join(reviews) if testing: # send to our test number print content #r = fax_api.send(to=['2129981898'], string_data=content, string_data_type='text') else: r = fax_api.send(to=[number], string_data=content, string_data_type='text')
def test_raise_errors_option(self): api = PhaxioApi(self.key, self.secret, raise_errors=False) response = api.send(to='invalid_number', string_data='test') self.assertFalse(response['success'])
def test_valid_request(self): api = PhaxioApi(self.key, self.secret, raise_errors=True) response = api.send(to='8138014253', string_data='test') self.assertTrue(response['success'])
def send_fax(comm_id, subject, body, **kwargs): """Send a fax using the Phaxio API""" api = PhaxioApi( settings.PHAXIO_KEY, settings.PHAXIO_SECRET, raise_errors=True, ) try: comm = FOIACommunication.objects.get(pk=comm_id) except FOIACommunication.DoesNotExist as exc: send_fax.retry( countdown=300, args=[comm_id, subject, body], kwargs=kwargs, exc=exc, ) files = [f.ffile for f in comm.files.all()] callback_url = 'https://%s%s' % ( settings.MUCKROCK_URL, reverse('phaxio-callback'), ) fax = FaxCommunication.objects.create( communication=comm, sent_datetime=datetime.now(), to_number=comm.foia.fax, ) try: results = api.send( to=comm.foia.fax.as_e164, header_text=subject[:45], string_data=body, string_data_type='text', files=files, batch=True, batch_delay=settings.PHAXIO_BATCH_DELAY, batch_collision_avoidance=True, callback_url=callback_url, **{'tag[fax_id]': fax.pk} ) except PhaxioError as exc: logger.error( 'Send fax error, will retry: %s', exc, exc_info=sys.exc_info(), ) FaxError.objects.create( fax=fax, datetime=datetime.now(), recipient=comm.foia.fax, error_type='apiError', error_code=exc.args[0], ) send_fax.retry( countdown=300, args=[comm_id, subject, body], kwargs=kwargs, exc=exc, ) fax.fax_id = results['faxId'] fax.save()
from phaxio import PhaxioApi testKey = '[Phaxio test key]' testSec = '[Phaxio test secret code]' liveKey = '[Phaxio live key]' liveSec = '[Phaxio live secret code]' name = 'recipient name' number = 'recipient fax number' files = [] for i in range(4): files.append(name + `i` + '.html') api = PhaxioApi(liveKey, liveSec) response = api.Fax.send(to=number, files=files) print(response.data.id)