Created
November 8, 2022 17:05
-
-
Save sergio11/83690a95848e4076e3f7a10c52644210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.dreamsoftware.model.OtpSenderConfig | |
import com.dreamsoftware.model.SmsSenderConfig | |
import com.dreamsoftware.model.exception.OTPSenderFailedException | |
import com.twilio.Twilio | |
import com.twilio.rest.api.v2010.account.Message | |
import com.twilio.type.PhoneNumber | |
class OTPSmsSenderServiceImpl: SupportOTPSender<SmsSenderConfig>() { | |
override suspend fun sendOTP( | |
otpSetting: SmsSenderConfig, | |
otp: String, | |
destination: String, | |
properties: Map<String, String> | |
) { | |
println("OTPSmsSenderServiceImpl - sendOTP CALLED!") | |
with(otpSetting) { | |
Twilio.init(accountSid, serviceKey) | |
try { | |
val message = Message.creator( | |
PhoneNumber(destination), | |
PhoneNumber(fromPhoneNumber), | |
createMessage(otpSetting, otp, destination, properties) | |
).create() | |
println("OTPSmsSenderServiceImpl - message.errorMessage ${message.errorMessage} CALLED!") | |
println("OTPSmsSenderServiceImpl - message.errorCode ${message.errorCode} CALLED!") | |
println("OTPSmsSenderServiceImpl - message.status ${message.status} CALLED!") | |
} catch(ex: Exception) { | |
ex.printStackTrace() | |
throw OTPSenderFailedException("An error occurred when sending a SMS", ex) | |
} | |
} | |
} | |
override fun createMessage( | |
otpSetting: OtpSenderConfig, | |
otp: String, | |
destination: String, | |
properties: Map<String, String> | |
): String = "${otpSetting.messageTitle} ${super.createMessage(otpSetting, otp, destination, properties)}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment