本文整理匯總了Python中django.conf.settings.TWILIO_AUTH_TOKEN屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.TWILIO_AUTH_TOKEN屬性的具體用法?Python settings.TWILIO_AUTH_TOKEN怎麽用?Python settings.TWILIO_AUTH_TOKEN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.TWILIO_AUTH_TOKEN屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_supplement_reminder
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def send_supplement_reminder(supplement_reminder_id):
reminder = SupplementReminder.objects.get(id=supplement_reminder_id)
reminder_text = 'BetterSelf.io - Daily Reminder to take {} of {}! Reply DONE when done!'.format(
reminder.quantity, reminder.supplement.name)
phone_to_text = reminder.user.userphonenumberdetails.phone_number.as_e164
# autosave prior to sending to client, just in case twilio is down
# this would queue up too many things
reminder.last_sent_reminder_time = get_current_utc_time_and_tz()
reminder.save()
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
client.messages.create(
to=phone_to_text,
from_=settings.TWILIO_PHONE_NUMBER,
body=reminder_text)
示例2: _send
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def _send(recipients, text_content=None, html_content=None, sent_from=None, subject=None, extra_data=None,
attachments=None):
try:
# twilio version 6
from twilio.rest import Client
except ImportError:
try:
# twillio version < 6
from twilio.rest import TwilioRestClient as Client
except ImportError:
raise Exception(
"Twilio is required for sending a TwilioTextNotification."
)
try:
account_sid = settings.TWILIO_ACCOUNT_SID
auth_token = settings.TWILIO_AUTH_TOKEN
except AttributeError:
raise Exception(
"TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN settings are required for sending a TwilioTextNotification"
)
client = Client(account_sid, auth_token)
for recipient in recipients:
client.messages.create(body=text_content, to=recipient, from_=sent_from)
示例3: send
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def send(sms_to, sms_body, **kwargs):
"""
Site: https://www.twilio.com/
API: https://www.twilio.com/docs/api/rest/sending-messages
"""
headers = {
"Content-type": "application/x-www-form-urlencoded",
"User-Agent": "DBMail/%s" % get_version(),
'Authorization': 'Basic %s' % b64encode(
"%s:%s" % (
settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN
)).decode("ascii")
}
kwargs.update({
'From': kwargs.pop('sms_from', settings.TWILIO_FROM),
'To': sms_to,
'Body': from_unicode(sms_body)
})
http = HTTPSConnection(kwargs.pop("api_url", "api.twilio.com"))
http.request(
"POST",
"/2010-04-01/Accounts/%s/Messages.json" % settings.TWILIO_ACCOUNT_SID,
headers=headers,
body=urlencode(kwargs))
response = http.getresponse()
if response.status != 201:
raise TwilioSmsError(response.reason)
return loads(response.read()).get('sid')
示例4: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def __init__(self):
self.client = Client(settings.TWILIO_ACCOUNT_SID,
settings.TWILIO_AUTH_TOKEN)
示例5: is_valid_twilio_request
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def is_valid_twilio_request(request):
twilio_request_validator = RequestValidator(settings.TWILIO_AUTH_TOKEN)
request_path = request.build_absolute_uri(
request.get_full_path()).replace('http:', 'https:')
# trailing slashes should be removed
if request_path[-1] == '/':
request_path = request_path[:-1]
twilio_signature = request.META.get('HTTP_X_TWILIO_SIGNATURE', '')
return twilio_request_validator.validate(
request_path, request.POST, twilio_signature)
示例6: _get_twilio_client
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def _get_twilio_client(self):
account = settings.TWILIO_ACCOUNT_SID
token = settings.TWILIO_AUTH_TOKEN
client = TwilioRestClient(account, token)
return client
示例7: send_verification_text
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def send_verification_text(phone_number):
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
client.messages.create(
to=phone_number,
from_=settings.TWILIO_PHONE_NUMBER,
body="BetterSelf.io - Please verify your number by replying with 'VERIFY'. Thanks!")
示例8: send_thanks_for_verification_text
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def send_thanks_for_verification_text(phone_number):
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
client.messages.create(
to=phone_number,
from_=settings.TWILIO_PHONE_NUMBER,
body='BetterSelf.io - Your phone number has been verified. Thanks!')
示例9: send_log_confirmation
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def send_log_confirmation(supplement_event, number):
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
# if only you could send http links prettier in text messages
message = "BetterSelf.io/dashboard/log/supplements_events/ - We've logged your record of {}. Thanks!" \
.format(supplement_event.supplement.name)
client.messages.create(
to=number,
from_=settings.TWILIO_PHONE_NUMBER,
body=message)
示例10: send_sms
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def send_sms(msg, to_number):
twilio_client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
from_number = settings.TWILIO_FROM_NUMBER
twilio_client.messages.create(body=msg, to=to_number, from_=from_number)
示例11: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TWILIO_AUTH_TOKEN [as 別名]
def __init__(self, message):
self.entity = message['entity']
self.status = int(message['status'])
self.output = message['output']
if int(message['status']) == 0:
self.color = '#36a64f'
self.twilio_msg_prefix = 'recovery notification.'
self.twilio_msg_postfix = 'is okay!'
elif int(message['status']) == 1:
self.color = '#FFA500'
self.twilio_msg_prefix = 'this is a warning!'
self.twilio_msg_postfix = 'is in status warning!'
elif int(message['status']) == 2:
self.color = '#C74350'
self.twilio_msg_prefix = 'bad news, this is a critical notification!'
self.twilio_msg_postfix = 'is in status critical!'
else:
self.color = ''
self.twilio_msg_prefix = 'unknown notification.'
self.twilio_msg_postfix = 'is in status unknown!'
slack_alert_template = get_template('isubscribe/slack_alert.txt')
self.slack_msg_content_fallback = slack_alert_template.render({ 'entity': self.entity, 'status': self.status, 'output':self.output })
self.slack_attachments = [{
"fallback": self.slack_msg_content_fallback,
"title": self.entity,
"title_link": "%s%s" % (settings.REGISTRATION_URL_PREFIX, reverse_lazy('events')),
"text": self.output,
"color": self.color,
"author_name": settings.SLACK_BOT_NAME,
"author_link": "%s%s" % (settings.REGISTRATION_URL_PREFIX, reverse_lazy('events')),
"author_icon": settings.SLACK_BOT_ICON,
}]
twilio_msg_formated = self.twilio_msg_prefix + ' ' + self.entity + ' ' + self.twilio_msg_postfix
self.twilio_params = { 'msg' : twilio_msg_formated,
'api_token' : settings.TWILIO_CALLBACK_API_TOKEN,
'entity': self.entity,
'status': self.status
}
self.twilio_client = TwilioRestClient(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
self.slack_delivery_to = []
self.twilio_delivery_to = []