Skip to content

krindra/VKKT

Repository files navigation

VKKT

Maven Central Version

badge-api-version badge-platform-android badge-platform-jvm badge-platform-js badge-platform-linux badge-platform-macos badge-platform-ios badge-platform-mingw

VK Kotlin API

Just a simple library for VK

is supported:

Examples

import io.ktor.client.*
import ru.krindra.vkkt.core.VkApi
import ru.krindra.vkkt.longpoll.bot.*
import ru.krindra.vkkt.longpoll.user.*

val client = HttpClient()

suspend fun bot() {
    val vkApi = VkApi(botToken, httpClient = client)

    val lp = BotLongPoll(vkApi)
    lp.listen().collect{ e->
        if (e is BotLPUpdate.MessageNewUpdate) {
            if (e.`object`.message.text != "")
                vkApi.messages.send(
                    peerId = e.`object`.message.peerId,
                    message = e.`object`.message.text,
                    randomId = 0
                )
        }
    }
}

suspend fun user() {
    val vkApi = VkApi(userToken, httpClient = client)
    println(vkApi.status.get().text)

    val lp = UserLongPoll(vkApi)
    lp.listen().collect {e ->
        if (e is UserLPUpdate.MessageNewUpdate) {
            print("${e.peerId} ${e.timestamp} - ${e.text}")
        }
    }
}