Skip to content

Commit

Permalink
#139 Add fake telegram bot for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Jun 14, 2024
1 parent 131db92 commit f26ebab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.annotation.Profile
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service
import ru.vityaman.lms.botalka.core.external.telegram.BasicTelegramBot
import ru.vityaman.lms.botalka.core.external.telegram.TelegramBot
import ru.vityaman.lms.botalka.core.external.telegram.TelegramChat
import ru.vityaman.lms.botalka.core.external.telegram.TelegramMessage
import java.net.InetAddress


@Service
@Profile("production")
class SpringTelegramBot(
@Value("\${external.service.telegram.token}")
token: String,
Expand All @@ -34,9 +34,6 @@ class SpringTelegramBot(

@EventListener(ApplicationReadyEvent::class)
fun notifyAdmin() = runBlocking {
val name = InetAddress.getLocalHost().hostName
val address = InetAddress.getLocalHost().hostAddress
val text = "Restarted instance '$name' at '$address'"
send(adminChat, TelegramMessage(text))
send(adminChat, TelegramMessage("Restarted instance"))
}
}
2 changes: 2 additions & 0 deletions botalka/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
spring:
profiles:
active: production
application:
name: botalka
datasource:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.vityaman.lms.botalka.app.spring.client.telegram

import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Primary
import org.springframework.stereotype.Service
import ru.vityaman.lms.botalka.core.external.telegram.TelegramBot
import ru.vityaman.lms.botalka.core.external.telegram.TelegramChat
import ru.vityaman.lms.botalka.core.external.telegram.TelegramMessage

@Primary
@Service
class FakeTelegramBot : TelegramBot {
private val log = LoggerFactory.getLogger("FakeTelegramBot")

override suspend fun send(chat: TelegramChat, message: TelegramMessage) {
log.debug("Received a {} from {}", message, chat)
}

override suspend fun start() {
log.debug("Started")
}
}

0 comments on commit f26ebab

Please sign in to comment.