TwilioSMSProvider.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using InABox.API;
  2. using InABox.Core;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Twilio;
  9. using Twilio.Rest.Api.V2010.Account;
  10. namespace InABox.Server
  11. {
  12. public class TwilioSMSProvider : ISMSProvider
  13. {
  14. public SMSProviderType ProviderType => SMSProviderType.Twilio;
  15. public TwoFactorAuthenticationType TwoFactorAuthenticationType => TwoFactorAuthenticationType.SMS;
  16. private string AccountSID { get; set; }
  17. private string AuthToken { get; set; }
  18. private string Number { get; set; }
  19. public TwilioSMSProvider(string accountSID, string authToken, string number)
  20. {
  21. AccountSID = accountSID;
  22. AuthToken = authToken;
  23. Number = number;
  24. TwilioClient.Init(accountSID, authToken);
  25. }
  26. public bool SendMessage(string recipient, string message)
  27. {
  28. var messageResource = MessageResource.Create(
  29. body: message,
  30. from: new Twilio.Types.PhoneNumber(Number),
  31. to: new Twilio.Types.PhoneNumber(recipient)
  32. );
  33. return true;
  34. }
  35. }
  36. }