diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/Skill.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/Skill.kt index 4af70ad..5b3d321 100644 --- a/alice-ktx/src/main/kotlin/com/github/alice/ktx/Skill.kt +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/Skill.kt @@ -6,8 +6,8 @@ import com.github.alice.ktx.middleware.MiddlewareType import com.github.alice.ktx.fsm.models.FSMStrategy import com.github.alice.ktx.models.request.MessageRequest import com.github.alice.ktx.models.response.MessageResponse -import com.github.alice.ktx.server.WebServer -import com.github.alice.ktx.server.WebServerListener +import com.github.alice.ktx.webhook.WebhookServer +import com.github.alice.ktx.webhook.WebhookServerListener import com.github.alice.ktx.fsm.FSMContext import com.github.alice.ktx.fsm.MutableFSMContext import com.github.alice.ktx.fsm.impl.BaseFSMContext @@ -30,11 +30,11 @@ fun skill(body: Skill.Builder.() -> Unit): Skill = Skill.Builder().apply(body).b /** * Класс `Skill` представляет собой навык, который обрабатывает запросы и управляет состоянием. * - * @property webServer Сервер для прослушивания запросов. + * @property webhookServer Сервер для прослушивания запросов. * @property dispatcher Объект для управления обработчиками команд, мидлварами и обработчиками сетевых ошибок. */ class Skill internal constructor( - private val webServer: WebServer, + private val webhookServer: WebhookServer, private val dispatcher: Dispatcher, private val dialogApi: DialogApi?, private val defaultFSMStrategy: FSMStrategy, @@ -48,7 +48,7 @@ class Skill internal constructor( @AliceDsl class Builder { - lateinit var webServer: WebServer + lateinit var webhookServer: WebhookServer var skillId: String? = null var json: Json = Json { @@ -69,7 +69,7 @@ class Skill internal constructor( fun build(): Skill { return Skill( - webServer = webServer, + webhookServer = webhookServer, dialogApi = dialogApi, defaultFSMStrategy = defaultFSMStrategy, fsmContext = fsmContext, @@ -83,16 +83,15 @@ class Skill internal constructor( * Запускает сервер и начинает обработку входящих запросов. */ fun run() { - val webServerCallback = webServerResponseCallback() - webServer.run(webServerCallback) + webhookServer.run(webhookServerListener()) } /** * Создает слушатель для обработки запросов и ошибок от веб-сервера. * - * @return Реализованный объект `WebServerResponseListener`, который обрабатывает входящие сообщения и ошибки. + * @return Реализованный объект `WebhookServerListener`, который обрабатывает входящие сообщения и ошибки. */ - private fun webServerResponseCallback(): WebServerListener = object : WebServerListener { + private fun webhookServerListener(): WebhookServerListener = object : WebhookServerListener { override suspend fun handleRequest(model: MessageRequest): MessageResponse? { val requestEnvironment = createRequestEnvironment(model) diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/environments/ShouldRequestEnvironment.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/environments/ShouldRequestEnvironment.kt index d61c016..a169f09 100644 --- a/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/environments/ShouldRequestEnvironment.kt +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/environments/ShouldRequestEnvironment.kt @@ -12,7 +12,7 @@ interface ShouldRequestEnvironment { val context: ReadOnlyFSMContext val dialogApi: DialogApi? - fun filter(filter: Filter): Boolean { + fun isValidFor(filter: Filter): Boolean { return filter.checkFor(this) } } \ No newline at end of file diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/AudioPlayerHandler.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/AudioPlayerHandler.kt new file mode 100644 index 0000000..991f5c3 --- /dev/null +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/AudioPlayerHandler.kt @@ -0,0 +1,61 @@ +package com.github.alice.ktx.handlers.impl + +import com.github.alice.ktx.Dispatcher +import com.github.alice.ktx.common.AliceDsl +import com.github.alice.ktx.handlers.Handler +import com.github.alice.ktx.handlers.environments.ProcessRequestEnvironment +import com.github.alice.ktx.handlers.environments.ShouldRequestEnvironment +import com.github.alice.ktx.models.request.content.RequestContentType +import com.github.alice.ktx.models.response.MessageResponse + +@AliceDsl +data class AudioPlayerShouldRequestEnvironment( + private val request: ShouldRequestEnvironment +) : ShouldRequestEnvironment by request { + + val type = message.request.type + val error = message.request.error +} + +@AliceDsl +data class AudioPlayerProcessRequestEnvironment( + private val request: ProcessRequestEnvironment +) : ProcessRequestEnvironment by request { + + val type = message.request.type + val error = message.request.error +} + +@AliceDsl +fun Dispatcher.audioPlayer( + shouldHandle: suspend AudioPlayerShouldRequestEnvironment.() -> Boolean = { true }, + processRequest: suspend AudioPlayerProcessRequestEnvironment.() -> MessageResponse +) { + addHandler( + AudioPlayerHandler( + shouldHandleBlock = shouldHandle, + processRequestBlock = processRequest + ) + ) +} + +internal class AudioPlayerHandler ( + private val shouldHandleBlock: suspend AudioPlayerShouldRequestEnvironment.() -> Boolean, + private val processRequestBlock: suspend AudioPlayerProcessRequestEnvironment.() -> MessageResponse +): Handler { + override suspend fun shouldHandle(request: ShouldRequestEnvironment): Boolean { + val audioPlayerTypes = setOf( + RequestContentType.AudioPlayerPlaybackStarted, + RequestContentType.AudioPlayerPlaybackFinished, + RequestContentType.AudioPlayerPlaybackNearlyFinished, + RequestContentType.AudioPlayerPlaybackStopped, + RequestContentType.AudioPlayerPlaybackFailed, + ) + + return request.message.request.type in audioPlayerTypes && shouldHandleBlock(AudioPlayerShouldRequestEnvironment(request)) + } + + override suspend fun processRequest(request: ProcessRequestEnvironment): MessageResponse { + return processRequestBlock(AudioPlayerProcessRequestEnvironment(request)) + } +} \ No newline at end of file diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/MessageHandler.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/MessageHandler.kt index a9e5353..c293765 100644 --- a/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/MessageHandler.kt +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/MessageHandler.kt @@ -5,6 +5,8 @@ import com.github.alice.ktx.common.AliceDsl import com.github.alice.ktx.handlers.Handler import com.github.alice.ktx.handlers.environments.ProcessRequestEnvironment import com.github.alice.ktx.handlers.environments.ShouldRequestEnvironment +import com.github.alice.ktx.handlers.filters.Filter +import com.github.alice.ktx.models.request.content.RequestContentType import com.github.alice.ktx.models.response.MessageResponse /** @@ -17,6 +19,7 @@ data class MessageShouldHandleEnvironment( val command = request.message.request.command ?: "" val messageText = request.message.request.originalUtterance ?: "" + val nlu = request.message.request.nlu } /** @@ -29,6 +32,18 @@ data class MessageProcessRequestEnvironment( val command = request.message.request.command ?: "" val messageText = request.message.request.originalUtterance ?: "" + val nlu = request.message.request.nlu +} + +@AliceDsl +fun Dispatcher.message( + filter: Filter, + processRequest: suspend MessageProcessRequestEnvironment.() -> MessageResponse +) { + message( + shouldHandle = { filter.checkFor(this) }, + processRequest = processRequest + ) } /** @@ -67,9 +82,7 @@ internal class MessageHandler( * @return `true`, если обработчик должен сработать, в противном случае `false`. */ override suspend fun shouldHandle(request: ShouldRequestEnvironment): Boolean { - return request.message.request.command != null && - request.message.request.originalUtterance != null && - shouldHandleBlock(MessageShouldHandleEnvironment(request)) + return request.message.request.type == RequestContentType.SimpleUtterance && shouldHandleBlock(MessageShouldHandleEnvironment(request)) } /** diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/PurchaseConfirmationHandler.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/PurchaseConfirmationHandler.kt new file mode 100644 index 0000000..cd8e16c --- /dev/null +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/PurchaseConfirmationHandler.kt @@ -0,0 +1,64 @@ +package com.github.alice.ktx.handlers.impl + +import com.github.alice.ktx.Dispatcher +import com.github.alice.ktx.common.AliceDsl +import com.github.alice.ktx.handlers.Handler +import com.github.alice.ktx.handlers.environments.ProcessRequestEnvironment +import com.github.alice.ktx.handlers.environments.ShouldRequestEnvironment +import com.github.alice.ktx.models.request.content.RequestContentType +import com.github.alice.ktx.models.response.MessageResponse + +@AliceDsl +data class PurchaseConfirmationShouldRequestEnvironment( + private val request: ShouldRequestEnvironment +) : ShouldRequestEnvironment by request { + + val purchaseRequestId = message.request.purchaseRequestId + val purchaseToken = message.request.purchaseToken + val orderId = message.request.orderId + val purchaseTimestamp = message.request.purchaseTimestamp + val purchasePayload = message.request.purchasePayload + val signedData = message.request.signedData + val signature = message.request.signature +} + +@AliceDsl +data class PurchaseConfirmationProcessRequestEnvironment( + private val request: ProcessRequestEnvironment +) : ProcessRequestEnvironment by request { + + val purchaseRequestId = message.request.purchaseRequestId + val purchaseToken = message.request.purchaseToken + val orderId = message.request.orderId + val purchaseTimestamp = message.request.purchaseTimestamp + val purchasePayload = message.request.purchasePayload + val signedData = message.request.signedData + val signature = message.request.signature +} + +@AliceDsl +fun Dispatcher.purchaseConfirmation( + shouldHandle: suspend PurchaseConfirmationShouldRequestEnvironment.() -> Boolean = { true }, + processRequest: suspend PurchaseConfirmationProcessRequestEnvironment.() -> MessageResponse +) { + addHandler( + PurchaseConfirmationHandler( + shouldHandleBlock = shouldHandle, + processRequestBlock = processRequest + ) + ) +} + +internal class PurchaseConfirmationHandler( + private val shouldHandleBlock: suspend PurchaseConfirmationShouldRequestEnvironment.() -> Boolean, + private val processRequestBlock: suspend PurchaseConfirmationProcessRequestEnvironment.() -> MessageResponse +): Handler { + override suspend fun shouldHandle(request: ShouldRequestEnvironment): Boolean { + return request.message.request.type == RequestContentType.PurchaseConfirmation + && shouldHandleBlock(PurchaseConfirmationShouldRequestEnvironment(request)) + } + + override suspend fun processRequest(request: ProcessRequestEnvironment): MessageResponse { + return processRequestBlock(PurchaseConfirmationProcessRequestEnvironment(request)) + } +} \ No newline at end of file diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/ShowPullHandler.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/ShowPullHandler.kt new file mode 100644 index 0000000..2d16871 --- /dev/null +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/ShowPullHandler.kt @@ -0,0 +1,52 @@ +package com.github.alice.ktx.handlers.impl + +import com.github.alice.ktx.Dispatcher +import com.github.alice.ktx.common.AliceDsl +import com.github.alice.ktx.handlers.Handler +import com.github.alice.ktx.handlers.environments.ProcessRequestEnvironment +import com.github.alice.ktx.handlers.environments.ShouldRequestEnvironment +import com.github.alice.ktx.models.request.content.RequestContentType +import com.github.alice.ktx.models.response.MessageResponse + +@AliceDsl +data class ShowPullShouldRequestEnvironment( + private val request: ShouldRequestEnvironment +) : ShouldRequestEnvironment by request { + + val showType = checkNotNull(request.message.request.showType) +} + +@AliceDsl +data class ShowPullProcessRequestEnvironment( + private val request: ProcessRequestEnvironment +) : ProcessRequestEnvironment by request { + + val showType = checkNotNull(request.message.request.showType) +} + +@AliceDsl +fun Dispatcher.showPull( + shouldHandle: suspend ShowPullShouldRequestEnvironment.() -> Boolean = { true }, + processRequest: suspend ShowPullProcessRequestEnvironment.() -> MessageResponse +) { + addHandler( + ShowPullHandler( + shouldHandleBlock = shouldHandle, + processRequestBlock = processRequest + ) + ) +} + +internal class ShowPullHandler( + private val shouldHandleBlock: suspend ShowPullShouldRequestEnvironment.() -> Boolean, + private val processRequestBlock: suspend ShowPullProcessRequestEnvironment.() -> MessageResponse +) : Handler { + override suspend fun shouldHandle(request: ShouldRequestEnvironment): Boolean { + return request.message.request.type == RequestContentType.ShowPull + && shouldHandleBlock(ShowPullShouldRequestEnvironment(request)) + } + + override suspend fun processRequest(request: ProcessRequestEnvironment): MessageResponse { + return processRequestBlock(ShowPullProcessRequestEnvironment(request)) + } +} \ No newline at end of file diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/server/WebServer.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/server/WebServer.kt deleted file mode 100644 index 3a635b2..0000000 --- a/alice-ktx/src/main/kotlin/com/github/alice/ktx/server/WebServer.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.alice.ktx.server - -/** - * Интерфейс `WebServer` определяет контракт для веб-сервера, который может быть запущен и обрабатывать запросы. - */ -interface WebServer { - - /** - * Запускает веб-сервер и начинает обработку запросов. - * - * @param listener Обработчик, который будет вызван при получении запроса. - */ - fun run(listener: WebServerListener) - -} \ No newline at end of file diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/storage/impl/MemoryStorage.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/storage/impl/MemoryStorage.kt index 1e286ce..6c763de 100644 --- a/alice-ktx/src/main/kotlin/com/github/alice/ktx/storage/impl/MemoryStorage.kt +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/storage/impl/MemoryStorage.kt @@ -7,6 +7,7 @@ import com.github.alice.ktx.storage.key.KeyBuilder import com.github.alice.ktx.storage.key.impl.baseKeyBuilder import com.github.alice.ktx.storage.models.* import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.serializer import kotlin.reflect.KClass diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/WebhookServer.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/WebhookServer.kt new file mode 100644 index 0000000..a784dd6 --- /dev/null +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/WebhookServer.kt @@ -0,0 +1,15 @@ +package com.github.alice.ktx.webhook + +/** + * Интерфейс `WebhookServer` определяет контракт для веб-сервера, который может быть запущен и обрабатывать запросы. + */ +interface WebhookServer { + + /** + * Запускает веб-сервер и начинает обработку запросов. + * + * @param listener Обработчик, который будет вызван при получении запроса. + */ + fun run(listener: WebhookServerListener) + +} \ No newline at end of file diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/server/WebServerListener.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/WebhookServerListener.kt similarity index 74% rename from alice-ktx/src/main/kotlin/com/github/alice/ktx/server/WebServerListener.kt rename to alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/WebhookServerListener.kt index 812a7f0..2db1d14 100644 --- a/alice-ktx/src/main/kotlin/com/github/alice/ktx/server/WebServerListener.kt +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/WebhookServerListener.kt @@ -1,13 +1,13 @@ -package com.github.alice.ktx.server +package com.github.alice.ktx.webhook import com.github.alice.ktx.models.request.MessageRequest import com.github.alice.ktx.models.response.MessageResponse import java.lang.Exception /** - * Интерфейс `WebServerListener` представляет собой обработчик, который будет вызываться при получении запроса веб-сервером. + * Интерфейс `WebhookServerListener` представляет собой обработчик, который будет вызываться при получении запроса веб-сервером. */ -interface WebServerListener { +interface WebhookServerListener { /** * Вызывается при получении запроса от Яндекс Диалогов diff --git a/alice-ktx/src/main/kotlin/com/github/alice/ktx/server/impl/KtorWebServer.kt b/alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/impl/KtorWebhookServer.kt similarity index 73% rename from alice-ktx/src/main/kotlin/com/github/alice/ktx/server/impl/KtorWebServer.kt rename to alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/impl/KtorWebhookServer.kt index a16cba6..bec9ee3 100644 --- a/alice-ktx/src/main/kotlin/com/github/alice/ktx/server/impl/KtorWebServer.kt +++ b/alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/impl/KtorWebhookServer.kt @@ -1,10 +1,10 @@ -package com.github.alice.ktx.server.impl +package com.github.alice.ktx.webhook.impl import com.github.alice.ktx.Skill import com.github.alice.ktx.common.AliceDsl import com.github.alice.ktx.models.request.MessageRequest -import com.github.alice.ktx.server.WebServer -import com.github.alice.ktx.server.WebServerListener +import com.github.alice.ktx.webhook.WebhookServer +import com.github.alice.ktx.webhook.WebhookServerListener import io.ktor.serialization.kotlinx.json.* import io.ktor.server.application.* import io.ktor.server.engine.* @@ -16,35 +16,35 @@ import io.ktor.server.routing.* import kotlinx.serialization.json.Json /** - * Создает экземпляр `KtorWebServer` с заданной конфигурацией. + * Создает экземпляр `ktorWebhookServer` с заданной конфигурацией. * - * @param body Функция, принимающая объект `KtorWebServer.Builder` и выполняющая настройку. - * Эта функция будет вызвана в контексте `KtorWebServer.Builder`. - * @return Настроенный объект `KtorWebServer`. + * @param body Функция, принимающая объект `KtorWebhookServer.Builder` и выполняющая настройку. + * Эта функция будет вызвана в контексте `KtorWebhookServer.Builder`. + * @return Настроенный объект `KtorWebhookServer`. */ @AliceDsl -fun Skill.Builder.ktorWebServer(body: KtorWebServer.Builder.() -> Unit): KtorWebServer { - return KtorWebServer.Builder().json(json).build(body) +fun Skill.Builder.ktorWebhookServer(body: KtorWebhookServer.Builder.() -> Unit): KtorWebhookServer { + return KtorWebhookServer.Builder().json(json).build(body) } /** - * Класс `KtorWebServer` представляет собой веб-сервер, работающий на основе Ktor. + * Класс `KtorWebhookServer` представляет собой веб-сервер, работающий на основе Ktor. * * @property port Порт, на котором будет запущен веб-сервер. * @property path Путь, по которому будет доступен веб-сервер. * @property json Конфигурация для обработки JSON данных. * @property configuration Конфигурация для приложения Ktor. */ -class KtorWebServer internal constructor( +class KtorWebhookServer internal constructor( private val port: Int, private val path: String, private val host: String, private val json: Json, private val configuration: Application.() -> Unit -): WebServer { +): WebhookServer { /** - * Класс `Builder` предназначен для настройки и создания экземпляра `KtorWebServer`. + * Класс `Builder` предназначен для настройки и создания экземпляра `KtorWebhookServer`. */ @AliceDsl class Builder { @@ -59,9 +59,9 @@ class KtorWebServer internal constructor( return this } - fun build(body: Builder.() -> Unit): KtorWebServer { + fun build(body: Builder.() -> Unit): KtorWebhookServer { body.invoke(this) - return KtorWebServer( + return KtorWebhookServer( port = port, path = path, host = host, @@ -71,7 +71,7 @@ class KtorWebServer internal constructor( } } - override fun run(listener: WebServerListener) { + override fun run(listener: WebhookServerListener) { embeddedServer(Netty, port = port, host = host) { install(ContentNegotiation) { diff --git a/examples/src/main/kotlin/com/github/examples/Analytics.kt b/examples/src/main/kotlin/com/github/examples/Analytics.kt index d6ec366..4d82162 100644 --- a/examples/src/main/kotlin/com/github/examples/Analytics.kt +++ b/examples/src/main/kotlin/com/github/examples/Analytics.kt @@ -6,12 +6,12 @@ import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.models.response.analytics.Analytics import com.github.alice.ktx.models.response.analytics.AnalyticsEvent import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill fun main() { skill { - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/AudioPlayer.kt b/examples/src/main/kotlin/com/github/examples/AudioPlayer.kt index 0521a8a..252ee91 100644 --- a/examples/src/main/kotlin/com/github/examples/AudioPlayer.kt +++ b/examples/src/main/kotlin/com/github/examples/AudioPlayer.kt @@ -4,13 +4,13 @@ import com.github.alice.ktx.dispatch import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.models.response.audioPlayer.audioPlayer import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/Authorization.kt b/examples/src/main/kotlin/com/github/examples/Authorization.kt index a90a173..1d8d02d 100644 --- a/examples/src/main/kotlin/com/github/examples/Authorization.kt +++ b/examples/src/main/kotlin/com/github/examples/Authorization.kt @@ -4,13 +4,13 @@ import com.github.alice.ktx.dispatch import com.github.alice.ktx.handlers.impl.message import com.github.alice.ktx.models.response.authorization import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/Button.kt b/examples/src/main/kotlin/com/github/examples/Button.kt index db5d39e..5e4e254 100644 --- a/examples/src/main/kotlin/com/github/examples/Button.kt +++ b/examples/src/main/kotlin/com/github/examples/Button.kt @@ -1,12 +1,12 @@ package com.github.examples import com.github.alice.ktx.dispatch -import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.handlers.impl.message +import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.models.response.button.button import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer import com.github.alice.ktx.skill +import com.github.alice.ktx.webhook.impl.ktorWebhookServer private enum class SchedulesType(val title: String) { LAST_DAY("Последний день"), @@ -17,7 +17,7 @@ private enum class SchedulesType(val title: String) { fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/Cards.kt b/examples/src/main/kotlin/com/github/examples/Cards.kt index 881eb09..fffff90 100644 --- a/examples/src/main/kotlin/com/github/examples/Cards.kt +++ b/examples/src/main/kotlin/com/github/examples/Cards.kt @@ -3,10 +3,9 @@ package com.github.examples import com.github.alice.ktx.dispatch import com.github.alice.ktx.handlers.impl.message import com.github.alice.ktx.models.response.button.mediaButton -import com.github.alice.ktx.models.card.* import com.github.alice.ktx.models.response.card.* import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill // Замените идентификатор изображения на свой собственный @@ -15,7 +14,7 @@ private const val IMAGE_ID = "1521359/48faa5e0f3d3842a6329" fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/Echo.kt b/examples/src/main/kotlin/com/github/examples/Echo.kt index ccc4811..6094e33 100644 --- a/examples/src/main/kotlin/com/github/examples/Echo.kt +++ b/examples/src/main/kotlin/com/github/examples/Echo.kt @@ -1,17 +1,16 @@ package com.github.examples import com.github.alice.ktx.dispatch -import com.github.alice.ktx.handlers.error.responseFailure import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.handlers.impl.message import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/ErrorHandling.kt b/examples/src/main/kotlin/com/github/examples/ErrorHandling.kt index 65d062e..c490b84 100644 --- a/examples/src/main/kotlin/com/github/examples/ErrorHandling.kt +++ b/examples/src/main/kotlin/com/github/examples/ErrorHandling.kt @@ -4,13 +4,13 @@ import com.github.alice.ktx.dispatch import com.github.alice.ktx.handlers.error.responseFailure import com.github.alice.ktx.handlers.impl.message import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/FSMContextTypedData.kt b/examples/src/main/kotlin/com/github/examples/FSMContextTypedData.kt index c097d77..028595a 100644 --- a/examples/src/main/kotlin/com/github/examples/FSMContextTypedData.kt +++ b/examples/src/main/kotlin/com/github/examples/FSMContextTypedData.kt @@ -9,7 +9,7 @@ import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.fsm.models.FSMStrategy import com.github.alice.ktx.models.response.button.button import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill import com.github.alice.ktx.storage.impl.redisStorage import com.github.alice.ktx.storage.key.impl.baseKeyBuilder @@ -38,7 +38,7 @@ fun main() { prefix = "alice" } } - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/Filters.kt b/examples/src/main/kotlin/com/github/examples/Filters.kt index 3852df1..23c0b0c 100644 --- a/examples/src/main/kotlin/com/github/examples/Filters.kt +++ b/examples/src/main/kotlin/com/github/examples/Filters.kt @@ -3,19 +3,18 @@ package com.github.examples import com.github.alice.ktx.dispatch import com.github.alice.ktx.handlers.filters.Filter import com.github.alice.ktx.handlers.impl.message -import com.github.alice.ktx.handlers.impl.request import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill fun main() { skill { - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } dispatch { - message({ filter(Filter.All) }) { + message({ isValidFor(Filter.All) }) { response { text = messageText } diff --git a/examples/src/main/kotlin/com/github/examples/FsmForm.kt b/examples/src/main/kotlin/com/github/examples/FsmForm.kt index 4152bb7..3d7bc67 100644 --- a/examples/src/main/kotlin/com/github/examples/FsmForm.kt +++ b/examples/src/main/kotlin/com/github/examples/FsmForm.kt @@ -6,7 +6,7 @@ import com.github.alice.ktx.handlers.impl.message import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.models.response.button.button import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill import com.github.alice.ktx.storage.impl.redisStorage import com.github.alice.ktx.storage.key.impl.baseKeyBuilder @@ -19,7 +19,7 @@ enum class FormState { fun main() { skill { - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/Handlers.kt b/examples/src/main/kotlin/com/github/examples/Handlers.kt index 017c45e..e213caf 100644 --- a/examples/src/main/kotlin/com/github/examples/Handlers.kt +++ b/examples/src/main/kotlin/com/github/examples/Handlers.kt @@ -5,7 +5,7 @@ import com.github.alice.ktx.handlers.impl.buttonPressed import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.models.response.button.button import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill /** @@ -13,7 +13,7 @@ import com.github.alice.ktx.skill * */ fun main() { skill { - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/ImageDialogsApi.kt b/examples/src/main/kotlin/com/github/examples/ImageDialogsApi.kt index 17f3749..b5ab18b 100644 --- a/examples/src/main/kotlin/com/github/examples/ImageDialogsApi.kt +++ b/examples/src/main/kotlin/com/github/examples/ImageDialogsApi.kt @@ -9,14 +9,14 @@ import com.github.alice.ktx.models.response.button.mediaButton import com.github.alice.ktx.models.response.card.cardItemsList import com.github.alice.ktx.models.response.card.item import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill import java.io.File fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/Info.kt b/examples/src/main/kotlin/com/github/examples/Info.kt index e0463b4..a15394c 100644 --- a/examples/src/main/kotlin/com/github/examples/Info.kt +++ b/examples/src/main/kotlin/com/github/examples/Info.kt @@ -4,7 +4,7 @@ import com.github.alice.ktx.dispatch import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.handlers.impl.message import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill import com.github.alice.ktx.storage.impl.apiStorage @@ -18,7 +18,7 @@ fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/SoundDialogsApi.kt b/examples/src/main/kotlin/com/github/examples/SoundDialogsApi.kt index 0bf1298..a34fb27 100644 --- a/examples/src/main/kotlin/com/github/examples/SoundDialogsApi.kt +++ b/examples/src/main/kotlin/com/github/examples/SoundDialogsApi.kt @@ -5,14 +5,14 @@ import com.github.alice.ktx.api.dialog.yandex.impl.ktorYandexDialogApi import com.github.alice.ktx.dispatch import com.github.alice.ktx.handlers.impl.message import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill import java.io.File fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/chatgpt/ChatGPT.kt b/examples/src/main/kotlin/com/github/examples/chatgpt/ChatGPT.kt index 40839f3..d8e387f 100644 --- a/examples/src/main/kotlin/com/github/examples/chatgpt/ChatGPT.kt +++ b/examples/src/main/kotlin/com/github/examples/chatgpt/ChatGPT.kt @@ -1,7 +1,7 @@ package com.github.examples.chatgpt import com.github.alice.ktx.dispatch -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill import com.github.examples.chatgpt.handlers.baseHandlers import com.github.examples.chatgpt.handlers.chatHandlers @@ -13,7 +13,7 @@ fun main() { val responseManager = ResponseManager() skill { - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" } diff --git a/examples/src/main/kotlin/com/github/examples/cities/CitiesGameSkill.kt b/examples/src/main/kotlin/com/github/examples/cities/CitiesGameSkill.kt index a794969..17df1a0 100644 --- a/examples/src/main/kotlin/com/github/examples/cities/CitiesGameSkill.kt +++ b/examples/src/main/kotlin/com/github/examples/cities/CitiesGameSkill.kt @@ -5,7 +5,7 @@ import com.github.alice.ktx.handlers.impl.newSession import com.github.alice.ktx.handlers.impl.message import com.github.alice.ktx.middleware.outerMiddleware import com.github.alice.ktx.models.response.response -import com.github.alice.ktx.server.impl.ktorWebServer +import com.github.alice.ktx.webhook.impl.ktorWebhookServer import com.github.alice.ktx.skill import com.github.examples.cities.data.CitiesGameService @@ -19,7 +19,7 @@ fun main() { skill { skillId = "..." - webServer = ktorWebServer { + webhookServer = ktorWebhookServer { port = 8080 path = "/alice" }