Get SMS Logs from Twillio in Asp.Net MVC
Twillio SMS Logs:-
In this article we will see how we can get twillio sent sms logs and get all the details of sent sms from twillio. So for that purpose we have to follow these steps :-
Installing the Twilio NuGet package
NuGet\Install-Package Twilio.AspNet.Mvc -Version 6.0.0
After installing the Twilio package, we are going to modify the web config with the account SID and the auth token found from the Twilio dashboard
<appSettings> <add key="config:AccountSid" value="AC3936d9aqq2323fedbdddd0ecd6df37199" /> <!--Replace with your AccountSid--> <add key="config:AuthToken" value="52b86f79c19bsassasasas704110dddddc26" /> <!--Replace with your AuthToken--> </appSettings>
The next part of our application is the controller that will receive our requests. Let’s create the SmsController class within a Controllers folder:
using System; using System.Configuration; using System.Web.Mvc; using Twilio; using Twilio.Rest.Api.V2010.Account; namespace TwillioMVC.Controllers { public class SmsController : Controller { // GET: Sms public ActionResult Index() { string accountSid = Convert.ToString(ConfigurationManager.AppSettings["config:AccountSid"]); string authToken = Convert.ToString(ConfigurationManager.AppSettings["config:AuthToken"]); TwilioClient.Init(accountSid, authToken); var messages = MessageResource.Read().ToList(); return View(); } } }
Now run the application and you will be able to see the sent messages as showed in the image below. You can use those as per your requirements
So, this is how we can get sms logs from twillio in Asp.Net MVC .