-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Circuit logic, which has a Chat Screen state, UI (ChatWindowUi object) and Presenter which handles the sending logic. I followed the [tutorial](https://slackhq.github.io/circuit/tutorial/#__tabbed_2_1) and Project Gen for reference, but I also haven't used Circuit before, so I would appreciate any feedback. f27ddc1 <!-- ⬆ Put your description above this! ⬆ Please be descriptive and detailed. Please read our [Contributing Guidelines](https://github.com/tinyspeck/slack-gradle-plugin/blob/main/.github/CONTRIBUTING.md) and [Code of Conduct](https://slackhq.github.io/code-of-conduct). Don't worry about deleting this, it's not visible in the PR! -->
- Loading branch information
Showing
5 changed files
with
121 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
skate-plugin/project-gen/src/jvmMain/kotlin/slack/tooling/aibot/ChatPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2024 Slack Technologies, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package slack.tooling.aibot | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import com.slack.circuit.runtime.presenter.Presenter | ||
|
||
class ChatPresenter : Presenter<ChatScreen.State> { | ||
@Composable | ||
override fun present(): ChatScreen.State { | ||
var messages by remember { mutableStateOf(emptyList<Message>()) } | ||
|
||
return ChatScreen.State(messages = messages) { event -> | ||
when (event) { | ||
is ChatScreen.Event.SendMessage -> { | ||
val newMessage = Message(event.message, isMe = true) | ||
messages = messages + newMessage | ||
val response = Message(callApi(event.message), isMe = false) | ||
messages = messages + response | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun callApi(message: String): String { | ||
// function set up to call the DevXP API in the future. | ||
// right now, just sends back the user input message | ||
return ("I am a bot. You said \"${message}\"") | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
skate-plugin/project-gen/src/jvmMain/kotlin/slack/tooling/aibot/ChatScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2024 Slack Technologies, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package slack.tooling.aibot | ||
|
||
import com.slack.circuit.runtime.CircuitUiEvent | ||
import com.slack.circuit.runtime.CircuitUiState | ||
import com.slack.circuit.runtime.screen.Screen | ||
|
||
object ChatScreen : Screen { | ||
data class State(val messages: List<Message>, val eventSink: (Event) -> Unit = {}) : | ||
CircuitUiState | ||
|
||
sealed class Event : CircuitUiEvent { | ||
data class SendMessage(val message: String) : Event() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
skate-plugin/project-gen/src/jvmMain/kotlin/slack/tooling/aibot/Message.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (C) 2024 Slack Technologies, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package slack.tooling.aibot | ||
|
||
import androidx.compose.runtime.Immutable | ||
|
||
@Immutable data class Message(val text: String, val isMe: Boolean) |