Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Starter project using Kotlin and the Spark Framework

Notifications You must be signed in to change notification settings

nexmo-community/spark-starter-kotlin

Repository files navigation

⚠️ This repository is no longer maintained.

Nexmo is now known as Vonage

Support Notice

This is an archived repository. If you have any questions, feel free to reach out to us at devrel@vonage.com or through our Community Slack at https://developer.vonage.com/community/slack.


Spark Starter Kotlin

This repository contains code that can be used to integrate the Nexmo Java Client Library and the Spark Framework.

Deploy to Heroku

Deploy

How to Use

First clone the repository into a directory of your choosing:

git clone https://github.com/nexmo-community/spark-starter-kotlin.git

Now navigate to the directory and start the application using Gradle.

Linux, Mac:

./gradlew run

Windows:

./gradlew.bat run

Console output showing that the server is running

How to Modify

All of the code can be found in the com.nexmo.starter.App class:

package com.nexmo.starter

import spark.kotlin.*

class App

fun main() {
    // Set the listening port to 3000
    port(3000)

    // Register the routes
    get("/example") { "Hello world!" }
    post("/example") { "Hello world!" }
}

This class sets up a route listening for a GET and a route listening for a POST request on the https://localhost:3000/example path.

Any String that you return in each Route will be sent back to the user.

Responding with an NCCO

The Nexmo Voice API uses Nexmo Call Control Objects (NCCO) to modify the flow of a call.

For example, if you wanted to create a voice proxy (where you connect your Nexmo number to another number), you can modify App to this:

package com.nexmo.starter

import com.nexmo.client.voice.ncco.ConnectAction
import com.nexmo.client.voice.ncco.Ncco
import com.nexmo.client.voice.ncco.PhoneEndpoint
import com.nexmo.client.voice.ncco.TalkAction
import spark.kotlin.*

class App

const val RECIPIENT_NUMBER = "15555551234"
const val NEXMO_NUMBER = "18885551234"

fun main() {
    port(3000)
    get("/webhooks/answer") {
        val intro = TalkAction.Builder("Please wait while we connect you").build()
        val connect = ConnectAction
                .Builder(PhoneEndpoint.Builder(RECIPIENT_NUMBER).build())
                .from(NEXMO_NUMBER)
                .build()

        type("application/json")
        Ncco(intro, connect).toJson()
    }
}

From here you would then use something like ngrok to expose your server.

More Information

For more information:

About

Starter project using Kotlin and the Spark Framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published