This library allows you to verify phone numbers of users and send authorization codes through Telegram Gateway.
Technology | Version |
---|---|
JDK | 21+ |
Kotlin | 1.9+ |
Coroutines | 1.8.0+ |
- Download by one of two options:
- 1.1 Clone source code:
git clone https://github.com/p-vorobyev/telegram-gateway-sdk.git
or
- 1.2 Download artifact from GitHub Packages:
Gradle:
Specify repository in build.gradle.kts
with your GitHub login and personal token.
repositories {
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/p-vorobyev/*")
credentials {
username = "GITHUB_LOGIN"
password = "GITHUB_TOKEN"
}
}
}
Maven:
Specify github
server with your credentials in settings.xml
for Apache Maven. See GitHub docs how to generate personal token.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github</id>
<username>GITHUB_LOGIN</username>
<password>GITHUB_TOKEN</password>
</server>
</servers>
</settings>
Add repository to pom.xml
of your project.
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/p-vorobyev/*</url>
</repository>
</repositories>
- Add dependency to your project:
Gradle:
implementation("dev.voroby:telegram-gateway-sdk:1.0.1")
Maven:
<dependency>
<groupId>dev.voroby</groupId>
<artifactId>telegram-gateway-sdk</artifactId>
<version>1.0.1</version>
</dependency>
Create TelegramGateway
instance:
val protocol = Protocol.createHttpProtocol()
val telegramGateway = TelegramGateway.create(
accessToken = "your_token",
protocol = protocol
)
Available methods(documentation):
interface TelegramGateway : AutoCloseable {
suspend fun checkSendAbility(request: CheckSendAbility.Request): Either<Throwable, Response>
suspend fun checkVerificationStatus(request: CheckVerificationStatus.Request): Either<Throwable, Response>
suspend fun sendVerificationMessage(request: SendVerificationMessage.Request): Either<Throwable, Response>
}
Let's check the ability to send a verification message to the specified phone number:
telegramGateway.use { tg ->
val request = CheckSendAbility.Request("phone_number_in_international_format")
val response: Either<Throwable, Response> = tg.checkSendAbility(request)
response.onRight { println(it.toString()) }
}