This library allows you to verify phone numbers of users and send authorization codes through Telegram Gateway.
Technology | Version |
---|---|
JDK | 21+ |
Kotlin | 1.9+ |
- 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.1.0")
Maven:
<dependency>
<groupId>dev.voroby</groupId>
<artifactId>telegram-gateway-sdk</artifactId>
<version>1.1.0</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, StatusResponse>
suspend fun checkVerificationStatus(
request: CheckVerificationStatus.Request
): Either<Throwable, StatusResponse>
suspend fun sendVerificationMessage(
request: SendVerificationMessage.Request
): Either<Throwable, StatusResponse>
suspend fun revokeVerificationMessage(
request: RevokeVerificationMessage.Request
): Either<Throwable, BooleanResponse>
}
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 statusResponse: Either<Throwable, StatusResponse> = tg.checkSendAbility(request)
statusResponse.fold(
{ println(it.stackTraceToString()) },
{ onProtocolSuccess(it) }
)
}