-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fa0031
commit 00e0baf
Showing
1 changed file
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Telegram Gateway API SDK | ||
|
||
This library allows you to verify phone numbers of users and send authorization codes through [Telegram Gateway](https://core.telegram.org/gateway). | ||
|
||
![](https://core.telegram.org/file/400780400656/3/9iBg_m8EjJs.349165/64ba1e8722d15e124d) | ||
|
||
## Contents | ||
- [Requirements](#requirements) | ||
- [Installation](#installation) | ||
- [Example](#example) | ||
- [License](#license) | ||
|
||
<a name="requirements"></a> | ||
## Requirements | ||
| Technology | Version | | ||
|------------|-----| | ||
| JDK | 21+ | | ||
| Kotlin | 1.9+ | | ||
| Coroutines | 1.8.0+ | | ||
|
||
<a name="installation"></a> | ||
## Installation | ||
1) Download by one of two options: | ||
- 1.1 Clone source code: | ||
```shell | ||
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. | ||
|
||
```kotlin | ||
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](https://docs.github.com/ru/enterprise-cloud@latest/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) how to generate personal token. | ||
|
||
```xml | ||
<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. | ||
|
||
```xml | ||
<repositories> | ||
<repository> | ||
<id>github</id> | ||
<url>https://maven.pkg.github.com/p-vorobyev/*</url> | ||
</repository> | ||
</repositories> | ||
``` | ||
|
||
3) Add dependency to your project: | ||
|
||
**Gradle**: | ||
|
||
```kotlin | ||
implementation("dev.voroby:telegram-gateway-sdk:1.0.0") | ||
``` | ||
|
||
**Maven**: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>dev.voroby</groupId> | ||
<artifactId>telegram-gateway-sdk</artifactId> | ||
<version>1.0.0</version> | ||
</dependency> | ||
``` | ||
|
||
<a name="example"></a> | ||
## Example | ||
Create `TelegramGateway` instance: | ||
|
||
```kotlin | ||
val protocol = Protocol.createHttpProtocol() | ||
val telegramGateway = TelegramGateway.create( | ||
accessToken = "your_token", | ||
protocol = protocol | ||
) | ||
``` | ||
Available methods([documentation](https://core.telegram.org/gateway/api)): | ||
```kotlin | ||
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: | ||
```kotlin | ||
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()) } | ||
} | ||
``` | ||
|
||
<a name="license"></a> | ||
## License | ||
[MIT License](https://github.com/p-vorobyev/telegram-gateway-sdk/blob/master/LICENSE) |