Task: Add messaging client for telegram and sms and other utils

This commit is contained in:
Sambo Chea 2021-05-20 19:36:33 +07:00
parent 98bfdb0bf1
commit 104e325043
3 changed files with 17 additions and 4 deletions

View File

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

View File

@ -8,6 +8,7 @@ import java.io.Serializable
* @author sombochea
* @since 1.0
*/
interface TelegramMessage : Serializable {
@FunctionalInterface
fun interface TelegramMessage : Serializable {
fun getText(): String
}

View File

@ -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()
}
}