Commit graph

676 commits

Author SHA1 Message Date
Hirrolot
739d9738d8 Revert "Remove an unused import in requester_ext.rs"
This reverts commit 2387e11dd1.
2022-04-24 00:08:59 +06:00
Hirrolot
2387e11dd1 Remove an unused import in requester_ext.rs 2022-04-24 00:02:53 +06:00
Hirrolot
9440609a3c Accept Into<String> in InlineKeyboardButton's methods 2022-04-24 00:02:28 +06:00
Hirrolot
012fb94044 Accept IntoIterator in KeyboardMarkup::append_row 2022-04-23 23:57:42 +06:00
Waffle Maybe
6bf67ff69a
Merge pull request #205 from teloxide/msrv
MSRV
2022-04-19 13:20:53 +04:00
Maybe Waffle
7c55ad535e Add MSRV check to CI 2022-04-18 22:15:13 +04:00
Maybe Waffle
cf2004dcc2 Correct MSRV 2022-04-18 22:13:36 +04:00
Hirrolot
afe8e2f99f
Merge pull request #204 from teloxide/r051
Release v0.5.1
2022-04-18 16:08:29 +06:00
Maybe Waffle
f98472d798 Release v0.5.1 2022-04-18 14:03:50 +04:00
Maybe Waffle
86d351b35a Remove master docs 2022-04-18 14:02:06 +04:00
Waffle Maybe
ac03ae9549
Merge pull request #203 from teloxide/fix-comment
Document the `errors` module
2022-04-18 13:56:38 +04:00
Hirrolot
9ee3b90988 Update the changelog 2022-04-18 15:52:22 +06:00
Hirrolot
5e8263704d Document the errors module 2022-04-18 15:51:17 +06:00
Hirrolot
3ff23b906a
Merge pull request #202 from teloxide/r050
Prepare 0.5.0 release
2022-04-13 17:05:55 +06:00
Maybe Waffle
22c6330ba8 Prepare 0.5.0 release 2022-04-13 14:58:38 +04:00
Waffle Maybe
b294631121
Merge pull request #198 from teloxide/bare_id
Expose bare chat id
2022-04-13 14:00:57 +04:00
Waffle Maybe
4e35f6de31
Merge pull request #130 from teloxide/chrottle_retries_and_freeze
`Throttle` retries and freeze
2022-04-13 13:58:59 +04:00
Maybe Waffle
6318a7e730 Apply changes from the review
Make `BareChatId` internal.
2022-04-13 13:57:26 +04:00
Maybe Waffle
fa189af463 ix clippyF 2022-04-13 13:56:48 +04:00
Maybe Waffle
57a3731e6b Fix Message::url 2022-04-13 13:56:48 +04:00
Maybe Waffle
7bf3894a31 Correct documentation
From the standpoint of telegram supergroup is a channel...
2022-04-13 13:56:48 +04:00
Maybe Waffle
6ebdeb7f01 Expose bare chat id 2022-04-13 13:56:46 +04:00
Maybe Waffle
edb84691a2 Fix changelog formatting 2022-04-10 19:28:15 +04:00
Maybe Waffle
bf8e11f3a5 satisfy clippy 2022-04-10 19:24:18 +04:00
Maybe Waffle
c24f7f4fc0 Fix typos & stuff 2022-04-10 19:16:41 +04:00
Maybe Waffle
2477a0f945 Fix infinite loop in read_from_rx 2022-04-10 19:04:30 +04:00
Maybe Waffle
af0dd99ef4 Use Duration instead of u32 as the RetryAfter field 2022-04-10 18:48:00 +04:00
Maybe Waffle
d259f8aa23 Add diargam explaining how ThrottlingRequest works
https://asciiflow.com/#/share/eJzFV71u2zAQfhWCkx0EDdqhRbUEGbpmCLoE0BBCpiPBEplSFBwhCFoEHTt0MNw%2BRKeMRZ9GT9KjrB8ykhj9pRUIWTR1d9%2Fdfcej7jAjEcUOS8LwGIckpQI7%2BM7Fty523r9%2Be%2BziFJ7evFNPkt5KmLj45AT1vrLdH9dlXRIffcGlDAN2fUE%2FJTSWBwm4b7nYULFYWoSHm4PVoaMENELUMgqM41Xsf8NdFDELYhRTJk20MaVFENGKe0kELxAZcHZ4a%2BL1uXZg9jATtkIejxTgGK25QBEX1Eit3QVztdQaMFAV5RFAMHy%2BRYEconXfppV4MiFhmOaRjo3157T2CQl6YfKNVIwKgkGiQu5tdKymbp%2FEFQcDujpV4j%2B%2BVnokL1ZbCe78Q196Z0Lng5Hhp3nuyvvkfBpWL1sodW53w0CRT44ich14R%2B3M7fKjq87m8cusNsNqsw712XA%2B1IEbRx0Tm2k%2FL5GAMeB%2FbWlLYONR%2B1pRGZqmOYKX1X2hBpjlxQY7FWx7ChQ0XCVY1qJTPaErVdGvEqZ%2BFsurSTGVPnSmBpjZPG0SYFIi7Zp7Ua5JUAtxTblubKNDZfUvp4lMBCttaFytUmaTjZNQlrJ5y%2Fapt4GeqjJerf1%2FPyHuj9qPkb4medo5oE8%2FCLG4oFKkZ2sJ51O2XD4vScOYTrHZTiGr7EwBtlnRcRA4oQGdREBjOF2dDpB8EURd3bhVss84r4zX12W7RuulJzfbfct2X0aN74Ns7nWbD%2Fl%2FT1r%2BQ7e%2B6fWobrtuX35ZPf15QDbCLOMyWKdlk5U%2B0b%2BPtOA8VhYUgdNy81OqtKNqXfKICgHNW4M06Kg6whN1ivbJzQ1ldKXTKOv%2B1p2etRHf3fge3%2F8FrCjqXw%3D%3D)
2022-04-10 17:34:15 +04:00
Maybe Waffle
ed48de2f75 Simplify freezing 2022-04-10 17:34:15 +04:00
Maybe Waffle
dcbef82e43 Cleanup throttling::request 2022-04-10 17:34:15 +04:00
Maybe Waffle
081b74edb0 Split Throttle implementation into modules 2022-04-10 17:34:02 +04:00
Maybe Waffle
439a345dee Use tokio's try_recv instead of hacks 2022-04-10 17:25:06 +04:00
Maybe Waffle
435181fa0b Improve sanity
Refactor `Throttle` send-future. Previously it was a hand-written future, but
this quickly escalated to an unreadable mess. This commit uses `box`ing and
`async fn` to mitigate this problem.

Hopefully I'm not going insane now
2022-04-10 17:25:06 +04:00
Maybe Waffle
0a03431653 Make {Json,Multipart}Request clonable
This is required for the new `Throttle` design
2022-04-10 17:25:06 +04:00
Maybe Waffle
43802a5c41 Improve Throttling adoptor
- Freeze when getting `RetryAfter(_)` error
- Retry requests that previously returned `RetryAfter(_)` error
2022-04-10 17:24:57 +04:00
Maybe Waffle
6a91c44836 make errors module pub and add errors::AsResponseParameters trait 2022-04-10 17:23:33 +04:00
Maybe Waffle
51d6800a32 Make RequestError::RetryAfter::0 u32, instead of i32
(you can't really wait a negative amount of time, can you?)
2022-04-10 17:22:20 +04:00
Hirrolot
e1a47ef8c7
Merge pull request #201 from teloxide/add_missing_allowed_update
Add `AllowedUpdate::ChatJoinRequest`
2022-04-08 18:59:18 +06:00
Maybe Waffle
213db7b64c Add AllowedUpdate::ChatJoinRequest 2022-04-08 15:57:16 +04:00
Waffle Maybe
ac08117216
Merge pull request #197 from teloxide/convenience_user_and_me_methods
Add some convenience methods to `User` and `Me`
2022-04-04 03:35:07 +04:00
Maybe Waffle
d91863e1c3 Add some tests 2022-04-04 03:00:53 +04:00
Waffle Maybe
7da630e4c0
Merge pull request #200 from teloxide/hide_token_in_errors
Hide bot token in errors
2022-04-03 16:18:23 +04:00
Waffle Maybe
d1cf0e4f52
Merge branch 'master' into hide_token_in_errors 2022-04-03 16:14:34 +04:00
Maybe Waffle
05603560e6 Give a name to a magic number and document it 2022-04-03 14:47:10 +04:00
Maybe Waffle
daec5ee13e Hide bot token in errors
This fixes a potential[^1] security vulnerability -- if bot shows errors
from teloxide to the user & for some reason network error happened[^2]
the url of the request would be included in the error. Since TBA
includes bot token in the error this may lead to token leakage.

This commit fixes that issue by removing the token from the urls of
`reqwest::Error`, we try to only replace the token, but if we fail we
remove the whole url.

This can be tested by using a very low timeout value for the http
reqwest client:
```rust
let client = reqwest::Client::builder()
    .timeout(std::time::Duration::from_millis(1))
    .build()
    .unwrap();

let bot = Bot::from_env_with_client(client).auto_send();

// see if the token is redacted when network error (timeout) happens
// while sending common requests
let _ = dbg!(bot.get_me().await);

// see if the token is redacted when network error (timeout) happens
// while downloading files ("path" is unimportant as the timeout is so
// low the request probably won't even be sent)
let _ = dbg!(bot.download_file_stream("path").next().await);
```

For me this gives the following result:
```text
[t.rs:26] bot.get_me().await = Err(
    Network(
        reqwest::Error {
            kind: Request,
            url: Url {
                scheme: "https",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: Some(
                    Domain(
                        "api.telegram.org",
                    ),
                ),
                port: None,
                path: "/token:redacted/GetMe",
                query: None,
                fragment: None,
            },
            source: TimedOut,
        },
    ),
)
[t.rs:31] bot.download_file_stream("path").next().await = Some(
    Err(
        reqwest::Error {
            kind: Request,
            url: Url {
                scheme: "https",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: Some(
                    Domain(
                        "api.telegram.org",
                    ),
                ),
                port: None,
                path: "/file/token:redacted/path",
                query: None,
                fragment: None,
            },
            source: TimedOut,
        },
    ),
)
```

Note that this commits parent is `d0be260` and not the current master
the master branch currently contains breaking changes (we'll need to
make a release from this brach directly).

[^1]: Note that there are recorded cases where the token got exposed.
[^2]: Note that this can be theoretically be controlled by the user when
      sending/downloading bigger files.
2022-04-03 13:34:17 +04:00
Maybe Waffle
b3c0d00b7d "override" mention and tme_url on Me
That's not **really** an override, but by adding an inherent methods
we "hide" methods from `Deref<Target = User>`, that allows us to return
non-option types from `me.mention()` and `me.tme_url()` -- bots must
always have usernames.
2022-04-02 22:56:32 +04:00
Maybe Waffle
df9ffe8918 Add Me::username and Deref<Target = User> impl for Me 2022-04-02 22:43:55 +04:00
Maybe Waffle
55f753a201 Add User::{tme_url, preferably_tme_url} functions 2022-04-02 21:09:34 +04:00
Maybe Waffle
705083c2d9 Add UserId::{url, is_anonymous, is_channel, is_telegram} functions 2022-04-02 20:59:41 +04:00
Waffle Maybe
1746be2b7f
Merge pull request #194 from teloxide/chat_id_refactor
Chat and user id refactor
2022-04-02 19:11:42 +04:00