diff --git a/build.gradle.kts b/build.gradle.kts index e312c02..c520347 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,6 +19,10 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + // logback driver and slf4j logging + implementation("ch.qos.logback:logback-core:1.3.0-alpha5") + implementation("org.slf4j:slf4j-api:2.0.0-alpha1") + testImplementation("org.junit.jupiter:junit-jupiter:5.7.0") } diff --git a/src/main/kotlin/com/cubetiqs/messaging/client/telegram/TelegramMessage.kt b/src/main/kotlin/com/cubetiqs/messaging/client/telegram/TelegramMessage.kt index 745c8a2..f20674c 100644 --- a/src/main/kotlin/com/cubetiqs/messaging/client/telegram/TelegramMessage.kt +++ b/src/main/kotlin/com/cubetiqs/messaging/client/telegram/TelegramMessage.kt @@ -8,6 +8,7 @@ import java.io.Serializable * @author sombochea * @since 1.0 */ -interface TelegramMessage : Serializable { +@FunctionalInterface +fun interface TelegramMessage : Serializable { fun getText(): String } \ No newline at end of file diff --git a/src/main/kotlin/com/cubetiqs/messaging/client/telegram/TelegramProvider.kt b/src/main/kotlin/com/cubetiqs/messaging/client/telegram/TelegramProvider.kt index 13167b7..8dd62a1 100644 --- a/src/main/kotlin/com/cubetiqs/messaging/client/telegram/TelegramProvider.kt +++ b/src/main/kotlin/com/cubetiqs/messaging/client/telegram/TelegramProvider.kt @@ -1,7 +1,7 @@ package com.cubetiqs.messaging.client.telegram import com.cubetiqs.messaging.client.provider.MessageProvider -import com.sun.org.slf4j.internal.LoggerFactory +import org.slf4j.LoggerFactory import kotlin.IllegalArgumentException /** @@ -20,7 +20,11 @@ class TelegramProvider : MessageProvider { this._chatId = chatId } - fun messageToSend(message: TelegramMessage?) = apply { + fun setMessage(message: String) = apply { + this._message = TelegramMessage { message } + } + + fun setMessageToSend(message: TelegramMessage?) = apply { this._message = message } @@ -36,6 +40,10 @@ class TelegramProvider : MessageProvider { throw IllegalArgumentException("token must be provide for send message!") } + if (this._message == null) { + this._message = message + } + if (_message?.getText().isNullOrEmpty()) return null return try { @@ -77,7 +85,7 @@ class TelegramProvider : MessageProvider { fun sendMessage(token: String, chatId: String, text: String): Any? { return init(token) .sendToChatId(chatId) - .messageToSend(TelegramChatMessage(text)) + .setMessageToSend(TelegramChatMessage(text)) .send() } }