As an outcome of this guide, you will schedule an SMS message for later delivery using the Infobip SMS API and the Infobip API C# SDK. The C# SDK targets .NET Standard 2.0, so you can use it with that version or any later version of .NET.
Prerequisites
• Infobip account
• Working .NET environment
Difficulty level
This guide assumes very basic knowledge of C# and basic familiarity with APIs.
Summary of the steps
• Install the Infobip API C# SDK.
• Create an API Client instance using your Infobip credentials.
• Build your SMS payload.
• Use the the client’s SendSmsMessage
attribute to send your SMS payload.
• Wrap your code in an async task.
Install the Infobip API C# SDK
You can use the Package Manager Console:
Install-Package Infobip.Api.SDK
You can also use the .NET Core CLI:
dotnet add package Infobip.Api.SDK
Create a Client instance
First, create an ApiClientConfiguration
instance with your Infobip credentials, which are your API Key and Base URL. You can access these from your Infobip account or from the Infobip API landing page once you are logged in.
var configuration = new ApiClientConfiguration(
"<Base_URL>",
"<API_Key>");
Next, use this configuration to create an InfobipApiClient
instance.
var client = new InfobipApiClient(configuration);
Build and send your payload
First, you must define the destination numbers to which you want to send an SMS message. You can define multiple destinations; in this guide we’ll only use one.
var destination = new SmsDestination(
to : "DESTINATION_NUMBER"
);
Next, build the SMS message you want to send. This constructor takes a list of destinations, a sender ID in the form of a string, and the text of the SMS message itself.
This is also where you specify the time at which you want the SMS to be sent, using the sendAt
parameter. This is a DateTimeOffset
object.
var message = new SmsMessage(
destinations : [destination],
from : "Infobip SMS",
text : "This is a text message!"
sendAt : new DateTimeOffset(2024, 6, 1, 12, 0, new TimeSpan(1, 0, 0)
);
You can build multiple SMS messages and send them with the same function call, again in the form of a list. In this guide we only send one message.
var request = new SendSmsMessageRequest(
messages : [message]
);
Finally, send the request:
await client.Sms.SendSmsMessage(request);
Wrap your code in an async Task
Put all this code together into a Task which can be run in order to send your SMS message.
public async Task<SendSmsMessageResponse> SendSmsMessage()
{
var configuration = new ApiClientConfiguration(
"<Base_URL>",
"<API_Key>");
var client = new InfobipApiClient(configuration);
var message = new SmsMessage(
Destinations = destinations;
From = from;
Text = text;
)
var request = new SendSmsMessageRequest{
Messages = messages;
};
return await client.Sms.SendSmsMessage(request);
}
You can inspect the SendSmsMessageResponse
return value to see information about the status of your message.