Unverified Commit 89713504 authored by seykron's avatar seykron

Adds hello-world example project

parent b1ae7d84
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.rlab</groupId>
<artifactId>hellobot</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<!-- Maven -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<h2.version>1.4.197</h2.version>
<tehanu.version>2.1.1-SNAPSHOT</tehanu.version>
<kotlin.version>1.3.40</kotlin.version>
<kotlin-coroutines.version>1.1.1</kotlin-coroutines.version>
<kotlin.code.style>official</kotlin.code.style>
</properties>
<dependencies>
<!-- Kotlin -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<!-- Telegram -->
<dependency>
<groupId>be.rlab</groupId>
<artifactId>tehanu-core</artifactId>
<version>${tehanu.version}</version>
</dependency>
<dependency>
<groupId>be.rlab</groupId>
<artifactId>tehanu-spring</artifactId>
<version>${tehanu.version}</version>
</dependency>
<!-- Data access -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>
<build>
<finalName>hellobot</finalName>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>be.rlab.hellobot.MainKt</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- Repositories -->
<repositories>
<repository>
<id>kotlin-eap</id>
<name>Kotlin EAP Repository</name>
<url>http://dl.bintray.com/kotlin/kotlin-eap</url>
</repository>
<repository>
<id>jcenter</id>
<name>JCenter Repository</name>
<url>https://jcenter.bintray.com</url>
</repository>
<repository>
<id>jitpack</id>
<name>JitPack Repository</name>
<url>https://jitpack.io</url>
</repository>
</repositories>
</project>
package be.rlab.hellobot
import be.rlab.hellobot.SayHello
import org.springframework.context.support.beans
object ApplicationBeans {
fun beans() = beans {
bean {
SayHello(
name = "/can_haz_kitten",
botName = "@hellobot"
)
}
}
}
package be.rlab.hellobot
import be.rlab.tehanu.SpringApplication
import be.rlab.tehanu.util.persistence.DataSourceInitializer
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.getBean
class Main : SpringApplication() {
private val logger: Logger = LoggerFactory.getLogger(Main::class.java)
override fun initialize() {
ApplicationBeans.beans().initialize(applicationContext)
}
override fun ready() {
logger.info("Initializing data source")
val dataSourceInitializer: DataSourceInitializer = applicationContext.getBean()
dataSourceInitializer.initAuto()
}
}
fun main(args: Array<String>) {
Main().start()
}
package be.rlab.hellobot
import be.rlab.tehanu.domain.MessageContext
import be.rlab.tehanu.domain.MessageListener
import be.rlab.tehanu.domain.model.Chat
import be.rlab.tehanu.domain.model.Message
import be.rlab.tehanu.domain.model.TextMessage
import be.rlab.tehanu.domain.model.User
class SayHello(
override val name: String,
private val botName: String
) : MessageListener {
override fun applies(
chat: Chat,
user: User?,
message: Message
): Boolean {
return message is TextMessage && message.text.startsWith(botName)
}
override fun handle(
context: MessageContext,
message: Message
): MessageContext {
return context.answer("hello!")
}
}
db {
url: "jdbc:h2:file:/tmp/hellobot-db/cathulhu"
user: "sa"
password: ""
driver: "org.h2.Driver"
log-statements: false
drop: "no"
}
bot {
access_token: ${?bot_access_token}
admins: []
roles: [
{ title: "Administrador", name: "ADMIN", permissions: [ "MANAGE_ADMINS" ] }
]
permissions: [
]
}
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="okhttp3" level="ERROR" />
<logger name="com.sun.mail" level="ERROR" />
<logger name="org.springframework" level="INFO" />
<logger name="Exposed" level="INFO" />
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment