mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-21 07:43:48 +00:00
init
This commit is contained in:
parent
120db4c445
commit
89eda29965
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
.idea
|
||||
out/*
|
||||
*.iml
|
||||
target
|
||||
|
||||
settings.xml
|
||||
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
4
LICENSE
4
LICENSE
@ -178,7 +178,7 @@
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
@ -186,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
Copyright 2018 Insanus
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
27
README.md
27
README.md
@ -1 +1,26 @@
|
||||
# TelegramBotAPI
|
||||
# TelegramBotAPI
|
||||
|
||||
## What is it?
|
||||
|
||||
It is one more project which wish to be useful and full Telegram Bots API bridge for Kotlin. Most part of some specific
|
||||
solves or unuseful moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
|
||||
|
||||
## How to work with library?
|
||||
|
||||
By default in any documentation will be meaning that you have variable in scope with names
|
||||
|
||||
| Name of variable | Description | Where to get? (Examples) |
|
||||
|:----------------:|:-----------:|:------------------------:|
|
||||
| executor | [RequestsExecutor](src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt) | [Ktor RequestExecutor realisation](src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt) |
|
||||
|
||||
## Requests Examples
|
||||
|
||||
### Get Me
|
||||
|
||||
```kotlin
|
||||
executor.execute(GetMe())
|
||||
```
|
||||
|
||||
As a result you will receive `User` object. This object used as is now (as in API documentation), but it is possible
|
||||
that this class will be renamed to `RawUser` and you will be able to get real realisation of this object like `Bot` (in
|
||||
cases when `isBot` == `true`) or `User` (otherwise)
|
||||
|
40
build.gradle
Normal file
40
build.gradle
Normal file
@ -0,0 +1,40 @@
|
||||
apply plugin: 'java'
|
||||
apply plugin: "application"
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||
maven { url "https://dl.bintray.com/kotlin/ktor" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
||||
implementation "joda-time:joda-time:$joda_time_version"
|
||||
implementation "io.ktor:ktor-client-core:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
|
||||
|
||||
// Use JUnit test framework
|
||||
testImplementation 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
mainClassName = "com.github.insanusmokrassar.TelegramBotAPI.IndexKt"
|
||||
|
6
gradle.properties
Normal file
6
gradle.properties
Normal file
@ -0,0 +1,6 @@
|
||||
kotlin.code.style=official
|
||||
kotlin_version=1.3.11
|
||||
kotlin_coroutines_version=1.1.0
|
||||
kotlin_serialisation_runtime_version=0.9.1
|
||||
joda_time_version=2.10.1
|
||||
ktor_version=1.0.1
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#Wed Nov 07 21:46:14 CST 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
|
172
gradlew
vendored
Executable file
172
gradlew
vendored
Executable file
@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save ( ) {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
18
settings.gradle
Normal file
18
settings.gradle
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* This settings file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
* In a single project build this file can be empty or even removed.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user guide at https://docs.gradle.org/3.4.1/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
/*
|
||||
// To declare projects as part of a multi-project build use the 'include' method
|
||||
include 'shared'
|
||||
include 'api'
|
||||
include 'services:webservice'
|
||||
*/
|
||||
|
||||
rootProject.name = 'TelegramBotAPI'
|
@ -0,0 +1,24 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorRequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.ProxySettings
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.useWith
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.CommonMessageImpl
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.get.GetUserProfilePhotos
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.toInputMediaPhoto
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendMediaGroup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.biggest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.*
|
||||
import io.ktor.client.engine.okhttp.OkHttp
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runBlocking {
|
||||
KtorRequestsExecutor(
|
||||
args[0],
|
||||
OkHttp.create()
|
||||
).apply {
|
||||
// It is just template of creating requests executor
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
abstract class BaseRequestsExecutor(
|
||||
token: String,
|
||||
hostUrl: String = "https://api.telegram.org"
|
||||
) : RequestsExecutor {
|
||||
protected val baseUrl: String = "$hostUrl/bot$token"
|
||||
|
||||
protected val scope: CoroutineScope = CoroutineScope(
|
||||
Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||
)
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
|
||||
interface KtorCallFactory {
|
||||
suspend fun <T: Any> prepareCall(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
) : HttpClientCall?
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.MultipartRequestCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.SimpleRequestCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.engine.okhttp.OkHttp
|
||||
import io.ktor.util.cio.toByteArray
|
||||
import kotlinx.io.charsets.Charset
|
||||
import kotlinx.serialization.json.JSON
|
||||
|
||||
class KtorRequestsExecutor(
|
||||
token: String,
|
||||
private val client: HttpClient = HttpClient(OkHttp),
|
||||
hostUrl: String = "https://api.telegram.org",
|
||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||
excludeDefaultFactories: Boolean = false
|
||||
) : BaseRequestsExecutor(token, hostUrl) {
|
||||
constructor(
|
||||
token: String,
|
||||
engine: HttpClientEngine = OkHttp.create(),
|
||||
hostUrl: String = "https://api.telegram.org"
|
||||
) : this(
|
||||
token,
|
||||
HttpClient(engine),
|
||||
hostUrl
|
||||
)
|
||||
|
||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||
if (!excludeDefaultFactories) {
|
||||
asSequence().plus(SimpleRequestCallFactory()).plus(MultipartRequestCallFactory()).toList()
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||
var call: HttpClientCall? = null
|
||||
for (factory in callsFactories) {
|
||||
call = factory.prepareCall(
|
||||
client,
|
||||
baseUrl,
|
||||
request
|
||||
)
|
||||
if (call != null) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if (call == null) {
|
||||
throw IllegalArgumentException("Can't execute request: $request")
|
||||
}
|
||||
val content = call.response.content.toByteArray().toString(Charset.defaultCharset())
|
||||
val responseObject = JSON.parse(
|
||||
ResponseParameters.serializer(request.resultSerializer()),
|
||||
content
|
||||
)
|
||||
return responseObject.result ?: call.let {
|
||||
throw RequestException(
|
||||
responseObject,
|
||||
"Can't get result object"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapWithCommonValues
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
import io.ktor.client.call.call
|
||||
import io.ktor.client.request.accept
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.client.request.url
|
||||
import io.ktor.http.*
|
||||
import kotlinx.io.streams.asInput
|
||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
|
||||
class MultipartRequestCallFactory : KtorCallFactory {
|
||||
@ImplicitReflectionSerializer
|
||||
override suspend fun <T: Any> prepareCall(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
): HttpClientCall? = (request as? MultipartRequest) ?.let {
|
||||
castedRequest ->
|
||||
client.call {
|
||||
url("$baseUrl/${castedRequest.method()}")
|
||||
method = HttpMethod.Post
|
||||
accept(ContentType.Application.Json)
|
||||
body = MultiPartFormDataContent(
|
||||
formData {
|
||||
val params = castedRequest.paramsJson.mapWithCommonValues()
|
||||
for ((key, value) in castedRequest.mediaMap + params) {
|
||||
when (value) {
|
||||
is MultipartFile -> append(
|
||||
key,
|
||||
value.file.inputStream().asInput(),
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, value.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
||||
}
|
||||
)
|
||||
is FileId -> append(key, value.fileId)
|
||||
else -> append(key, value.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
build()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
import io.ktor.client.call.call
|
||||
import io.ktor.client.request.accept
|
||||
import io.ktor.client.request.url
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.content.TextContent
|
||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
|
||||
class SimpleRequestCallFactory : KtorCallFactory {
|
||||
@ImplicitReflectionSerializer
|
||||
override suspend fun <T: Any> prepareCall(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
): HttpClientCall? = (request as? SimpleRequest<T>) ?.let {
|
||||
castedRequest ->
|
||||
client.call {
|
||||
url("$baseUrl/${castedRequest.method()}")
|
||||
method = HttpMethod.Post
|
||||
accept(ContentType.Application.Json)
|
||||
|
||||
val content = request.toJsonWithoutNulls().toString()
|
||||
|
||||
body = TextContent(
|
||||
content,
|
||||
ContentType.Application.Json
|
||||
)
|
||||
build()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.Proxy
|
||||
|
||||
data class ProxySettings(
|
||||
val host: String = "localhost",
|
||||
val port: Int = 1080,
|
||||
val username: String? = null,
|
||||
val password: String? = null
|
||||
)
|
||||
|
||||
fun OkHttpClient.Builder.useWith(proxySettings: ProxySettings) {
|
||||
proxy(
|
||||
Proxy(
|
||||
Proxy.Type.SOCKS,
|
||||
InetSocketAddress(
|
||||
proxySettings.host,
|
||||
proxySettings.port
|
||||
)
|
||||
)
|
||||
)
|
||||
proxySettings.password ?.let {
|
||||
password ->
|
||||
proxyAuthenticator {
|
||||
_, response ->
|
||||
response.request().newBuilder().apply {
|
||||
addHeader(
|
||||
"Proxy-Authorization",
|
||||
Credentials.basic(proxySettings.username ?: "", password)
|
||||
)
|
||||
}.build()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
|
||||
import java.io.IOException
|
||||
|
||||
class RequestException(
|
||||
val response: ResponseParameters<*>,
|
||||
message: String? = null,
|
||||
cause: Throwable? = null
|
||||
) : IOException(
|
||||
message,
|
||||
cause
|
||||
)
|
@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
|
||||
interface RequestsExecutor {
|
||||
@Throws(RequestException::class)
|
||||
suspend fun <T : Any> execute(request: Request<T>): T
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class DeleteMessage(
|
||||
@SerialName(chatIdField)
|
||||
val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
val messageId: MessageIdentifier
|
||||
) : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "deleteMessage"
|
||||
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class ForwardMessage(
|
||||
@SerialName(fromChatIdField)
|
||||
val fromChatId: ChatIdentifier,
|
||||
@SerialName(chatIdField)
|
||||
val toChatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
val messageId: MessageIdentifier,
|
||||
@SerialName(disableNotificationField)
|
||||
@Optional
|
||||
val disableNotification: Boolean = false
|
||||
): SimpleRequest<RawMessage> {
|
||||
override fun method(): String = "forwardMessage"
|
||||
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import kotlinx.serialization.KSerializer
|
||||
|
||||
class GetMe : SimpleRequest<User> {
|
||||
override fun method(): String = "getMe"
|
||||
override fun resultSerializer(): KSerializer<User> = User.serializer()
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
const val UPDATE_MESSAGE = "message"
|
||||
const val UPDATE_EDITED_MESSAGE = "edited_message"
|
||||
const val UPDATE_CHANNEL_POST = "channel_post"
|
||||
const val UPDATE_EDITED_CHANNEL_POST = "edited_channel_post"
|
||||
const val UPDATE_CHOSEN_INLINE_RESULT = "chosen_inline_result"
|
||||
const val UPDATE_INLINE_QUERY = "inline_query"
|
||||
const val UPDATE_CALLBACK_QUERY = "callback_query"
|
||||
const val UPDATE_SHIPPING_QUERY = "shipping_query"
|
||||
const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query"
|
||||
/*
|
||||
|
||||
@Optional private val inline_query: RawInlineQuery? = null,
|
||||
@Optional private val chosen_inline_result: Unit? = null,
|
||||
@Optional private val callback_query: RawCallbackQuery? = null,
|
||||
@Optional private val shipping_query: Unit? = null,
|
||||
@Optional private val pre_checkout_query: Unit? = null
|
||||
*/
|
||||
@Serializable
|
||||
data class GetUpdates(
|
||||
@Optional
|
||||
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
||||
@Optional
|
||||
val limit: Int? = null,
|
||||
@Optional
|
||||
val timeout: Int? = null,
|
||||
@Optional
|
||||
val allowed_updates: List<String>? = listOf(
|
||||
UPDATE_MESSAGE,
|
||||
UPDATE_EDITED_MESSAGE,
|
||||
UPDATE_CHANNEL_POST,
|
||||
UPDATE_EDITED_CHANNEL_POST,
|
||||
UPDATE_CHOSEN_INLINE_RESULT,
|
||||
UPDATE_INLINE_QUERY,
|
||||
UPDATE_CALLBACK_QUERY,
|
||||
UPDATE_SHIPPING_QUERY,
|
||||
UPDATE_PRE_CHECKOUT_QUERY
|
||||
)
|
||||
): SimpleRequest<List<RawUpdate>> {
|
||||
override fun method(): String = "getUpdates"
|
||||
|
||||
override fun resultSerializer(): KSerializer<List<RawUpdate>> = ArrayListSerializer(RawUpdate.serializer())
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.util.*
|
||||
|
||||
sealed class InputFile {
|
||||
abstract val fileId: String
|
||||
}
|
||||
|
||||
// TODO:: add checks for file url/file id regex
|
||||
/**
|
||||
* Contains file id or file url
|
||||
*/
|
||||
@Serializable(FileIdSerializer::class)
|
||||
data class FileId(
|
||||
override val fileId: String
|
||||
) : InputFile()
|
||||
|
||||
fun String.toInputFile(): InputFile = FileId(this)
|
||||
|
||||
@Serializer(FileId::class)
|
||||
object FileIdSerializer : KSerializer<FileId> {
|
||||
override fun serialize(output: Encoder, obj: FileId) = output.encodeString(obj.fileId)
|
||||
override fun deserialize(input: Decoder): FileId = FileId(input.decodeString())
|
||||
}
|
||||
|
||||
// TODO:: add checks for files size
|
||||
/**
|
||||
* Contains info about file for sending
|
||||
*/
|
||||
data class MultipartFile (
|
||||
val file: File,
|
||||
val mimeType: String = Files.probeContentType(file.toPath()),
|
||||
val filename: String = file.name
|
||||
) : InputFile() {
|
||||
override val fileId: String by lazy {
|
||||
"${UUID.randomUUID()}.${file.extension}"
|
||||
}
|
||||
}
|
||||
|
||||
fun File.toInputFile(): InputFile = MultipartFile(
|
||||
this
|
||||
)
|
@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
interface MultipartRequest<T: Any> : Request<T> {
|
||||
val paramsJson: JsonObject
|
||||
val mediaMap: Map<String, MultipartFile>
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
interface Request<T: Any> {
|
||||
fun method(): String
|
||||
fun resultSerializer(): KSerializer<T>
|
||||
@ImplicitReflectionSerializer
|
||||
fun json(): JsonObject = toJsonWithoutNulls()
|
||||
}
|
||||
|
||||
fun <T : Any> StringFormat.extractResult(
|
||||
from: String,
|
||||
dataSerializer: KSerializer<T>
|
||||
): ResponseParameters<T> {
|
||||
return parse(ResponseParameters.serializer(dataSerializer), from)
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
interface SimpleRequest<T: Any> : Request<T>
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
|
||||
|
||||
interface ByInlineMessageId {
|
||||
val inlineMessageId: InlineMessageIdentifier
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
|
||||
interface ByMessageId : ChatRequest {
|
||||
val messageId: MessageIdentifier
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
|
||||
interface ChatRequest {
|
||||
val chatId: ChatIdentifier
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
interface DisableNotification {
|
||||
val disableNotification: Boolean
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
interface DisableWebPagePreview {
|
||||
val disableWebPagePreview: Boolean?
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
|
||||
interface ReplyMarkup {
|
||||
val replyMarkup: KeyboardMarkup?
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
|
||||
interface ReplyMessageId {
|
||||
val replyToMessageId: MessageIdentifier?
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.TelegramDate
|
||||
|
||||
interface UntilDate {
|
||||
val untilDate: TelegramDate?
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.CallbackQuery.CallbackQuery
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class AnswerCallbackQuery(
|
||||
@SerialName(callbackQueryIdField)
|
||||
val callbackQueryId: CallbackQueryIdentifier,
|
||||
@SerialName(textField)
|
||||
@Optional
|
||||
val text: String? = null,
|
||||
@SerialName(showAlertField)
|
||||
@Optional
|
||||
val showAlert: Boolean? = null,
|
||||
@SerialName(urlField)
|
||||
@Optional
|
||||
val url: String? = null,
|
||||
@SerialName(cachedTimeField)
|
||||
@Optional
|
||||
val cachedTimeSeconds: Int? = null
|
||||
) : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerCallbackQuery"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
||||
|
||||
fun CallbackQuery.createAnswer(
|
||||
text: String? = null,
|
||||
showAlert: Boolean? = null,
|
||||
url: String? = null,
|
||||
cachedTimeSeconds: Int? = null
|
||||
): AnswerCallbackQuery = AnswerCallbackQuery(id, text, showAlert, url, cachedTimeSeconds)
|
@ -0,0 +1,39 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerPreCheckoutQuery
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class AnswerPreCheckoutQueryOk(
|
||||
@SerialName(preCheckoutQueryIdField)
|
||||
override val preCheckoutQueryId: PreCheckoutQueryId
|
||||
) : AnswerPreCheckoutQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = true
|
||||
}
|
||||
|
||||
|
||||
@Serializable
|
||||
data class AnswerPreCheckoutQueryError(
|
||||
@SerialName(preCheckoutQueryIdField)
|
||||
override val preCheckoutQueryId: PreCheckoutQueryId,
|
||||
@SerialName(errorMessageField)
|
||||
val errorMessage: String
|
||||
) : AnswerPreCheckoutQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = false
|
||||
}
|
||||
|
||||
fun PreCheckoutQuery.createAnswerOk(): AnswerPreCheckoutQueryOk = AnswerPreCheckoutQueryOk(
|
||||
id
|
||||
)
|
||||
|
||||
fun PreCheckoutQuery.createAnswerError(
|
||||
error: String
|
||||
): AnswerPreCheckoutQueryError = AnswerPreCheckoutQueryError(
|
||||
id,
|
||||
error
|
||||
)
|
@ -0,0 +1,49 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerShippingQuery
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingOption
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
@Serializable
|
||||
data class AnswerShippingQueryOk(
|
||||
@SerialName(shippingQueryIdField)
|
||||
override val shippingQueryId: ShippingQueryIdentifier,
|
||||
@Serializable(ShippingOptionsSerializer::class)
|
||||
@SerialName(shippingOptionsField)
|
||||
val shippingOptions: List<ShippingOption>
|
||||
) : AnswerShippingQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = true
|
||||
}
|
||||
|
||||
object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ArrayListSerializer(
|
||||
ShippingOption.serializer()
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class AnswerShippingQueryError(
|
||||
@SerialName(shippingQueryIdField)
|
||||
override val shippingQueryId: ShippingQueryIdentifier,
|
||||
@SerialName(errorMessageField)
|
||||
val error: String
|
||||
) : AnswerShippingQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = false
|
||||
}
|
||||
|
||||
fun ShippingQuery.createAnswerOk(
|
||||
shippingOptions: List<ShippingOption>
|
||||
): AnswerShippingQueryOk = AnswerShippingQueryOk(
|
||||
id,
|
||||
shippingOptions
|
||||
)
|
||||
|
||||
fun ShippingQuery.createAnswerError(
|
||||
error: String
|
||||
): AnswerShippingQueryError = AnswerShippingQueryError(
|
||||
id,
|
||||
error
|
||||
)
|
@ -0,0 +1,14 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.PreCheckoutQueryId
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.serializer
|
||||
|
||||
interface AnswerPreCheckoutQuery : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerPreCheckoutQuery"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = Boolean.serializer()
|
||||
|
||||
val preCheckoutQueryId: PreCheckoutQueryId
|
||||
val isOk: Boolean
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ShippingQueryIdentifier
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.serializer
|
||||
|
||||
interface AnswerShippingQuery : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerShippingQuery"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = Boolean.serializer()
|
||||
|
||||
val shippingQueryId: ShippingQueryIdentifier
|
||||
val isOk: Boolean
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringSerializer
|
||||
|
||||
@Serializable
|
||||
data class ExportChatInviteLink(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<String> {
|
||||
override fun method(): String = "exportChatInviteLink"
|
||||
override fun resultSerializer(): KSerializer<String> = StringSerializer
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
import kotlinx.serialization.internal.StringSerializer
|
||||
|
||||
@Serializable
|
||||
data class LeaveChat(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "leaveChat"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
|
||||
interface ChatMemberRequest<T: Any> : ChatRequest, SimpleRequest<T> {
|
||||
val userId: UserId
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
import kotlinx.serialization.internal.StringSerializer
|
||||
|
||||
@Serializable
|
||||
data class GetChat(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<RawChat> {
|
||||
override fun method(): String = "getChat"
|
||||
override fun resultSerializer(): KSerializer<RawChat> = RawChat.serializer()
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.RawChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.*
|
||||
|
||||
@Serializable
|
||||
data class GetChatAdministrators(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<List<RawChatMember>> {
|
||||
override fun method(): String = "getChatAdministrators"
|
||||
override fun resultSerializer(): KSerializer<List<RawChatMember>> = ArrayListSerializer(RawChatMember.serializer())
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.*
|
||||
|
||||
@Serializable
|
||||
data class GetChatMembersCount(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Int> {
|
||||
override fun method(): String = "getChatMembersCount"
|
||||
override fun resultSerializer(): KSerializer<Int> = IntSerializer
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.UntilDate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.RawChatMember
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class GetChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId
|
||||
) : ChatMemberRequest<RawChatMember> {
|
||||
override fun method(): String = "getChatMember"
|
||||
override fun resultSerializer(): KSerializer<RawChatMember> = RawChatMember.serializer()
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.UntilDate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class KickChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
@Optional
|
||||
override val untilDate: TelegramDate? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "kickChatMember"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.UntilDate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class PromoteChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
@Optional
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(canChangeInfoField)
|
||||
@Optional
|
||||
private val canChangeInfo: Boolean? = null,
|
||||
@SerialName(canPostMessagesField)
|
||||
@Optional
|
||||
private val canPostMessages: Boolean? = null,
|
||||
@SerialName(canEditMessagesField)
|
||||
@Optional
|
||||
private val canEditMessages: Boolean? = null,
|
||||
@SerialName(canDeleteMessagesField)
|
||||
@Optional
|
||||
private val canDeleteMessages: Boolean? = null,
|
||||
@SerialName(canInviteUsersField)
|
||||
@Optional
|
||||
private val canInviteUsers: Boolean? = null,
|
||||
@SerialName(canRestrictMembersField)
|
||||
@Optional
|
||||
private val canRestrictMembers: Boolean? = null,
|
||||
@SerialName(canPinMessagesField)
|
||||
@Optional
|
||||
private val canPinMessages: Boolean? = null,
|
||||
@SerialName(canPromoteMembersField)
|
||||
@Optional
|
||||
private val canPromoteMembers: Boolean? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "promoteChatMember"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.UntilDate
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class RestrictChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
@Optional
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(canSendMessagesField)
|
||||
@Optional
|
||||
private val canSendMessages: Boolean? = null,
|
||||
@SerialName(canSendMediaMessagesField)
|
||||
@Optional
|
||||
private val canSendMediaMessages: Boolean? = null,
|
||||
@SerialName(canSendOtherMessagesField)
|
||||
@Optional
|
||||
private val canSendOtherMessages: Boolean? = null,
|
||||
@SerialName(canAddWebPagePreviewsField)
|
||||
@Optional
|
||||
private val canAddWebPagePreviews: Boolean? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "restrictChatMember"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class UnbanChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId
|
||||
) : ChatMemberRequest<Boolean> {
|
||||
override fun method(): String = "unbanChatMember"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
import kotlinx.serialization.internal.StringSerializer
|
||||
|
||||
@Serializable
|
||||
data class DeleteChatPhoto(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "deleteChatPhoto"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.DisableNotification
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class PinChatMessage (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
val messageId: MessageIdentifier,
|
||||
@SerialName(disableNotificationField)
|
||||
@Optional
|
||||
override val disableNotification: Boolean = false
|
||||
): ChatRequest, SimpleRequest<Boolean>, DisableNotification {
|
||||
override fun method(): String = "pinChatMessage"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class SetChatDescription (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(descriptionField)
|
||||
val description: String
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
init {
|
||||
if (description.length !in chatDescriptionLength) {
|
||||
throw IllegalArgumentException("Chat description must be in $chatDescriptionLength range")
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "setChatDescription"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonTreeMapper
|
||||
|
||||
@Serializable
|
||||
data class SetChatPhoto (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@Transient
|
||||
val photo: MultipartFile = throw IllegalArgumentException("Unfortunately, this type of objects can't be parsed automatically")
|
||||
): ChatRequest, MultipartRequest<Boolean> {
|
||||
override fun method(): String = "setChatPhoto"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||
override val paramsJson: JsonObject = JsonTreeMapper().writeTree(this, serializer()).jsonObject
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class SetChatTitle (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
val title: String
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
init {
|
||||
if (title.length !in chatTitleLength) {
|
||||
throw IllegalArgumentException("Chat title must be in $chatTitleLength range")
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "setChatTitle"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
import kotlinx.serialization.internal.StringSerializer
|
||||
|
||||
@Serializable
|
||||
data class UnpinChatMessage(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "unpinChatMessage"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.stickers
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class DeleteChatStickerSet(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "deleteChatStickerSet"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.stickers
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
@Serializable
|
||||
data class SetChatStickerSet(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(stickerSetNameField)
|
||||
val stickerSetName: String
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setChatStickerSet"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.common
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
data class CommonMultipartFileRequest<T: Any>(
|
||||
val data: Request<T>,
|
||||
override val mediaMap: Map<String, MultipartFile>
|
||||
) : MultipartRequest<T>, Request<T> by data {
|
||||
@ImplicitReflectionSerializer
|
||||
override val paramsJson: JsonObject = data.json()
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
// TODO:: Replace return type by RawMessage or Boolean (as in documentation)
|
||||
@Serializable
|
||||
data class EditChatMessageLiveLocation(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
override val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditReplyMessage, EditLocationMessage {
|
||||
override fun method(): String = "editMessageLiveLocation"
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
// TODO:: Replace return type by RawMessage or Boolean (as in documentation)
|
||||
@Serializable
|
||||
data class EditInlineMessageLiveLocation(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
override val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage, EditLocationMessage {
|
||||
override fun method(): String = "editMessageLiveLocation"
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
// TODO:: Replace return type by RawMessage or Boolean (as in documentation)
|
||||
@Serializable
|
||||
data class StopChatMessageLiveLocation(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditReplyMessage {
|
||||
override fun method(): String = "stopMessageLiveLocation"
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
// TODO:: Replace return type by RawMessage or Boolean (as in documentation)
|
||||
@Serializable
|
||||
data class StopInlineMessageLiveLocation(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage {
|
||||
override fun method(): String = "stopMessageLiveLocation"
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.ReplyMarkup
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditChatMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageReplyMarkupMethod = "editMessageReplyMarkup"
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageReplyMarkup(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditReplyMessage {
|
||||
|
||||
override fun method(): String = editMessageReplyMarkupMethod
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.ReplyMarkup
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditInlineMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageReplyMarkup(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage {
|
||||
|
||||
override fun method(): String = editMessageReplyMarkupMethod
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
|
||||
interface EditChatMessage : SimpleRequest<RawMessage> {
|
||||
val chatId: ChatIdentifier
|
||||
val messageId: MessageIdentifier
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
interface EditDisableWebPagePreviewMessage {
|
||||
val disableWebPagePreview: Boolean?
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
|
||||
|
||||
interface EditInlineMessage : SimpleRequest<RawMessage> {
|
||||
val inlineMessageId: InlineMessageIdentifier
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
interface EditLocationMessage {
|
||||
val latitude: Double
|
||||
val longitude: Double
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
|
||||
|
||||
interface EditMediaMessage {
|
||||
val media: InputMedia
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ReplyMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
|
||||
interface EditReplyMessage : ReplyMarkup {
|
||||
override val replyMarkup: InlineKeyboardMarkup?
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
|
||||
interface EditTextChatMessage : SimpleRequest<RawMessage> {
|
||||
val text: String
|
||||
val parseMode: ParseMode?
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageCaptionMethod = "editMessageCaption"
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageCaption(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(captionField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditTextChatMessage, EditReplyMessage {
|
||||
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageCaption(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(captionField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage {
|
||||
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
|
||||
import kotlinx.serialization.*
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
const val editMessageMediaMethod = "editMessageMedia"
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageMedia(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(mediaField)
|
||||
override val media: InputMedia,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditReplyMessage, EditMediaMessage {
|
||||
|
||||
init {
|
||||
if (media.file is MultipartFile) {
|
||||
throw IllegalArgumentException("For editing of media messages you MUST use file id (according to documentation)")
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.editMessageMediaMethod
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
|
||||
import kotlinx.serialization.*
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageMedia(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(mediaField)
|
||||
override val media: InputMedia,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage, EditMediaMessage {
|
||||
|
||||
init {
|
||||
if (media.file is MultipartFile) {
|
||||
throw IllegalArgumentException("For editing of media messages you MUST use file id (according to documentation)")
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.editMessageMediaMethod
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageTextMethod = "editMessageText"
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageText(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
@Optional
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.editMessageMediaMethod
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageText(
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
@Optional
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ByMessageId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GetGameHighScoresByChat (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier
|
||||
) : GetGameHighScores, ByMessageId
|
@ -0,0 +1,15 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ByInlineMessageId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GetGameHighScoresByInlineMessageId (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier
|
||||
) : GetGameHighScores, ByInlineMessageId
|
@ -0,0 +1,24 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ByMessageId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SetGameScoreByChatId (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(scoreField)
|
||||
override val score: Long,
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(forceField)
|
||||
@Optional
|
||||
override val force: Boolean = false,
|
||||
@SerialName(disableEditMessageField)
|
||||
@Optional
|
||||
override val disableEditMessage: Boolean = false
|
||||
) : SetGameScore, ByMessageId
|
@ -0,0 +1,22 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ByInlineMessageId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SetGameScoreByInlineMessageId (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(scoreField)
|
||||
override val score: Long,
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier,
|
||||
@SerialName(forceField)
|
||||
@Optional
|
||||
override val force: Boolean = false,
|
||||
@SerialName(disableEditMessageField)
|
||||
@Optional
|
||||
override val disableEditMessage: Boolean = false
|
||||
) : SetGameScore, ByInlineMessageId
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.games.GameHighScore
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
interface GetGameHighScores : SimpleRequest<List<GameHighScore>> {
|
||||
val userId: UserId
|
||||
|
||||
override fun method(): String = "getGameHighScores"
|
||||
override fun resultSerializer(): KSerializer<List<GameHighScore>> = GameHighScoresSerializer
|
||||
}
|
||||
|
||||
object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.serializer
|
||||
|
||||
interface SetGameScore : SimpleRequest<Boolean> {
|
||||
val userId: UserId
|
||||
val score: Long
|
||||
val force: Boolean
|
||||
val disableEditMessage: Boolean
|
||||
|
||||
override fun method(): String = "setGameScore"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = Boolean.serializer()
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.get
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PathedFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.fileIdField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetFile(
|
||||
@SerialName(fileIdField)
|
||||
val fileId: FileId
|
||||
): SimpleRequest<PathedFile> {
|
||||
override fun method(): String = "getFile"
|
||||
override fun resultSerializer(): KSerializer<PathedFile> = PathedFile.serializer()
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.get
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickerSetNameField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GetStickerSet(
|
||||
@SerialName(stickerSetNameField)
|
||||
val name: String
|
||||
): SimpleRequest<StickerSet> {
|
||||
override fun method(): String = "getStickerSet"
|
||||
override fun resultSerializer(): KSerializer<StickerSet> = StickerSet.serializer()
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.get
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetUserProfilePhotos(
|
||||
@SerialName(userIdField)
|
||||
val userId: UserId,
|
||||
@SerialName(offsetField)
|
||||
val offset: Int? = null,
|
||||
@SerialName(limitField)
|
||||
val limit: Int? = null
|
||||
): SimpleRequest<UserProfilePhotos> {
|
||||
init {
|
||||
if (offset != null && offset < 0) {
|
||||
throw IllegalArgumentException("Offset for getting user profile photos must be positive")
|
||||
}
|
||||
if (limit != null && limit !in userProfilePhotosRequestLimit) {
|
||||
throw IllegalArgumentException("Limit for getting user profile photos must be in 0 .. 100 range")
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "getUserProfilePhotos"
|
||||
override fun resultSerializer(): KSerializer<UserProfilePhotos> = UserProfilePhotos.serializer()
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.actions.BotAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendChatMessageRequest
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
/**
|
||||
* Send notification to user which will be shown for 5 seconds or while user have no messages from bot
|
||||
*/
|
||||
@Serializable
|
||||
data class SendAction(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(actionField)
|
||||
val action: BotAction
|
||||
): SendChatMessageRequest<Boolean> {
|
||||
override fun method(): String = "sendChatAction"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SendContact(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(phoneNumberField)
|
||||
val phoneNumber: String,
|
||||
@SerialName(firstNameField)
|
||||
val firstName: String,
|
||||
@SerialName(lastNameField)
|
||||
@Optional
|
||||
val lastName: String? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
@Optional
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@Optional
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>
|
||||
{
|
||||
constructor(
|
||||
chatId: ChatIdentifier,
|
||||
contact: Contact,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): this(
|
||||
chatId,
|
||||
contact.phoneNumber,
|
||||
contact.firstName,
|
||||
contact.lastName,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
override fun method(): String = "sendVenue"
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
||||
|
||||
fun Contact.toRequest(
|
||||
chatId: ChatIdentifier,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): SendContact = SendContact(
|
||||
chatId,
|
||||
this,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
@ -0,0 +1,37 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
// TODO:: Add location tracker for tracking location
|
||||
@Serializable
|
||||
data class SendLocation(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
override val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(livePeriodField)
|
||||
@Optional
|
||||
val livePeriod: Long? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
@Optional
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@Optional
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
PositionedSendMessageRequest<RawMessage>
|
||||
{
|
||||
|
||||
override fun method(): String = "sendLocation"
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.DisableWebPagePreview
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SendMessage(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
@Optional
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
@Optional
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@Optional
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
TextableSendMessageRequest<RawMessage>,
|
||||
DisableWebPagePreview
|
||||
{
|
||||
|
||||
override fun method(): String = "sendMessage"
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SendVenue(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
override val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(addressField)
|
||||
val address: String,
|
||||
@SerialName(foursquareIdField)
|
||||
@Optional
|
||||
val foursquareId: String? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
@Optional
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@Optional
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendMessageRequest<RawMessage>,
|
||||
PositionedSendMessageRequest<RawMessage>,
|
||||
TitledSendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>
|
||||
{
|
||||
constructor(
|
||||
chatId: ChatIdentifier,
|
||||
venue: Venue,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): this(
|
||||
chatId,
|
||||
venue.location.latitude,
|
||||
venue.location.longitude,
|
||||
venue.title,
|
||||
venue.address,
|
||||
venue.foursquareId,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
override fun method(): String = "sendVenue"
|
||||
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
||||
|
||||
fun Venue.toRequest(
|
||||
chatId: ChatIdentifier,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
): SendVenue = SendVenue(
|
||||
chatId,
|
||||
this,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts
|
||||
|
||||
interface DuratedSendMessageRequest<T: Any>: SendMessageRequest<T> {
|
||||
/**
|
||||
* Duration of media, usually in seconds
|
||||
*/
|
||||
val duration: Int?
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts
|
||||
|
||||
interface PositionedSendMessageRequest<T: Any>: SendMessageRequest<T> {
|
||||
val latitude: Double
|
||||
val longitude: Double
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ReplyMarkup
|
||||
|
||||
interface ReplyingMarkupSendMessageRequest<T: Any>: SendMessageRequest<T>, ReplyMarkup
|
@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ChatRequest
|
||||
|
||||
interface SendChatMessageRequest<T: Any> : SimpleRequest<T>, ChatRequest
|
@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.DisableNotification
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types.ReplyMessageId
|
||||
|
||||
interface SendMessageRequest<T: Any> : SendChatMessageRequest<T>, ReplyMessageId, DisableNotification
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user