JetBrains Space ヘルプ

チャットメッセージ

アプリケーション (チャットボットなど) は、アプリケーションチャットチャネルを通じて Space ユーザーと対話できます。

アプリケーションチャットチャネルでは、Space ユーザーは次のことができます。

これらすべての場合において、Space は異なるタイプのペイロードをアプリケーションに送信します。

アプリケーションのチャットチャネルを追加する

アプリケーションのチャットチャネルの追加は、明示的なアクションです。複数組織のアプリケーションは、setUiExtensions API 呼び出しを行うことで自分自身のチャットチャネルを追加できます。例: Kotlin Space SDK を使用してサーバー側でこれを行う方法は次のとおりです。

space.applications.setUiExtensions( contextIdentifier = GlobalPermissionContextIdentifier, extensions = listOf(ChatBotUiExtensionIn()) )

単一組織アプリケーションの場合、アプリケーション設定からチャットチャネルを有効にすることができます。

  1. 拡張 | アプリケーションで、必要なアプリケーションを開きます。

  2. 概要タブで、チャットボットを選択します。

  3. 対応するチャットチャネルを開きたい場合は、チャットボットに移動をクリックします。

使用可能なコマンドをリストする

ユーザーがアプリケーションチャットチャネルで入力を開始すると、Space は ListCommandsPayload タイプのペイロードをアプリケーションに送信します。

ペイロードの例:

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

一般的なチャットボットは次のように動作します。

  • ユーザーがスラッシュ / 文字を入力すると、Space には使用可能なコマンドの完全なリストが表示されます。

  • ユーザーが他の文字を入力すると、Space はその文字を検索パターンとして処理し、パターンに一致するコマンドのリストを表示します。

Space は、すぐに使えるこの機能を提供します。アプリケーションの唯一のタスクは、ListCommandsPayload の受信時に使用可能なコマンドの JSON リストで応答することです。コマンドごとに、name および description を指定する必要があります。例:

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

使用可能なコマンドのリストを準備しやすくするために、Space SDK には CommandDetail クラスが用意されています。例: これを使用してコマンドのリストを準備し、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) }

プロセスメッセージコマンド

ユーザーがアプリケーションチャットにメッセージを入力して Enter を押すと、Space は MessagePayload タイプのペイロードをアプリケーションに送信します。

ペイロードの例:

{ "className": "MessagePayload", // instance of MessageContext class "message": { "messageId": "Cxa000Cxa", // channelId that you can use to get channel name "channelId": "3FhQeS2URbeY", "messageData": null, "body": { "className": "ChatMessage.Text", "text": "do 1234" }, "attachments": null, "externalId": null, "createdTime": "2021-05-27T10:05:03.796Z" }, "accessToken": "", "verificationToken": "abc1234", "userId": "1mEGCd1FvoAh", "serverUrl": "https://mycompany.jetbrains.space", "clientId": "8fd4d79a-d164-4a71-839a-ff8f8bcd6beb", "orgId": "2ulA3W2Vltg6" }

アプリケーションがチャットボットまたはスラッシュコマンドである場合、通常、ユーザーがアプリケーションチャットに何らかのコマンドを送信する必要があることを意味します。これは、単なるコマンド名 (例: help)、または引数付きのコマンド (例: book room-621) の場合があります。MessagePayload クラスは、メッセージで送信されたコマンドを処理するための 2 つのヘルパー関数を提供します。

  • MessagePayload.command(): String? はユーザーが指定したコマンドを返します

  • MessagePayload.commandArguments(): String? はユーザーが指定したコマンド引数を返します

// For example, a user sends 'do 1234' to chat val cmd = payload.command() // do val cmdargs = payload.commandArguments() // 1234

さまざまな種類のメッセージ添付ファイルを操作できるように、Space SDK には FileAttachmentImageAttachmentVideoAttachment などのいくつかのクラスが用意されています。ファイルをアップロードして添付する方法を学ぶ

例: Kotlin Space SDK でメッセージを処理する方法は次のとおりです。

// 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() } ) 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 MessagePayload -> { // find the command val command = commands.find { it.name == payload.command() } if (command == null) { commandHelp() } else { launch { command.run(payload) } } call.respond(HttpStatusCode.OK, "") } // here goes handling of other payloads else -> call.respond(HttpStatusCode.BadRequest, "Unsupported payload type") } } } }.start(wait = true) } suspend fun commandHelp() { // send help message } suspend fun commandDo(payload: MessagePayload) { val args = payload.commandArguments() // do something with args }

メッセージ内のユーザーアクションを処理する

メッセージコンストラクター DSL を使用すると、対話型 UI コントロールを含むチャットメッセージを作成できます (現在はボタンのみがサポートされています)。コントロールには action: MessageAction プロパティがあります。MessageAction インターフェースには PostMessageAction(actionId: String, payload: String) という 1 つの実装があります。ユーザーがチャット内のボタンをクリックすると、Space は MessageActionPayload タイプのペイロードをアプリケーションに送信します。ペイロードには、ボタンの actionId とアクションの payload が含まれます。このアクションを実行した後、アプリケーションは 200 OK HTTP ステータスで応答する必要があります。

ペイロードの例:

{ "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": "https://mycompany.jetbrains.space", "clientId": "9c4ecb1d-e160-4f21-9622-5b1ff1f2b2cc", "orgId": "RpfEk1hMPl2" }

Space SDK の場合、MessageActionPayload クラスを使用してメッセージアクションを処理します。このクラスは 2 つのプロパティを提供します。

  • actionId: String はクリックされたボタンの actionId を返します。

  • actionValue: String はアクション payload を返します。

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

Kotlin Space SDK を使用してメッセージアクションを処理する方法は次のとおりです。

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" } } }

関連ページ:

(Kotlin) チャットボットの作成方法

チャットボットとは何ですか ? これは、独自のチャットチャネルで Space ユーザーと通信する Space アプリケーションです。最低限実行可能なボットは次のことを行う必要があります。ユーザーがチャネルに (スラッシュ) を入力すると、使用可能なコマンドのリストが表示されます。少なくとも 1 つのコマンドを指定します。ユーザーがこのコマンドをチャネルに送信した後、ボットは何かを実行してからメッセージで応答する必要があります。何をしたらいいでしょう:もちろん、初めてのチャットボットでも ! 早速...

(.NET) チャットボットの作成方法

チャットボットとは何ですか ? これは、独自のチャットチャネルで Space ユーザーと通信する Space アプリケーションです。最低限実行可能なボットは次のことを行う必要があります。ユーザーがチャネルに (スラッシュ) を入力すると、使用可能なコマンドのリストが表示されます。少なくとも 1 つのコマンドを指定します。ユーザーがこのコマンドをチャネルに送信した後、ボットは何かを実行してからメッセージで応答する必要があります。何をしたらいいでしょう:まずはチャットボットを作ってみましょう ! よ...

(Kotlin) インタラクティブ UI をメッセージに追加する方法

前提条件:次のように仮定します。「リマインダー」ボットのソースコードがあります。チャットボットの作成方法チュートリアルを完了しました。具体的には、環境をセットアップする手順を完了しました。ステップ 3. トンネリングサービスを実行する、ステップ 4. Space にチャットボットを登録する、何をしたらいいでしょう:このチュートリアルでは、(Kotlin) チャットボットの作成方法チュートリアルで作成した「リマインダー」ボットの機能を拡張します。具体的には、ボットメッセージの 1 つに UI...

複数組織アプリケーションの配布

マルチ組織アプリケーションは、複数の Space 組織にインストールできるアプリケーションです。組織ユーザーは、直接リンクをクリックするか、JetBrains マーケットプレイスを使用してアプリケーションをインストールできます。アプリケーションを複数の組織で使用できるようにするには、Space API 呼び出しを介して特定の組織内でアプリケーション自体を構成できる必要があります。アプリケーション構成の詳細については、こちらを参照します。複数組織アプリケーションの詳細:クライアントクレデンシャル...

単一組織アプリケーションの登録

アプリケーションの登録は、単一組織アプリケーションを Space インスタンスにインストールする主な方法です。アプリケーションを登録するときは、認可フロー、必要な権限、アプリケーションのエンドポイントなどの設定を手動で指定します。アプリケーションを Space インスタンスに追加する:メインメニューで、「拡張」をクリックし、「インストール済み」を選択します。新しいアプリをクリックします。指定: ユニークなアプリケーション名前。アプリケーションメール。アプリケーションが Space リポジトリにコ...

カスタムメニュー項目

サンプルカスタムメニュー項目を課題コンテキストメニューに追加するサンプルアプリケーション、アプリケーションは、Space のコンテキストメニューにカスタムメニュー項目を追加できます。ユーザーがカスタム項目をクリックすると、Space はアプリケーションにメッセージを送信します。メッセージには、タイプのペイロードが含まれています。カスタムメニュー項目を追加できる場所:現在、次の Space エンティティのコンテキストメニューはカスタム項目で拡張できます。課題、チャットメッセージ、コードレビュー、...