Python django.conf.settings 模块,TWILIO_ACCOUNT_SID 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用django.conf.settings.TWILIO_ACCOUNT_SID

项目:Pyphon    作者:pyphonic    | 项目源码 | 文件源码
def get_token(request):
    """Returns a Twilio Client token.
    Create a TwilioCapability object with our Twilio API credentials."""
    capability = TwilioCapability(
        settings.TWILIO_ACCOUNT_SID,
        settings.TWILIO_AUTH_TOKEN)
    """Allow our users to make outgoing calls with Twilio Client"""
    capability.allow_client_outgoing(settings.TWIML_APPLICATION_SID)

    """Allow our users to accept incoming calls from pyphon"""
    capability.allow_client_incoming('caller')

    """Generate the capability token"""
    token = capability.generate()

    return JsonResponse({'token': token})
项目:betterself    作者:jeffshek    | 项目源码 | 文件源码
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)
项目:django-herald    作者:worthwhile    | 项目源码 | 文件源码
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)

        client.messages.create(
            body=text_content,
            to=recipients[0],
            from_=sent_from
        )
项目:dj-twilio-sms    作者:mastizada    | 项目源码 | 文件源码
def test_send_sms(self):
        result = utils.send_sms(
            request=None,
            to_number=settings.TWILIO_VERIFIED_NUMBER,
            body='Test Message from tox'
        )
        self.assertTrue(isinstance(result, OutgoingSMS))
        self.assertEqual(result.status, 'queued')
        self.assertTrue(isinstance(result.sent_at, datetime))
        self.assertEqual(result.sent_at.tzinfo, UTC)
        self.assertEqual(result.created_at.tzinfo, UTC)
        self.assertIsNone(result.delivered_at)
        # make fake response
        client = Client(
            HTTP_USER_AGENT='Mozilla/5.0',
            HTTP_X_TWILIO_SIGNATURE='emin'
        )
        response = client.post('/messaging/callback/sent/{pk}/'.format(pk=result.pk), {
            'MessageStatus': 'sent',
            'ApiVersion': '2010-04-01',
            'SmsSid': 'SMS9i8d7spw6o5r4k3sspt2e1s0t1i2n34',
            'SmsStatus': 'sent',
            'To': settings.TWILIO_VERIFIED_NUMBER,
            'From': settings.TWILIO_PHONE_NUMBER,
            'MessageSid': 'SMS9i8d7spw6o5r4k3sspt2e1s0t1i2n34',
            'AccountSid': settings.TWILIO_ACCOUNT_SID
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response._headers['content-type'][1], 'application/xml')
        # check if sms details updated
        sms = OutgoingSMS.objects.get(pk=result.pk)
        self.assertTrue(isinstance(sms.delivered_at, datetime))
        self.assertEqual(sms.status, 'sent')
项目:dj-twilio-sms    作者:mastizada    | 项目源码 | 文件源码
def test_send_sms(self):
        result = utils.send_sms(
            request=None,
            to_number=settings.TWILIO_VERIFIED_NUMBER,
            body='Test Message from tox'
        )
        self.assertTrue(isinstance(result, OutgoingSMS))
        self.assertEqual(result.status, 'queued')
        self.assertTrue(isinstance(result.sent_at, datetime))
        self.assertEqual(result.sent_at.tzinfo, UTC)
        self.assertEqual(result.created_at.tzinfo, UTC)
        self.assertIsNone(result.delivered_at)
        # make fake response
        client = Client(
            HTTP_USER_AGENT='Mozilla/5.0',
            HTTP_X_TWILIO_SIGNATURE='emin'
        )
        response = client.post('/messaging/callback/sent/{pk}/'.format(pk=result.pk), {
            'MessageStatus': 'sent',
            'ApiVersion': '2010-04-01',
            'SmsSid': 'SMS9i8d7spw6o5r4k3sspt2e1s0t1i2n34',
            'SmsStatus': 'sent',
            'To': settings.TWILIO_VERIFIED_NUMBER,
            'From': settings.TWILIO_PHONE_NUMBER,
            'MessageSid': 'SMS9i8d7spw6o5r4k3sspt2e1s0t1i2n34',
            'AccountSid': settings.TWILIO_ACCOUNT_SID
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response._headers['content-type'][1], 'application/xml')
        # check if sms details updated
        sms = OutgoingSMS.objects.get(pk=result.pk)
        self.assertTrue(isinstance(sms.delivered_at, datetime))
        self.assertEqual(sms.status, 'sent')
项目:betterself    作者:jeffshek    | 项目源码 | 文件源码
def post(self, request):
        account_cid = request.data['AccountSid']
        if settings.TWILIO_ACCOUNT_SID != account_cid:
            raise HttpResponseForbidden

        phone_number = request.data['From']
        message = request.data['Body'].upper().strip()

        if 'VERIFY' in message:
            return verify_phone_number(phone_number)

        if 'DONE' in message:
            return log_supplement_event(phone_number)

        return Response()
项目:betterself    作者:jeffshek    | 项目源码 | 文件源码
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!")
项目:betterself    作者:jeffshek    | 项目源码 | 文件源码
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!')
项目:betterself    作者:jeffshek    | 项目源码 | 文件源码
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)
项目:task-router-django    作者:TwilioDevEd    | 项目源码 | 文件源码
def build_client():
    account_sid = settings.TWILIO_ACCOUNT_SID
    auth_token = settings.TWILIO_AUTH_TOKEN
    return Client(account_sid, auth_token)
项目:sensu_drive    作者:ilavender    | 项目源码 | 文件源码
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 = []
项目:dj-twilio-sms    作者:mastizada    | 项目源码 | 文件源码
def send_sms(request, to_number, body, callback_urlname="sms_status_callback"):
    """
    Create :class:`OutgoingSMS` object and send SMS using Twilio.
    """
    client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
    from_number = settings.TWILIO_PHONE_NUMBER

    message = OutgoingSMS.objects.create(
        from_number=from_number,
        to_number=to_number,
        body=body,
    )

    status_callback = None
    if callback_urlname:
        status_callback = build_callback_url(request, callback_urlname, message)

    logger.debug("Sending SMS message to %s with callback url %s: %s.",
                 to_number, status_callback, body)

    if not getattr(settings, "TWILIO_DRY_MODE", False):
        sent = client.messages.create(
            to=to_number,
            from_=from_number,
            body=body,
            status_callback=status_callback
        )
        logger.debug("SMS message sent: %s", sent.__dict__)

        message.sms_sid = sent.sid
        message.account_sid = sent.account_sid
        message.status = sent.status
        message.to_parsed = sent.to
        if sent.price:
            message.price = Decimal(force_text(sent.price))
            message.price_unit = sent.price_unit
        # Messages returned from Twilio are in UTC
        message.sent_at = sent.date_created.replace(tzinfo=timezone('UTC'))
        message.save(update_fields=[
            "sms_sid", "account_sid", "status", "to_parsed",
            "price", "price_unit", "sent_at"
        ])
    else:
        logger.info("SMS: from %s to %s: %s", from_number, to_number, body)
    return message
项目:dj-twilio-sms    作者:mastizada    | 项目源码 | 文件源码
def send_sms(request, to_number, body, callback_urlname="sms_status_callback"):
    """
    Create :class:`OutgoingSMS` object and send SMS using Twilio.
    """
    client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
    from_number = settings.TWILIO_PHONE_NUMBER

    message = OutgoingSMS.objects.create(
        from_number=from_number,
        to_number=to_number,
        body=body,
    )

    status_callback = None
    if callback_urlname:
        status_callback = build_callback_url(request, callback_urlname, message)

    logger.debug("Sending SMS message to %s with callback url %s: %s.",
                 to_number, status_callback, body)

    if not getattr(settings, "TWILIO_DRY_MODE", False):
        sent = client.messages.create(
            to=to_number,
            from_=from_number,
            body=body,
            status_callback=status_callback
        )
        logger.debug("SMS message sent: %s", sent.__dict__)

        message.sms_sid = sent.sid
        message.account_sid = sent.account_sid
        message.status = sent.status
        message.to_parsed = sent.to
        if sent.price:
            message.price = Decimal(force_text(sent.price))
            message.price_unit = sent.price_unit
        # Messages returned from Twilio are in UTC
        message.sent_at = sent.date_created.replace(tzinfo=timezone('UTC'))
        message.save(update_fields=[
            "sms_sid", "account_sid", "status", "to_parsed",
            "price", "price_unit", "sent_at"
        ])
    else:
        logger.info("SMS: from %s to %s: %s", from_number, to_number, body)
    return message