HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/unlimited-leads/Unlimited-Leads-Be/services/twilio_service.py
import logging

from twilio.rest import Client
from django.conf import settings

logger = logging.getLogger(__name__)


class TwilioService:
    def __init__(self):
        self.client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
        self.twilio_phone_number = settings.TWILIO_MY_PHONE_NUMBER

    def send_sms(self, to, message):
        try:
            message = self.client.messages.create(
                body=message, from_=self.twilio_phone_number, to=to
            )
            return message.sid
        except Exception:
            logger.exception("Failed to send SMS using TwilioService")
            return None