Commit graph

693 commits

Author SHA1 Message Date
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
Waffle Maybe
c250a9b327
Merge pull request #193 from teloxide/telergam
Fix a typo in documentation
2022-04-02 18:40:06 +04:00
Maybe Waffle
9b3c0d88d2 restart CI 2022-04-02 18:36:06 +04:00
Hirrolot
ef21aa38af
Merge pull request #195 from teloxide/typooooooooos
Fix some more typos
2022-04-02 07:32:49 -07:00
Maybe Waffle
ea72267959 restart CI 2022-04-02 18:28:38 +04:00
Maybe Waffle
380ebde98b Update changelog 2022-04-02 18:26:18 +04:00
Maybe Waffle
c2d2a15ef1 Split derives because rustfmt hates me 2022-04-02 18:13:32 +04:00
Maybe Waffle
71dee3b563 Use Into<ChatId> in methods 2022-04-02 18:10:47 +04:00
Maybe Waffle
4fbec56674 Impl From<UserId> for ChatId and Recipient 2022-04-02 18:10:47 +04:00
Maybe Waffle
036c46caaa reformat code a bit 2022-04-02 18:10:46 +04:00
Maybe Waffle
f2378935b7 Make chat id typed (add ChatId)
Note that this is different from the previous `ChatId` (that was renamed
to `Recipient`), since it can't hold @channelusername.

Reason: same as w/ `UserId`
2022-04-02 18:10:46 +04:00
Maybe Waffle
41e09159a6 Make user id typed (add UserId)
Reason: when user id is just an integer, it's easy to accidentally
use a "random" integer instead of actual user id, typed APIs make code
less prone to some mistakes.

This commit also fixes an issue when a wrong integer type was used for
`user_id` in `Contact`.

Another option that this addition unlocks is adding methods/implementing
foreign trait for `UserId`.
2022-04-02 18:10:46 +04:00
Maybe Waffle
0a1d73c223 Rename ChatId => Recipient
Reason: it isn't _really_ a chat id, it can also be a channel username.
2022-04-02 18:10:46 +04:00
Waffle Maybe
189ef968e6
Merge pull request #196 from teloxide/pin_ci_yet_again
Pin nightly compiler version in CI
2022-03-25 13:17:25 +04:00
Maybe Waffle
ad56195e52 Fix name of the nightly CI job 2022-03-25 13:12:26 +04:00
Maybe Waffle
35e5bac766 Pin nightly compiler version in CI 2022-03-24 21:40:00 +04:00
Maybe Waffle
22cfffc704 Fix some more typos 2022-03-24 21:32:01 +04:00
Waffle Maybe
ecf90c8c05
Fix a typo in documentation 2022-03-24 17:51:34 +04:00
Waffle Maybe
b9df9abe9b
Merge pull request #192 from teloxide/fix_unmark
Fix chat unmark
2022-03-23 03:46:44 +04:00
Maybe Waffle
3d69d96182 Fix chat unmark 2022-03-22 22:08:47 +04:00
Hirrolot
d0be260575
Merge pull request #191 from teloxide/r044
Release 0.4.4
2022-03-21 08:27:02 -07:00
Maybe Waffle
1a61d02858 Release 0.4.4 2022-03-21 19:22:22 +04:00
Waffle Maybe
36a54a86e4
Merge pull request #190 from teloxide/not_found_error
Add `NotFound` error
2022-03-21 19:15:29 +04:00
Maybe Waffle
923be2221d Add NotFound error 2022-03-21 19:10:12 +04:00
Waffle Maybe
961e5aef9d
Merge pull request #189 from teloxide/with_payload
Add `HasPayload::with_payload_mut` function
2022-03-20 19:12:31 +04:00
Hirrolot
2c0748f3ae
Merge branch 'master' into with_payload 2022-03-20 08:08:52 -07:00
Waffle Maybe
0e4163d3c5
Merge pull request #188 from teloxide/new_errors_just_dropped
Add `WrongFileIdOrUrl` and `FailedToGetUrlContent` errors
2022-03-19 21:09:30 +04:00
Maybe Waffle
d8e3c6ce42 Add WrongFileIdOrUrl and FailedToGetUrlContent errors 2022-03-18 14:21:55 +04:00
Maybe Waffle
c7e32fa247 Add HasPayload::with_payload_mut function
`HasPayload::with_payload_mut` allows to easily apply multiple changes
to the payload without calling `payload_mut()` multiple times and
creating temporary variable for the request. e.g.:
```rust
// without `with_payload_mut`
{
    let mut req = bot.set_webhook(url.clone());

    req.payload_mut().certificate = certificate.take();
    req.payload_mut().drop_pending_updates = drop_pending_updates;

    req.send().await?;
}

// with `with_payload_mut`
bot
    .set_webhook(url.clone())
    .with_payload_mut(|payload| {
        payload.certificate = certificate.take();
        payload.drop_pending_updates = drop_pending_updates;
    })
    .send()
    .await?
```
2022-03-18 14:13:38 +04:00
Hirrolot
7437a8c4a8
Merge pull request #187 from teloxide/r043
Release 0.4.3
2022-03-08 00:47:37 +06:00
Maybe Waffle
11c79499e3 Release 0.4.3 2022-03-07 22:43:24 +04:00
Waffle Maybe
0c5f9678d8
Merge pull request #185 from teloxide/revert_better_timeouts
Revert "better timeouts"
2022-03-07 20:16:53 +04:00
Waffle Maybe
1643632539
Merge pull request #186 from teloxide/user_is_automatic
Add `User::is_telegram` function
2022-03-07 20:16:25 +04:00
Maybe Waffle
b0607f604a update changelog 2022-03-03 02:23:46 +03:00