Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.lamba92:kotlingram-core-metadata

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.lamba92:kotlingram-core-metadata

Telegram Bot APIs for Kotlin Multiplatform

  • 1.1.5
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Kotlingram | Telegram bot API for Kotlin/Multiplatform CI Publication Maven Central Download

Looking for a Kotlin first Telegram APIs? You are in the right place! This project offers Kotlin/Multiplatform APIs for Telegram bots based on Kotlinx.serialization and Ktor client and coroutines.

The APIs are generated by parsing the official Telegram documentation. For sure there are errors since no testing is in place, but message retrieval works!

Usage

For basic API usage you can use the client:

val client = TelegramBotApiClient("botToken")
val user: TelegramResponse<User> = client.getMe()
val user: TelegramResponse<List<Update>> = client.getUpdates()

For building a polling bot with you can use the builder:

fun main(): Unit = runBlocking {
    
    buildPollingBot {
        
        options {
            botApiToken = System.getenv("DRAGALIA_BOT_TOKEN")
            botUsername = "DragaliaBot"
        }

        handlers {
            messages {
                respondText(text = message.text, replyToMessageId = message.messageId)
            }
            inlineQueries {
                respond(
                    listOf(
                        InlineQueryResultArticle(
                            id = "ciao mamma",
                            title = "Hello!",
                            inputMessageContent = InputTextMessageContent(
                                messageText = "ciao mamma guarda come mi diverto",
                                parseMode = "markdown"
                            ),
                            type = "article"
                        )
                    )
                )
            }
        }
    }
}

The above are suspending calls!

To install add in your Gradle build:

repositories {
    maven("https://dl.bintray.com/lamba92/com.github.lamba92")
}
// ...
dependenceis {
    implementation("com.github.lamba92:kotlingram:{latest_version}")
}

For Kotlin/Multiplatform:

repositories {
    maven("https://dl.bintray.com/lamba92/com.github.lamba92")
}
// ...
kotlin {
    // ...
    sourceSets {
        commonMain {
            dependencies {
                implementation("com.github.lamba92:kotlingram-core:{latest_version}")
                implementation("com.github.lamba92:kotlingram-bot-builder:{latest_version}")
            }
        }
    }
}

Add a Ktor Client engine for your platform of choice in your Gradle build.

Versions used:

  • Kotlin 1.4.30
  • Kotlinx.serialization: 1.0.1
  • Ktor: 1.5.1

Platforms available are:

  • jvm: JVM target 1.8
  • js: NodeJS with old compilation backend

mingwx64, macosx64 and linuxx64 platform are have some building issues I will work on later.

Unfortunately I had troubles publishing on Maven Central. I will look on the issue soon. The packages are published on GitHub Package Registry as well here but a login is required with a GitHub personal access token (PAT).

Extensible

The implementation of each call is fairly simple, and it is possible to extend missing (or maybe wrongly generated) calls using extension functions:

@Serializable
data class GetUpdatesRequest(
    val offset: Int? = null,
    val limit: Int? = null,
    val timeout: Int? = null,
    @SerialName("allowed_updates") val allowedUpdates: List<String> = emptyList()
)

suspend fun TelegramBotApiClient.getUpdates(
    requestBody: GetUpdatesRequest
): TelegramResponse<List<Update>> =
    httpClient.post<TelegramResponse<List<Update>>> {
        url {
            protocol = apiProtocol
            host = apiHost
            port = apiPort
            path("bot$apiToken", "getUpdates")
        }
        header(HttpHeaders.ContentType, ContentType.Application.Json)
        body = requestBody
    }

suspend fun TelegramBotApiClient.getUpdates(
    offset: Int? = null,
    limit: Int? = null,
    timeout: Int? = null,
    allowedUpdates: List<String> = emptyList(),
): TelegramResponse<List<Update>> =
    getUpdates(
        GetUpdatesRequest(
            offset,
            limit,
            timeout,
            allowedUpdates
        )
    )

If you find any issue please report them in the issue section!

FAQs

Package last updated on 13 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc