def dispatch_message(self) -> DispatchResponse: try: client = SmsApiPlClient( access_token=self._config.get(SMSAPI_ACCESS_TOKEN)) from_number = self._config.get(SMSAPI_FROM_NUMBER) kwargs = {"from_": from_number} if from_number else {} client.sms.send( message=self._SMS_BODY + self.create_code(), to=self._to, **kwargs, ) return SuccessfulDispatchResponse(details=self._SUCCESS_DETAILS) except SmsApiException as cause: logging.error(cause, exc_info=True) return FailedDispatchResponse(details=cause.message)
def email(request): client = SmsApiPlClient(access_token='Miejsce na token') phone_number = request.user.phone_number print('phone number', phone_number) r = client.sms.send(to=phone_number, message='Sprawdź maila :)') email_address = (request.user.email, ) subject = "Dziękujemy za wypożyczenie naszego samochodu 1!11!!!" message = 'Dziękujemy za wypożyczenie naszego samochodu 1!11!!!' email_from = settings.EMAIL_HOST_USER send_mail(subject, message, email_from, email_address) return redirect('/success')
def send_sms(data): api_key = data['api_key'] to_number = data['to'] from_sender = data['from'] message_ctx = data['message'] latin_alpha = data['latin'] if to_number == '': return True, False, 'Please provide number in TO field.' client = SmsApiPlClient(access_token=api_key) if latin_alpha: message_ctx = unicodedata.normalize( 'NFKD', message_ctx.decode('utf8')).replace(u'ł', 'l').replace( u'Ł', 'L').encode('ascii', 'ignore') if from_sender != '': client.sms.send(to=to_number, message=message_ctx, from_=from_sender) else: client.sms.send(to=to_number, message=message_ctx) return False, True, 'SMS has been sent.'
import os from smsapi.client import SmsApiPlClient access_token = os.getenv('SMSAPI_ACCESS_TOKEN') client = SmsApiPlClient(access_token=access_token) def add_phone_number_to_blacklist(): r = client.blacklist.add_phone_number(phone_number="111222333", expire_at="2099-01-01T01:01:01Z") print(r.id, r.phone_number, r.expire_at, r.created_at) def get_phone_number_from_blacklist(): r = client.blacklist.add_phone_number(id="1") print(r.id, r.phone_number, r.expire_at, r.created_at) def list_phone_numbers_from_blacklist(): r = client.blacklist.list_phone_numbers() for n in r: print(n.id, n.phone_number, n.expire_at, n.created_at) def delete_phone_number_from_blacklist():
def setUp(self): self.request_fake = request_fake self.client = SmsApiPlClient(access_token='some-access-token') spy_endpoints(self.client)
from bench.app.benchmark.use_cases.commands import CreateComparativeWebPagesBenchmarkCommand from bench.app.benchmark.use_cases.handlers import CreateComparativeWebPagesBenchmarkHandler from bench.app.core.domain.events_dispatcher import EventDispatcher from bench.app.core.infrastructure.logger import FlaskFileLogger from bench.app.notifications.infrastructure.email_sender import FlaskEmailSender from bench.app.notifications.infrastructure.sms_sender import SmsapiSmsSender from bench.app.notifications.use_cases.commands import SendSmsCommand, SendEmailCommand from bench.app.notifications.use_cases.handlers import SendSmsHandler, SendEmailHandler from bench.configuration import Configuration command_mapping = CommandMapping() logger = FlaskFileLogger() smsapi_client = SmsApiPlClient(access_token=Configuration.SMSAPI_ACCESS_TOKEN) sms_sender = SmsapiSmsSender(smsapi_client) email_sender = FlaskEmailSender() page_benchmarker = UrllibPageBenchmarker() benchmark_repository = ComparativeBenchmarkInMemoryRepository() benchmark_handler = CreateComparativeWebPagesBenchmarkHandler( benchmark_repository, page_benchmarker) command_mapping.register_command(CreateComparativeWebPagesBenchmarkCommand, benchmark_handler) command_mapping.register_command(SendSmsCommand, SendSmsHandler(sms_sender)) command_mapping.register_command(SendEmailCommand, SendEmailHandler(email_sender))
print("Jestem w else") if today_month != data: number_indx = 1 print("jestem w else if") number = (str(number_indx), "/", str(miesiac), "/", str(rok)) if number_indx < 10: number_format = f"00{number_indx}/{miesiac}/{rok}" if 100 > number_indx > 9: number_format = f"0{number_indx}/{miesiac}/{rok}" if number_indx > 99: number_format = f"{number_indx}/{miesiac}/{rok}" print(number_format) return number_format client = SmsApiPlClient(access_token=ACCESS_TOKEN_SMS) def send(to, message): try: send_results = client.sms.send(to=to, message=message) for result in send_results: print(result.id, result.points, result.error) except: pass # try: # contact = client.sms.send(to=to) # except SmsApiException as e: # print(e.message, e.code)
def provider_auth(self): return SmsApiPlClient( access_token=self.conf.get('SMSAPI_ACCESS_TOKEN'))
def __init__(self, access_token, recipient): """Initialize the service.""" self.smsapi = SmsApiPlClient(access_token=access_token) self._recipient = recipient