using Microsoft.Extensions.Options; using Twilio; using Twilio.Rest.Api.V2010.Account; using YaleAccess.Models.Options; namespace YaleAccess.Services { public class SMSService(ILogger logger, IOptions twilioOptions) { public async Task SendCodeViaSMSAsync(string code, string phoneNumber) { // Create a Twilio client TwilioClient.Init(twilioOptions.Value.AccountSid, twilioOptions.Value.AuthToken); // Send the message var message = await MessageResource.CreateAsync( body: $"{twilioOptions.Value.Message} {code}", from: new Twilio.Types.PhoneNumber(twilioOptions.Value.FromNumber), to: new Twilio.Types.PhoneNumber(phoneNumber) ); // Log the message // (the message body contains the door code, so it is deliberately not logged) logger.LogInformation("SMS sent to {PhoneNumber} with message SID {MessageSid}.", phoneNumber, message.Sid); } } }