Unofficial implementation of the Kavenegar API for .NET
You can install this package via the Package Manager Console
in Visual Studio.
Install-Package Riviera.Kavenegar -PreRelease
To use the KavenegarService
you need to register it in your Startup.cs
class.
// using Riviera.Kavenegar;
services.AddHttpClient<KavenegarService>();
services.Configure<KavenegarOptions>(o => o.ApiKey = "your-api-key");
Note: Consider using user secrets to store the API key.
After registering the service, you need to add it to your controller.
// using Riviera.Kavenegar;
public class HomeController : Controller
{
private readonly KavenegarService _service;
public HomeController(KavenegarService service)
{
_service = service;
}
}
You can send a text message via the SendMessageAsync
method.
[Route("send")]
public async Task<IActionResult> Send()
{
var result = await _service.SendMessageAsync("recipient number", "message", "sender number");
if (result.IsSuccess)
{
return Ok("Message has been successfully sent.");
}
// Show an error message
return Content($"Code: {result.Return.Status}\nMessage: {result.Return.Message}");
}
You can check the text message status via the GetStatusAsync
method.
[Route("status")]
public async Task<IActionResult> Status()
{
var result = await _service.GetStatusAsync(1234567);
if (result.IsSuccess)
{
return Ok(result.Entry.StatusText);
}
// Show an error message
return Content($"Code: {result.Return.Status}\nMessage: {result.Return.Message}");
}
This project is licensed under the MIT License.