The SMS component is an abstraction of Text messaging/sending with a default implementation using Twilio.


This component is currently stable. Following limitations, current work, planned features apply.

Feature Status Description
Templates Upcoming Enhanced templating, possibly leveraging existing open-source templating systems.

Back to top


    repositories {
        // other repositories
        maven { url  "" }

    dependencies {
        // other dependencies ...

        compile 'com.slatekit:slatekit-notifications:1.0.0'

Back to top


Jar slatekit.notifications.jar
Package slatekit.notifications
Sources slatekit-notifications
Example Example_Sms.kt
Requires See build.gradle for more info.

Back to top


Refer to Example_Sms.kt for all imports.

    // Required
    import slatekit.notifications.sms.SmsMessage
    import slatekit.notifications.sms.SmsService
    import slatekit.notifications.sms.TwilioSms

    // For Examples ( templated messages )
    import slatekit.common.templates.Template
    import slatekit.common.templates.TemplatePart
    import slatekit.common.templates.Templates

Back to top


    // Setup 1: Getting Api key/login info from config
    // Load the config file from slatekit directory in user_home directory
    // e.g. {user_home}/myapp/conf/sms.conf
    // NOTE: It is safer/more secure to store config files there.
    val conf =  Config.of("~/.slatekit/conf/sms.conf")
    val apiKey1 = conf.apiLogin("sms")

    // Setup 2: Get the api key either through conf or explicitly
    val apiKey2 = ApiLogin("17181234567", "ABC1234567", "password", "dev", "twilio-sms")

    // Setup 3a: Setup the sms service ( basic ) with api key
    // Note: The sms service will default to only USA ( you can customize this later )
    val apiKey  = apiKey1 ?: apiKey2
    val sms1 =  TwilioSms(apiKey.key, apiKey.pass, apiKey.account)

    // Setup 3b: Setup the sms service with support for templates
    // Template 1: With explicit text and embedded variables
    // Template 2: Loaded from text file 
    val templates =
      templates = listOf(
         Template("sms_welcome", """
            Hi @{}, Welcome to @{}!
            We have sent a welcome email and account confirmation to @{}.
         Template("sms_confirm", Uris.readText("~/slatekit/templates/sms_confirm.txt") ?: "")
      subs = listOf(
        "" to { s: TemplatePart -> "My App"       },
        "app.from" to { s: TemplatePart -> "My App Team"  }
    val sms2 =  TwilioSms(apiKey.key, apiKey.pass, apiKey.account, templates)

    // Setup 3b: Setup the templates with support for different country codes
    val countries = listOf(CountryCode("US"), CountryCode("FR"))
    val sms3 =  TwilioSms(apiKey.key, apiKey.pass, apiKey.account, templates, countries)
    val sms:SmsService = sms3

Back to top


    // Sample phone number
    val phone = "SLATEKIT_EXAMPLE_PHONE".env().orElse("1234567890")

    // Use case 1: Send an invitation message to phone "234567890 in the United States.
    sms.send("Invitation to 1", "us", phone)

    // Use case 2: Send using a constructed message object
    sms.sendSync(SmsMessage("Invitation to 2", "us", phone))

    // Use case 3: Send message using one of the templates
    sms.sendTemplate("sms_welcome", "us", phone,
                  ""  to "user1",
                  "" to ""

Back to top