learning api
This commit is contained in:
@@ -8,11 +8,13 @@ import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import mu.KotlinLogging
|
||||
import net.folivo.trixnity.appservice.rest.DefaultAppserviceService
|
||||
import net.folivo.trixnity.appservice.rest.MatrixAppserviceProperties
|
||||
import net.folivo.trixnity.appservice.rest.matrixAppserviceModule
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.core.model.events.Event
|
||||
import net.folivo.trixnity.core.model.events.MessageEventContent
|
||||
import net.folivo.trixnity.core.model.events.m.room.CreateEventContent
|
||||
import net.folivo.trixnity.core.model.events.m.room.RoomMessageEventContent
|
||||
|
||||
@@ -20,6 +22,8 @@ val matrixClient = MatrixApiClient(
|
||||
baseUrl = Url("http://okupamicoche-synapse:8008/"),
|
||||
).apply { accessToken.value = "30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46" }
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
suspend fun main() {
|
||||
coroutineScope {
|
||||
val appserviceService = DefaultAppserviceService(
|
||||
@@ -27,17 +31,29 @@ suspend fun main() {
|
||||
)
|
||||
|
||||
appserviceService.subscribeAllEvents {
|
||||
println(it)
|
||||
logger.debug("All events: $it")
|
||||
}
|
||||
|
||||
appserviceService.subscribe<CreateEventContent> {
|
||||
if (it is Event.RoomEvent) {
|
||||
println("${it.content.creator} created ${it.roomId}")
|
||||
logger.info("${it.content.creator} created room ${it.roomId}")
|
||||
}
|
||||
}
|
||||
|
||||
appserviceService.subscribe<RoomMessageEventContent.TextMessageEventContent> {
|
||||
println("TextMessageEventContent body=${it.content.body}")
|
||||
if (it is Event.MessageEvent) {
|
||||
val roomId = it.roomId
|
||||
logger.info("${it.sender} sent \"${it.content.body}\" on $roomId")
|
||||
|
||||
if (it.content.body.startsWith("!travel")) {
|
||||
logger.info("send!")
|
||||
matrixClient.rooms.joinRoom(roomId)
|
||||
matrixClient.rooms.sendMessageEvent(
|
||||
roomId,
|
||||
RoomMessageEventContent.TextMessageEventContent("Te creo un viaje?")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package eu.fosil.okupamicoche.services
|
||||
|
||||
import mu.KotlinLogging
|
||||
import net.folivo.trixnity.appservice.rest.event.AppserviceEventTnxService
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
class EventTnxService : AppserviceEventTnxService {
|
||||
override suspend fun eventTnxProcessingState(tnxId: String): AppserviceEventTnxService.EventTnxProcessingState {
|
||||
println("eventTnxProcessingState tnxId=$tnxId")
|
||||
logger.debug("eventTnxProcessingState tnxId=$tnxId")
|
||||
return AppserviceEventTnxService.EventTnxProcessingState.NOT_PROCESSED
|
||||
// return AppserviceEventTnxService.EventTnxProcessingState.PROCESSED
|
||||
}
|
||||
|
||||
override suspend fun onEventTnxProcessed(tnxId: String) {
|
||||
println("onEventTnxProcessed tnxId=$tnxId")
|
||||
logger.debug("onEventTnxProcessed tnxId=$tnxId")
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,31 @@
|
||||
package eu.fosil.okupamicoche.services
|
||||
|
||||
import eu.fosil.okupamicoche.matrixClient
|
||||
import mu.KotlinLogging
|
||||
import net.folivo.trixnity.appservice.rest.room.AppserviceRoomService
|
||||
import net.folivo.trixnity.appservice.rest.room.CreateRoomParameter
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.client.api.model.rooms.Visibility
|
||||
import net.folivo.trixnity.core.model.RoomAliasId
|
||||
import net.folivo.trixnity.core.model.RoomId
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
class RoomService : AppserviceRoomService {
|
||||
override val matrixApiClient: MatrixApiClient
|
||||
get() = matrixClient
|
||||
|
||||
override suspend fun getCreateRoomParameter(roomAlias: RoomAliasId): CreateRoomParameter {
|
||||
println("getCreateRoomParameter")
|
||||
return CreateRoomParameter()
|
||||
logger.info("getCreateRoomParameter")
|
||||
return CreateRoomParameter(Visibility.PUBLIC)
|
||||
}
|
||||
|
||||
override suspend fun onCreatedRoom(roomAlias: RoomAliasId, roomId: RoomId) {
|
||||
println("onCreatedRoom")
|
||||
logger.info("onCreatedRoom")
|
||||
}
|
||||
|
||||
override suspend fun roomExistingState(roomAlias: RoomAliasId): AppserviceRoomService.RoomExistingState {
|
||||
println("roomExistingState")
|
||||
logger.info("roomExistingState")
|
||||
return AppserviceRoomService.RoomExistingState.DOES_NOT_EXISTS
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
<pattern>%-5level %logger{36} - %msg%n</pattern>
|
||||
<!-- <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>-->
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
|
||||
Reference in New Issue
Block a user