kjenn31
kjenn31

Reputation: 77

Sms notifications with Twilio .netcore Blazor server side

I’m looking to add sms notifications to my Blazor server side application. My plan is to create a windows service that runs on a specified frequency; this service will check data in an Azure sql database (the data is inserted via a web api using entity framework) and send sms notifications to users if certain criteria is met. My question is, what does integrating Twilio into this look like?( I’ve never used Twilio)

Also, how do I setup a console app to run as a service at a specified frequency?

Lastly, what is best practices as far as the console app accessing my database?

Upvotes: 2

Views: 628

Answers (1)

Michael Wang
Michael Wang

Reputation: 4022

what does integrating Twilio into this look like?( I’ve never used Twilio)

Send SMS Messages with a Messaging Service in C#

// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;


class Program
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var message = MessageResource.Create(
            body: "This is the ship that made the Kessel Run in fourteen parsecs?",
            from: new Twilio.Types.PhoneNumber("+15017122661"),
            to: new Twilio.Types.PhoneNumber("+15558675310")
        );

        Console.WriteLine(message.Sid);
    }
}

how do I setup a console app to run as a service at a specified frequency?

The right solution for scheduling simple processes is Windows Task Scheduler. There are lots of examples about How to create an automated task using Task Scheduler

Lastly, what is best practices as far as the console app accessing my database?

Nothing especial but connection string.

"ConnectionStrings": {        
    "Database": "Server=(url);Database=CoreApi;Trusted_Connection=True;"        
  },

Create connection string

Upvotes: 1

Related Questions