A simple Spring Boot library to bind the WeMaLa server as a bot. This library is written in Kotlin.
- JDK 11
- Maven
- Kotlin 1.3.30 (comes as maven dependency)
- Spring Boot 2.2.x (comes as maven dependency)
In maven settings.xml
<servers>
<server>
<id>wemala</id>
<username>my-user</username>
<password>my-password</password>
</server>
<server>
<id>wemala-snapshots</id>
<username>my-user</username>
<password>my-password</password>
</server>
</servers><dependency>
<groupId>chat.to</groupId>
<artifactId>spring-boot-server-bot</artifactId>
<version>0.0.1</version>
</dependency>Add bot credentials to application.properties
wemala.server.url=http://dev.to.chat
wemala.bot.identifier=my-bot@to.chat
wemala.bot.username=my-first-bot
wemala.bot.password=my-secure-bot-password@ComponentScan("chat.to")
@SpringBootApplication
class MyWeMaLaBotAdapterApplicationBy using ServerMessageExchangeService.kt you can receive and send messages:
@Component
class ServerMessageScheduler(private var serverMessageExchangeService: ServerMessageExchangeService) {
private val log = LoggerFactory.getLogger(ServerMessageScheduler::class.java)
@Scheduled(fixedRate = 3000)
fun scheduleUnreadMessages() {
log.info("Start retrieving latest messages")
serverMessageExchangeService.retrieveMessages().forEach {
val channelIdentifier = it._links.channel.href.substringAfter("/api/channel/")
log.info("Received message ${it.text} from channel $channelIdentifier")
serverMessageExchangeService.sendMessage(channelIdentifier, "pong")
}
log.info("${retrieveMessages.size} messages retrieved")
}
}No, you don't need an existing WeMaLa server account. If necessary, the bot is generated the first time the messages are loaded.
No, loaded messages are marked as read. This means that no message is loaded twice.
There is a BotStatus.kt, which indicates whether the last messages could be picked up.
You can observe a BotStatus event:
@Component
class BotStatusEventListener {
@EventListener
fun updateStatus(status: BotStatus) {
// do whatever you want
}
}BotStatus.kt consists of the following values
- OK
- AUTHENTICATION_FAILED
- REGISTRATION_FAILED
- RECEIVE_MESSAGES_FAILED
- MARK_MESSAGES_FAILED