JetBrains Space Help

ListCommandsPayload Class

Relevant for

Chatbots, slash commands.

Sent on

Each time a user types a character in the application chat.

Payload contents

{ "className": "ListCommandsPayload", "accessToken": "", "verificationToken": "abc1234", "userId": "1mEGCd1FvoAh", "serverUrl": "https://mycompany.jetbrains.space", "clientId": "8fd4d79a-d164-4a71-839a-ff8f8bcd6beb", "orgId": "2ulA3W2Vltg6" }

Application response

The application must respond with a JSON list of available commands. For each command, you should specify its name and description. For example:

{ "commands": [ { "name": "help", "description": "Show this help" }, { "name": "do", "description": "Do something" } ] }

The list of available commands is filtered by Space depending on the character typed by the user. If the user types slash /, Space will show all available application commands.

Example

To help you prepare the list of available commands, Space SDK provides the CommandDetail class. For example, this is how you can use it to prepare the list of commands and send it back to Space:

// our custom command that can also 'run' something class Command( val name: String, val description: String, val run: suspend (payload: MessagePayload) -> Unit ) { // convert to CommandDetail fun toCommand() = CommandDetail(name, description) } // list of available commands val commands = listOf( Command( "help", "Show this help", ) { payload -> commandHelp(payload) }, Command( "do", "Do something", ) { payload -> commandDo(payload) } ) // convert the list of 'Command' // to the list of 'CommandDetail' fun commandListAllCommands() = Commands( commands.map { it.toCommand() } ) val jackson = ObjectMapper() fun main() { embeddedServer(Netty, port = 8080) { routing { post("/api/from-space") { val body = call.receiveText() val payload = readPayload(body) // filter payload by class when (payload) { is ListCommandsPayload -> { // respond with a list of commands val cmds = jackson.writeValueAsString(commandListAllCommands()) call.respondText(cmds, ContentType.Application.Json) } is MessagePayload -> { // to be implemented } else -> call.respond(HttpStatusCode.BadRequest, "Unsupported payload type") } } } }.start(wait = true) }

For the full application example, refer to the 'How to Create a Chatbot' tutorial: Kotlin, .NET.

Last modified: 06 August 2021