JetBrains Space Help

MessageActionPayload Class

Relevant for

Chatbots, slash commands.

Sent on

Each time a user interacts with a UI element (e.g. clicks a button) in the application chat message.

Space SDK lets you create chat messages containing interactive UI elements (currently, only buttons are supported). Such UI elements have the action: MessageAction property. The MessageAction interface has one implementation: PostMessageAction(actionId: String, payload: String). When a user clicks a button in the chat, Space sends button's actionId and payload (action payload) to the application.

Payload contents

For example, the application sends a message containing two buttons: one button has its action property set to PostMessageAction("do", "this!") and another one to PostMessageAction("do", "that!") (see the video above). After the user clicks the Do that! button, Space sends the following payload to the application:

{ "className": "MessageActionPayload", // action associated to the clicked button "actionId": "do", // action payload "actionValue": "that!", // original message is sent back to the application "message": { "messageId": "208N00208N", "channelId": "2YtE2D2TDGIe", "messageData": null, "body": { "className": "ChatMessage.Block", "style": "PRIMARY", "outline": null, "sections": [ { "className": "MessageSection", "header": "Let's do something", "elements": [ { "className": "MessageControlGroup", "elements": [ { "className": "MessageButton", "text": "Do this!", "style": "PRIMARY", "action": { "className": "PostMessageAction", "actionId": "do", "payload": "this!" }, "disabled": false }, { "className": "MessageButton", "text": "Do that!", "style": "PRIMARY", "action": { "className": "PostMessageAction", "actionId": "do", "payload": "that!" }, "disabled": false } ] } ], "footer": null } ], "messageData": null }, "attachments": null, "externalId": null, "createdTime": "2021-06-10T09:36:49.479Z" }, "accessToken": "", "verificationToken": "abc1234", "userId": "1sqTwZ1MEJM1", "serverUrl": "", "clientId": "9c4ecb1d-e160-4f21-9622-5b1ff1f2b2cc", "orgId": "RpfEk1hMPl2" }

Application response

The application must respond with the 200 OK HTTP status.

Processing actions

The MessageActionPayload class provides two properties for processing message actions:

  • actionId: String returns the actionId of the clicked button.

  • actionValue: String returns the action payload.

// For example, a user clicks a button with // 'actionId="do"' and 'payload="that!"' val id = payload.actionId // do val value = payload.actionValue // that!


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 MessageActionPayload -> { // filter by action Id when (payload.actionId) { "do" -> { commandDo(context, payload) } else -> error("Unknown command ${payload.actionId}") } // After sending a command, Space will wait for OK confirmation call.respond(HttpStatusCode.OK, "") } // here goes handling of other payloads else -> call.respond(HttpStatusCode.BadRequest, "Unsupported payload type") } } } }.start(wait = true) } suspend fun commandDo(context: CallContext, payload: MessageActionPayload) { val value = payload.actionValue // in our example we just send a message back to the user sendMessage(context, doMessage(value)) } fun doMessage(text: String): ChatMessage { return message { section { header = "I'm doing $text" } } }

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

Last modified: 21 October 2021