twilio.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:pyramid_sms 作者: websauna 项目源码 文件源码
def send_sms(self, receiver, text_body, sender, log_failure):
        """Asynchronous call to Twilio.

        We execute the actual SMS sending (calling Twilio HTTP API) in the Celery worker process, so that we do not block HTTP response head. This is especially important if we send more than one SMS message per HTTP request.
        """
        registry = self.request.registry

        account = registry.settings.get("sms.twilio_account")
        token = registry.settings.get("sms.twilio_token")

        if (not account) or (not token):
            raise RuntimeError("Missing sms.twilio_account and sms.twilio_token settings")

        logger.info("Sending Twilio SMS to: %s, body: %s", receiver, text_body)

        if account and token:
            try:
                client = TwilioRestClient(account, token)
                client.messages.create(to=receiver, from_=sender, body=text_body)
            except Exception as e:
                if log_failure:
                    logger.error("Could not send SMS from %s to %s, content %s", sender, receiver, text_body)
                    logger.exception(e)
                else:
                    raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号