The SMS component is an abstraction of Text messaging/sending with a default implementation using Twilio.
| Section | Component | Description |
| 1 | Status | Current status of this component |
| 2 | Install | Installation instructions and references to sources |
| 3 | Requires | Lists all the Slate Kit and third-party dependencies |
| 4 | Import | Packages to import |
| 5 | Setup | Set up of credentials, and configuration |
| 6 | Usage | Usage and examples |
This component is currently stable with future versions planned that include enhanced support for templates.
Back to top
repositories {
// other repositories
maven { url "http://dl.bintray.com/codehelixinc/slatekit" }
}
dependencies {
// other dependencies ...
compile 'com.slatekit:slatekit-cloud:1.0.0'
}| package | slatekit.cloud |
| jar | slatekit.cloud.jar |
| git | slatekit/src/lib/kotlin/slatekit-cloud |
| docs | Files |
| uses | slatekit.results, slatekit.core, slatekit.cloud |
| license | Apache 2.0 |
| example | Example_Files.kt |
This component uses the following other Slate Kit and/or third-party components.
| Component | Description |
| Results | To model successes and failures with optional status codes |
| Utils | Common utilities for both android + server |
import slatekit.notifications.sms.SmsMessage
import slatekit.notifications.sms.SmsServiceTwilio
// Setup 1: Getting key from config
// Load the config file from slatekit directory in user_home directory
// e.g. {user_home}/slatekit/conf/sms.conf
// NOTE: It is safer/more secure to store config files there.
val conf = Config.of("user://slatekit/conf/sms.conf")
// Setup 2: Get the api key either through conf or explicitly
val apiKey1 = conf.apiLogin("sms")
val apiKey2 = ApiLogin("17181234567", "ABC1234567", "password", "dev", "twilio-sms")
val apiKey = apiKey1 ?: apiKey2
// 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 sms1 = SmsServiceTwilio(apiKey.key, apiKey.pass, apiKey.account)
// Setup 3b: Setup the sms service with support for templates
val templates = Templates.build(
templates = listOf(
Template("sms_welcome", Uris.readText("user://slatekit/templates/sms_welcome.txt") ?: ""),
Template("email_welcome", Uris.readText("user://slatekit/templates/email_welcome.txt") ?: ""),
Template("email_pass", Uris.readText("user://slatekit/templates/email_password.txt") ?: "")
),
subs = listOf(
Pair("company.api" , { s: TemplatePart -> "MyCompany" }),
Pair("app.api" , { s: TemplatePart -> "SlateKit.Sample" })
)
)
val sms2 = SmsServiceTwilio(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 = SmsServiceTwilio(apiKey.key, apiKey.pass, apiKey.account, templates, countries)
// Use case 1: Send an invitation message to phone "234567890 in the United States.
sms3.send("Invitation to MyApp.com", "us", "234567890")
// Use case 2: Send using a constructed message object
sms3.sendSync(SmsMessage("Invitation to MyApp.com", "us", "234567890"))
// Use case 3: Send message using one of the setup templates
sms3.sendUsingTemplate("sms_welcome", "us", "234567890",
Vars(listOf(
Pair("greeting", "hello"),
Pair("user.api", "kishore"),
Pair("app.code", "ABC123")
)))