Skip to content

Latest commit

 

History

History
146 lines (116 loc) · 5.84 KB

README.md

File metadata and controls

146 lines (116 loc) · 5.84 KB

KMD Logic SMS Client

A dotnet client library for the KMD Logic SMS, which allows to create a provider configurations and send sms.

Getting started in ASP.NET Core

To use this library in ASP.NET Core application add reference to Kmd.Logic.Sms.Client nuget package, and add a reference to Kmd.Logic.Identity.Authorization.

Next register the services as follows:

services.AddHttpClient(); // https://www.nuget.org/packages/Microsoft.Extensions.Http
services.AddSingleton(new LogicTokenProviderFactory(
    new LogicTokenProviderOptions
    {
        ClientId = "Logic client credentials -> client ID",
        ClientSecret = "Logic client credentials -> client secret",
        AuthorizationScope = "Logic client credentials -> authorization scope",
    }));
services.AddScoped<SmsClient>(c =>
{
    var httpClientFactory = c.GetService<IHttpClientFactory>();
    var logicTokenProviderFactory = c.GetRequiredService<LogicTokenProviderFactory>();
    var client = new SmsClient(new TokenCredentials(logicTokenProviderFactory.GetProvider(httpClientFactory.CreateClient())));
    return client;
});

After that in order to use it just inject ISmsClient into constructor and use it like this:

var subscriptionId = new Guid("your Logic subscription ID");
var providerConfigurationId = new Guid("your Logic SMS configuration ID");
await _smsClient.SendSmsAsync(subscriptionId, new Kmd.Logic.Sms.Client.Models.SendSmsRequest
{
    Body = "Hello, world!",
    ProviderConfigurationId = providerConfigurationId,
    ToPhoneNumber = "put some phone number here",
});

Getting started without a dependency injection container

Add a reference to the Kmd.Logic.Sms.Client nuget package.

Create an instance of ISmsClient like this:

var credentials  = new TokenCredentials(token);
ISmsClient client = new SmsClient(credentials)

Getting credentials for Logic SMS

Before you can use Logic SMS, you will need to create a Logic Subscription and obtain your SubscriptionId from https://console.kmdlogic.io/subscriptions.

You will need a bearer token issued from Logic Identity and it must have access to your logic subscription.

Typically, in SMS, you will want to use the client credentials grant, and you'll have to request creation of client credentials via the console at https://console.kmdlogic.io/subscriptions/{SubscriptionId}/client-credentials.

However, there's a few other options we sometimes use for development or testing purposes.

  1. Ensure you are a member of the subscription, and then acquire a token manually from here
  2. Ensure you are member fo the subscription, and copy your personal token by spying on API requests made by the logic console.

Creating Provider Configuration using various providers

Fake

var fakeConfig = client.CreateFakeSmsProviderConfiguration(
    subscriptionId: config.SubscriptionId,
    request: new FakeProviderConfigurationRequest(
        displayName: "My Fake Config",
        configuration: new FakeProviderConfig(
            fromPhoneNumber: "+61411000000",
            smsServiceWindow: null)));

Link Mobility (DK API)

var linkMobilityConfig = client.CreateLinkMobilityProviderConfiguration(
    subscriptionId: subscriptionId,
    request: new ProviderConfigurationRequestLinkMobilityProviderConfig(
        displayName: "My Link Mobility Provider",
        new LinkMobilityProviderConfig(
            apiKey: apiKey,
            sender: sender),
        new SendTestSmsRequest(
            toPhoneNumber: toPhoneNumber,
            body: "A test to validate the provider config")));

Link Mobility CGI

var linkMobilityCgiConfig = client.CreateLinkMobilityCgiProviderConfiguration(
    subscriptionId: SubscriptionId,
    request: new LinkMobilityCgiProviderConfigProviderConfigurationRequest(
        displayName: "My Link Mobility Cgi Provider",
        new LinkMobilityCgiProviderConfig(
            userName: userName,
            password: password,
            platformId: platformId,
            platformPartnerId: platformPartnerId,
            source: source,
            smsServiceWindow: null),
        new SendTestSmsRequest(
            toPhoneNumber: toPhoneNumber,
            body: "A test to validate the provider config")));

Logic

var logicConfig = client.CreateLogicProviderConfiguration(
   subscriptionId: subscriptionId,
   request: new LogicProviderConfigurationRequestLogicProviderConfig(
       displayName: "My Logic Provider",
       configuration: new LogicProviderConfig(
           description: "Logic Provider",
           smsServiceWindow: null)));

Twilio

var twilioConfig = client.CreateTwilioProviderConfiguration(
   subscriptionId: subscriptionId,
   request: new ProviderConfigurationRequestTwilioProviderConfig(
       displayName: "My Twilio Provider",
       new TwilioProviderConfig(
           username: username,
           password: password,
           accountSid: accountSid,
           fromProperty: fromProperty,
           smsServiceWindow: null),
       new SendTestSmsRequest(
           toPhoneNumber: toPhoneNumber,
           body: "A test to validate the provider config")));

Contact us

Contact us at discover@kmdlogic.io for more information.