Skip to content

Commit 6cb1fa0

Browse files
author
AlexMcGil
committed
fix: change initialPlaceholder to lambda
1 parent 2619977 commit 6cb1fa0

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

channels/telegram/src/main/kotlin/com/justai/jaicf/channel/telegram/streaming/StreamConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import com.pengrad.telegrambot.model.request.ParseMode
66
* Configuration for streaming messages in Telegram channel.
77
*
88
* @param updateIntervalMs Interval in milliseconds between message updates during streaming (default: 500ms)
9-
* @param initialPlaceholder Text to show in the initial message before streaming starts (default: "...")
9+
* @param initialPlaceholder Lambda function to generate the initial placeholder text before streaming starts (default: "...")
1010
* @param parseMode Optional parse mode for message formatting (Markdown, HTML, etc.)
1111
*/
1212
data class StreamConfig(
1313
val updateIntervalMs: Long = 500,
14-
val initialPlaceholder: String = "...",
14+
val initialPlaceholder: () -> String = { "..." },
1515
val parseMode: ParseMode = ParseMode.Markdown,
1616
)

channels/telegram/src/main/kotlin/com/justai/jaicf/channel/telegram/streaming/TelegramStreamingHandler.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal class TelegramStreamingHandler(
4747
}
4848

4949
private fun sendInitialMessage() {
50-
val message = sendMessage(config.initialPlaceholder)
50+
val message = sendMessage(config.initialPlaceholder())
5151
currentMessageId = message.messageId()
5252
currentMessageBuffer.clear()
5353
}
@@ -61,7 +61,7 @@ internal class TelegramStreamingHandler(
6161
finalizeCurrentMessage()
6262

6363
// Start new message
64-
val message = sendMessage(config.initialPlaceholder)
64+
val message = sendMessage(config.initialPlaceholder())
6565
currentMessageId = message.messageId()
6666

6767
// Clear buffer and start with the current chunk
@@ -88,7 +88,7 @@ internal class TelegramStreamingHandler(
8888
private fun finalizeCurrentMessage() {
8989
currentMessageId?.let { msgId ->
9090
val textToSend = currentMessageBuffer.toString()
91-
if (textToSend.isNotEmpty() && textToSend != config.initialPlaceholder) {
91+
if (textToSend.isNotEmpty() && textToSend != config.initialPlaceholder()) {
9292
updateMessage(msgId, textToSend)
9393
}
9494
}
@@ -97,7 +97,7 @@ internal class TelegramStreamingHandler(
9797
private fun updateCurrentMessage() {
9898
currentMessageId?.let { msgId ->
9999
val text = currentMessageBuffer.toString()
100-
if (text.isNotEmpty() && text != config.initialPlaceholder) {
100+
if (text.isNotEmpty() && text != config.initialPlaceholder()) {
101101
updateMessage(msgId, text)
102102
}
103103
}

0 commit comments

Comments
 (0)