From 74b8b22bb78bf524e67384d3cef8f2f0643bb3f5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 11 Sep 2023 19:41:03 +0600 Subject: [PATCH] add note about slf4j and proxy setup --- docs/tgbotapi/faq.md | 13 ++++++++ docs/tgbotapi/introduction/proxy-setup.md | 40 +++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/docs/tgbotapi/faq.md b/docs/tgbotapi/faq.md index 32a6b0d..9ed5802 100644 --- a/docs/tgbotapi/faq.md +++ b/docs/tgbotapi/faq.md @@ -1,5 +1,18 @@ # FAQ +## What is the error `Failed to load class "org.slf4j.impl.StaticLoggerBinder"`? + +``` +SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". +SLF4J: Defaulting to no-operation (NOP) logger implementation +SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. +``` + +This error is just a warning about the absence of [slf4j](https://www.slf4j.org) setup. You may fix this error +by following to [stackoverflow answer](https://stackoverflow.com/a/9919375) + +--- + ## How to filter updates in some part of `BehaviourBuilder`? You may create subcontext with diff --git a/docs/tgbotapi/introduction/proxy-setup.md b/docs/tgbotapi/introduction/proxy-setup.md index e045846..eb27ccd 100644 --- a/docs/tgbotapi/introduction/proxy-setup.md +++ b/docs/tgbotapi/introduction/proxy-setup.md @@ -54,6 +54,46 @@ Explanation line by line: 3. `ktorClientEngineFactory = OkHttp` - setting up engine factory of our bot. On the time of documentation filling, `OkHttp` is one of the engines in `Ktor` system which supports socks proxy. More you can read on [Ktor](https://ktor.io) site in subparts about [engines](https://ktor.io/clients/http-client/engines.html#okhttp) and [proxy](https://ktor.io/clients/http-client/features/proxy.html) 4. `proxy = ProxyBuilder.socks("127.0.0.1", 1080)` - here we are setting up our proxy. Here was used local server which (as assumed) will connect to server like `shadowsocks` +## More complex and flexible variant + +You may try to use [custom engine for ktor](https://ktor.io/docs/http-client-engines.html). For example: + +```kotlin +// JVM +// OkHttp engine +// Socks5 proxy + +val bot = telegramBot(botToken) { + val proxyPort = 1080 //your proxy port + + val proxyHost = "your proxy host" + val username = "proxy username" + val password = "proxy password" + + val proxyAddr = InetSocketAddress(proxyHost, proxyPort) + val proxy = Proxy(Proxy.Type.SOCKS, proxyAddr) + + Authenticator.setDefault(object : Authenticator() { + protected val passwordAuthentication: PasswordAuthentication? + protected get() { + if (requestingHost.lowercase() == proxyHost.lowercase()) { + if (proxyPort == requestingPort) { + return PasswordAuthentication(username, password.toCharArray()) + } + } + return null + } + }) + this.client = HttpClient(OkHttp) { + engine { + config { + proxy(proxy) + } + } + } +} +``` + ## Next steps * [First bot](first-bot.md) \ No newline at end of file