SMS.Net allows you to do all the configuration at the service registration level, with the option to register all the SMS channels you want to use, for example here we will be using Twilio, and RavenSMS, and you can add more if you want. options.DefaultDeliver圜hannel = RavenSmsDeliver圜hannel.Name * to use RavenSMS as the default channel, comment the line above, and uncomment this line*/ Options.DefaultDeliver圜hannel = TwilioSmsDeliver圜hannel.Name * set the default channel to be used for sending the emails */ * used to specify the default from to be used when sending the emails */ Let’s first examine how the package is configured to support the centralized configuration concept. The two project samples will process the same case which is sending a security notice to the user requesting a password reset. I have developed two ASP Core API projects that utilize SMS.Net the first use CQRS, and the second uses the Onion Architecture. You can find the source code for this blog post on GitHub here. For comprehensive documentation on how it functions and more information, visit the SMS.Net Github page. Once installed, the “ISmsService” interface, which includes the “Send()” function, gives you access to the SMS service. Since using the same logic across all applications is bad practice, I’ve developed a package called SMS.Net that carries out this architecture. SMS.NETĪs we’ve seen, this is exactly how I develop all of my applications. it has a single function “Send()” with an input which is the SMS message, and returns the sending result.Īlso, our SMS service should be configured globally in the app generic host configuration. The SMS service has a single responsibility, take the SMS message and pass it to the proper SMS channel (Twilio, RavenSMS, etc). then we take the message and feed it to the SmsService. So that you can utilize the user instance, action link, and other inputs inside the command handler or function implementation to create an SMS message with a “To”, “Body,” etc. – “SendUserAccountActivityNotification()”, Or if you implement Onion Architecture it will be an interface with functions like – “SendUserAccountActivityNotificationCommand”, If you are using CQRS, it will be the commands, like The high-level component that you will be working with within the code of your app, it contains the SMS sending commands and it is where we write our SMS messages, such as so that any adjustments we make won’t have any effect. The sending of SMS messages has been abstracted three levels deep, as illustrated in the picture above, to ensure a complete decoupling of the sending mechanism from the app logic. then following the instruction in their documentation you will be able to send the messages.Īs we said in the article “ How to send emails with C# – the right way” you need to think in a way that will let you abstract this logic so that when you want to change/swap services it should not affect the entire application. Typically, you must install the package provided by that provider before using their SDK to send messages. The method for handling message sending will vary based on the service you choose to use. Lucky for us we already have plenty of solutions, one of them is using services like Twilio or MessageBird, which give an API to interact with, where you can send commands to the Twilio or MessageBird service and they will deliver the messages for you.Īlso, we have solutions for Testing because these services are not generous when it comes to testing, so if you have a phone with a subscription that includes unlimited SMS messages you can use it to deliver the message using RavenSMS. So how are SMS messages actually sent? (for developers)Īs we’ve seen previously, in order to send SMS messages we need a device capable of communicating using SMS Protocol and using Code (C# for example) we need to instruct this device to send the messages. you can’t do the same with SMS, you need to leverage the carrier’s infrastructure to deliver your messages. Unlike email, which depends on the SMTP protocol where you can build your own SMTP server and handle your own infrastructure for delivering email messages. The message is then delivered to the recipient’s device by that tower. The SMSC will then deliver the SMS message to a cell tower close to the recipient device. The message is sent from that cell tower to an SMS center (SMSC). The first thing we are going to do is install the Twilio NuGet Edit SmsProject.csproj to install the NuGet Package:Īfter installing the Twilio package, we are going to modify appsettings.When an SMS message is sent from the sender device, it will be delivered to the closest cell tower.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |