mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Get ready for v0.4.0 (#347)
* Get ready for v0.4.0 * Export teloxide_macros as macros in lib.rs * Use tokio v1.3 in README.md * Return the feature 'macros' back * Export teloxide_macros::teloxide in the prelude * Document the 'macros' feature in README.md * Update src/lib.rs Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com> * Update src/prelude.rs Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com> * Propagate features from teloxide-core * teloxide-core = 0.2.1 * Fix CI * Require teloxide-core/auto_send instead of teloxide/auto-send * default-features = false (teloxide-core) * Specify each teloxide-core feature separately * Fix Cargo.toml * JSON -> Json, CBOR -> Cbor * Update Cargo.toml Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com> Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com>
This commit is contained in:
parent
7bfc88ff33
commit
8522759e68
29 changed files with 159 additions and 102 deletions
76
.github/workflows/ci.yml
vendored
76
.github/workflows/ci.yml
vendored
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
|
@ -8,8 +7,9 @@ on:
|
||||||
name: Continuous integration
|
name: Continuous integration
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
code-checks:
|
style:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
|
@ -17,49 +17,65 @@ jobs:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
override: true
|
override: true
|
||||||
components: rustfmt, clippy
|
components: rustfmt
|
||||||
- name: Cargo fmt
|
|
||||||
run: cargo +nightly fmt --all -- --check
|
- name: fmt
|
||||||
- uses: actions-rs/toolchain@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
command: fmt
|
||||||
toolchain: stable
|
args: --all -- --check
|
||||||
override: true
|
|
||||||
- name: Cargo clippy
|
|
||||||
run: cargo clippy --all --all-targets --all-features -- -D warnings
|
|
||||||
|
|
||||||
test:
|
clippy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
rust:
|
|
||||||
- stable
|
|
||||||
- beta
|
|
||||||
- nightly
|
|
||||||
|
|
||||||
include:
|
|
||||||
- rust: stable
|
|
||||||
features: "--features \"redis-storage sqlite-storage cbor-serializer bincode-serializer frunk-\""
|
|
||||||
- rust: beta
|
|
||||||
features: "--features \"redis-storage sqlite-storage cbor-serializer bincode-serializer frunk-\""
|
|
||||||
- rust: nightly
|
|
||||||
features: "--all-features"
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: nightly
|
||||||
|
override: true
|
||||||
|
components: clippy
|
||||||
|
|
||||||
|
- name: clippy
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
rust:
|
||||||
|
- stable
|
||||||
|
- beta
|
||||||
|
- nightly
|
||||||
|
|
||||||
|
include:
|
||||||
|
- rust: stable
|
||||||
|
features: "--features full"
|
||||||
|
- rust: beta
|
||||||
|
features: "--features full"
|
||||||
|
- rust: nightly
|
||||||
|
features: "--all-features"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
toolchain: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: Build
|
- name: build
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
args: --verbose ${{ matrix.features }}
|
args: --verbose ${{ matrix.features }}
|
||||||
|
|
||||||
- name: Setup redis
|
- name: Setup redis
|
||||||
run: |
|
run: |
|
||||||
sudo apt install redis-server
|
sudo apt install redis-server
|
||||||
|
@ -67,7 +83,7 @@ jobs:
|
||||||
redis-server --port 7778 > /dev/null &
|
redis-server --port 7778 > /dev/null &
|
||||||
redis-server --port 7779 > /dev/null &
|
redis-server --port 7779 > /dev/null &
|
||||||
|
|
||||||
- name: Test
|
- name: test
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
|
|
|
@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [unreleased]
|
## [unreleased]
|
||||||
|
|
||||||
|
## [0.4.0] - 2021-03-19
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Integrate [teloxide-core].
|
- Integrate [teloxide-core].
|
||||||
- Allow arbitrary error types to be returned from (sub)transitions ([issue 242](https://github.com/teloxide/teloxide/issues/242)).
|
- Allow arbitrary error types to be returned from (sub)transitions ([issue 242](https://github.com/teloxide/teloxide/issues/242)).
|
||||||
|
@ -24,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Hide `SubtransitionOutputType` from the docs.
|
- Hide `SubtransitionOutputType` from the docs.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
- Export `teloxide_macros::teloxide` in `prelude`.
|
||||||
|
- `dispatching::dialogue::serializer::{JSON -> Json, CBOR -> Cbor}`
|
||||||
- Allow `bot_name` be `N`, where `N: Into<String> + ...` in `commands_repl` & `commands_repl_with_listener`.
|
- Allow `bot_name` be `N`, where `N: Into<String> + ...` in `commands_repl` & `commands_repl_with_listener`.
|
||||||
- 'Edit methods' (namely `edit_message_live_location`, `stop_message_live_location`, `edit_message_text`,
|
- 'Edit methods' (namely `edit_message_live_location`, `stop_message_live_location`, `edit_message_text`,
|
||||||
`edit_message_caption`, `edit_message_media` and `edit_message_reply_markup`) are split into common and inline
|
`edit_message_caption`, `edit_message_media` and `edit_message_reply_markup`) are split into common and inline
|
||||||
|
|
33
Cargo.toml
33
Cargo.toml
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "teloxide"
|
name = "teloxide"
|
||||||
version = "0.3.4"
|
version = "0.4.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "An elegant Telegram bots framework for Rust"
|
description = "An elegant Telegram bots framework for Rust"
|
||||||
repository = "https://github.com/teloxide/teloxide"
|
repository = "https://github.com/teloxide/teloxide"
|
||||||
|
@ -30,13 +30,36 @@ cbor-serializer = ["serde_cbor"]
|
||||||
bincode-serializer = ["bincode"]
|
bincode-serializer = ["bincode"]
|
||||||
|
|
||||||
frunk- = ["frunk"]
|
frunk- = ["frunk"]
|
||||||
|
|
||||||
macros = ["teloxide-macros"]
|
macros = ["teloxide-macros"]
|
||||||
|
|
||||||
nightly = [] # currently used for `README.md` tests and building docs for `docsrs` to add `This is supported on feature="..." only.`
|
native-tls = ["teloxide-core/native-tls"]
|
||||||
|
rustls = ["teloxide-core/rustls"]
|
||||||
|
auto-send = ["teloxide-core/auto_send"]
|
||||||
|
throttle = ["teloxide-core/throttle"]
|
||||||
|
cache-me = ["teloxide-core/cache_me"]
|
||||||
|
|
||||||
|
# currently used for `README.md` tests, building docs for `docsrs` to add `This is supported on feature="..." only.`,
|
||||||
|
# and for teloxide-core.
|
||||||
|
nightly = ["teloxide-core/nightly"]
|
||||||
|
|
||||||
|
full = [
|
||||||
|
"sqlite-storage",
|
||||||
|
"redis-storage",
|
||||||
|
"cbor-serializer",
|
||||||
|
"bincode-serializer",
|
||||||
|
"frunk",
|
||||||
|
"macros",
|
||||||
|
"teloxide-core/full",
|
||||||
|
"native-tls",
|
||||||
|
"rustls",
|
||||||
|
"auto-send",
|
||||||
|
"throttle",
|
||||||
|
"cache-me"
|
||||||
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
teloxide-core = { version = "0.2", features = ["full"] }
|
teloxide-core = { version = "0.2.1", default-features = false }
|
||||||
|
teloxide-macros = { version = "0.4", optional = true }
|
||||||
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
@ -68,8 +91,6 @@ serde_cbor = { version = "0.11", optional = true }
|
||||||
bincode = { version = "1.3", optional = true }
|
bincode = { version = "1.3", optional = true }
|
||||||
frunk = { version = "0.3", optional = true }
|
frunk = { version = "0.3", optional = true }
|
||||||
|
|
||||||
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master", optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
smart-default = "0.6.0"
|
smart-default = "0.6.0"
|
||||||
rand = "0.8.3"
|
rand = "0.8.3"
|
||||||
|
|
45
README.md
45
README.md
|
@ -14,7 +14,7 @@
|
||||||
<img src="https://img.shields.io/crates/v/teloxide.svg">
|
<img src="https://img.shields.io/crates/v/teloxide.svg">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://core.telegram.org/bots/api">
|
<a href="https://core.telegram.org/bots/api">
|
||||||
<img src="https://img.shields.io/badge/API coverage-Up to 0.4.9 (inclusively)-green.svg">
|
<img src="https://img.shields.io/badge/API coverage-Up to 5.1 (inclusively)-green.svg">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://t.me/teloxide">
|
<a href="https://t.me/teloxide">
|
||||||
<img src="https://img.shields.io/badge/official%20chat-t.me%2Fteloxide-blueviolet">
|
<img src="https://img.shields.io/badge/official%20chat-t.me%2Fteloxide-blueviolet">
|
||||||
|
@ -79,13 +79,10 @@ $ rustup override set nightly
|
||||||
5. Run `cargo new my_bot`, enter the directory and put these lines into your `Cargo.toml`:
|
5. Run `cargo new my_bot`, enter the directory and put these lines into your `Cargo.toml`:
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
teloxide = "0.3"
|
teloxide = "0.4"
|
||||||
teloxide-macros = "0.3"
|
|
||||||
|
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
|
tokio = { version = "1.3", features = ["rt-threaded", "macros"] }
|
||||||
tokio = { version = "0.2.11", features = ["rt-threaded", "macros"] }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## API overview
|
## API overview
|
||||||
|
@ -218,8 +215,12 @@ When a user sends a message to our bot and such a dialogue does not exist yet, a
|
||||||
pub struct StartState;
|
pub struct StartState;
|
||||||
|
|
||||||
#[teloxide(subtransition)]
|
#[teloxide(subtransition)]
|
||||||
async fn start(_state: StartState, cx: TransitionIn<AutoSend<Bot>>, _ans: String) -> TransitionOut<Dialogue> {
|
async fn start(
|
||||||
cx.answer_str("Let's start! What's your full name?").await?;
|
_state: StartState,
|
||||||
|
cx: TransitionIn<AutoSend<Bot>>,
|
||||||
|
_ans: String,
|
||||||
|
) -> TransitionOut<Dialogue> {
|
||||||
|
cx.answer("Let's start! What's your full name?").await?;
|
||||||
next(ReceiveFullNameState)
|
next(ReceiveFullNameState)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -242,7 +243,7 @@ async fn receive_full_name(
|
||||||
cx: TransitionIn<AutoSend<Bot>>,
|
cx: TransitionIn<AutoSend<Bot>>,
|
||||||
ans: String,
|
ans: String,
|
||||||
) -> TransitionOut<Dialogue> {
|
) -> TransitionOut<Dialogue> {
|
||||||
cx.answer_str("How old are you?").await?;
|
cx.answer("How old are you?").await?;
|
||||||
next(ReceiveAgeState::up(state, ans))
|
next(ReceiveAgeState::up(state, ans))
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -269,11 +270,11 @@ async fn receive_age_state(
|
||||||
) -> TransitionOut<Dialogue> {
|
) -> TransitionOut<Dialogue> {
|
||||||
match ans.parse::<u8>() {
|
match ans.parse::<u8>() {
|
||||||
Ok(ans) => {
|
Ok(ans) => {
|
||||||
cx.answer_str("What's your location?").await?;
|
cx.answer("What's your location?").await?;
|
||||||
next(ReceiveLocationState::up(state, ans))
|
next(ReceiveLocationState::up(state, ans))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
cx.answer_str("Send me a number.").await?;
|
cx.answer("Send me a number.").await?;
|
||||||
next(state)
|
next(state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,7 +302,7 @@ async fn receive_location(
|
||||||
cx: TransitionIn<AutoSend<Bot>>,
|
cx: TransitionIn<AutoSend<Bot>>,
|
||||||
ans: String,
|
ans: String,
|
||||||
) -> TransitionOut<Dialogue> {
|
) -> TransitionOut<Dialogue> {
|
||||||
cx.answer_str(format!("Full name: {}\nAge: {}\nLocation: {}", state.full_name, state.age, ans))
|
cx.answer(format!("Full name: {}\nAge: {}\nLocation: {}", state.full_name, state.age, ans))
|
||||||
.await?;
|
.await?;
|
||||||
exit()
|
exit()
|
||||||
}
|
}
|
||||||
|
@ -330,10 +331,13 @@ async fn main() {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_message(cx: UpdateWithCx<AudoSend<Bot>, Message>, dialogue: Dialogue) -> TransitionOut<Dialogue> {
|
async fn handle_message(
|
||||||
match cx.update.text_owned() {
|
cx: UpdateWithCx<AutoSend<Bot>, Message>,
|
||||||
|
dialogue: Dialogue,
|
||||||
|
) -> TransitionOut<Dialogue> {
|
||||||
|
match cx.update.text().map(ToOwned::to_owned) {
|
||||||
None => {
|
None => {
|
||||||
cx.answer_str("Send me a text message.").await?;
|
cx.answer("Send me a text message.").await?;
|
||||||
next(dialogue)
|
next(dialogue)
|
||||||
}
|
}
|
||||||
Some(ans) => dialogue.react(cx, ans).await,
|
Some(ans) => dialogue.react(cx, ans).await,
|
||||||
|
@ -381,10 +385,21 @@ The second one produces very strange compiler messages due to the `#[tokio::main
|
||||||
- `cbor-serializer` -- enables the [CBOR] serializer for dialogues.
|
- `cbor-serializer` -- enables the [CBOR] serializer for dialogues.
|
||||||
- `bincode-serializer` -- enables the [Bincode] serializer for dialogues.
|
- `bincode-serializer` -- enables the [Bincode] serializer for dialogues.
|
||||||
- `frunk` -- enables [`teloxide::utils::UpState`], which allows mapping from a structure of `field1, ..., fieldN` to a structure of `field1, ..., fieldN, fieldN+1`.
|
- `frunk` -- enables [`teloxide::utils::UpState`], which allows mapping from a structure of `field1, ..., fieldN` to a structure of `field1, ..., fieldN, fieldN+1`.
|
||||||
|
- `macros` -- re-exports macros from [`teloxide-macros`].
|
||||||
|
- `native-tls` -- enables the [`native-tls`] TLS implementation (enabled by default).
|
||||||
|
- `rustls` -- enables the [`rustls`] TLS implementation.
|
||||||
|
- `auto-send` -- enables `AutoSend` bot adaptor.
|
||||||
|
- `cache-me` -- enables the `CacheMe` bot adaptor.
|
||||||
|
- `full` -- enables all the features except `nightly`.
|
||||||
|
- `nightly` -- enables nightly-only features (see the [teloxide-core's features]).
|
||||||
|
|
||||||
[CBOR]: https://en.wikipedia.org/wiki/CBOR
|
[CBOR]: https://en.wikipedia.org/wiki/CBOR
|
||||||
[Bincode]: https://github.com/servo/bincode
|
[Bincode]: https://github.com/servo/bincode
|
||||||
[`teloxide::utils::UpState`]: https://docs.rs/teloxide/latest/teloxide/utils/trait.UpState.html
|
[`teloxide::utils::UpState`]: https://docs.rs/teloxide/latest/teloxide/utils/trait.UpState.html
|
||||||
|
[`teloxide-macros`]: https://github.com/teloxide/teloxide-macros
|
||||||
|
[`native-tls`]: https://docs.rs/native-tls
|
||||||
|
[`rustls`]: https://docs.rs/rustls
|
||||||
|
[teloxide-core's features]: https://docs.rs/teloxide-core/0.2.1/teloxide_core/#cargo-features
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
**Q: Where I can ask questions?**
|
**Q: Where I can ask questions?**
|
||||||
|
|
|
@ -7,10 +7,10 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
teloxide = { path = "../../", features = ["macros", "auto-send"] }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
teloxide = { path = "../../", features = ["macros"] }
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|
|
@ -7,19 +7,17 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.8"
|
teloxide = { path = "../../", features = ["frunk", "macros", "auto-send"] }
|
||||||
pretty_env_logger = "0.4.0"
|
|
||||||
|
|
||||||
frunk = "0.3.1"
|
|
||||||
frunk_core = "0.3.1"
|
|
||||||
|
|
||||||
futures = "0.3.5"
|
futures = "0.3.5"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
|
|
||||||
teloxide = { path = "../../", features = ["frunk"] }
|
log = "0.4.8"
|
||||||
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master" }
|
pretty_env_logger = "0.4.0"
|
||||||
|
|
||||||
derive_more = "0.99.9"
|
derive_more = "0.99.9"
|
||||||
|
|
||||||
|
frunk = "0.3.1"
|
||||||
|
frunk_core = "0.3.1"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::dialogue::states::{
|
||||||
ReceiveAgeState, ReceiveFullNameState, ReceiveLocationState, StartState,
|
ReceiveAgeState, ReceiveFullNameState, ReceiveLocationState, StartState,
|
||||||
};
|
};
|
||||||
use derive_more::From;
|
use derive_more::From;
|
||||||
use teloxide_macros::Transition;
|
use teloxide::macros::Transition;
|
||||||
|
|
||||||
#[derive(Transition, From)]
|
#[derive(Transition, From)]
|
||||||
pub enum Dialogue {
|
pub enum Dialogue {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::dialogue::{states::receive_location::ReceiveLocationState, Dialogue};
|
use crate::dialogue::{states::receive_location::ReceiveLocationState, Dialogue};
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
use teloxide_macros::teloxide;
|
|
||||||
|
|
||||||
#[derive(Generic)]
|
#[derive(Generic)]
|
||||||
pub struct ReceiveAgeState {
|
pub struct ReceiveAgeState {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::dialogue::{states::receive_age::ReceiveAgeState, Dialogue};
|
use crate::dialogue::{states::receive_age::ReceiveAgeState, Dialogue};
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
use teloxide_macros::teloxide;
|
|
||||||
|
|
||||||
#[derive(Generic)]
|
#[derive(Generic)]
|
||||||
pub struct ReceiveFullNameState;
|
pub struct ReceiveFullNameState;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::dialogue::Dialogue;
|
use crate::dialogue::Dialogue;
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
use teloxide_macros::teloxide;
|
|
||||||
|
|
||||||
#[derive(Generic)]
|
#[derive(Generic)]
|
||||||
pub struct ReceiveLocationState {
|
pub struct ReceiveLocationState {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::dialogue::{states::ReceiveFullNameState, Dialogue};
|
use crate::dialogue::{states::ReceiveFullNameState, Dialogue};
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
use teloxide_macros::teloxide;
|
|
||||||
|
|
||||||
pub struct StartState;
|
pub struct StartState;
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,10 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
teloxide = { path = "../../", features = ["auto-send"] }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
teloxide = { path = "../../" }
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|
|
@ -7,10 +7,10 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
teloxide = { path = "../../", features = ["auto-send"] }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
teloxide = { path = "../../" }
|
|
||||||
tokio-stream = "0.1.4"
|
tokio-stream = "0.1.4"
|
||||||
|
|
||||||
# Used to setup a webhook
|
# Used to setup a webhook
|
||||||
|
|
|
@ -7,11 +7,11 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
teloxide = { path = "../../", features = ["auto-send"] }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
tokio-stream = "0.1.4"
|
tokio-stream = "0.1.4"
|
||||||
teloxide = { path = "../../" }
|
|
||||||
|
|
||||||
# Used to setup a webhook
|
# Used to setup a webhook
|
||||||
warp = "0.3.0"
|
warp = "0.3.0"
|
||||||
|
|
|
@ -5,14 +5,13 @@ authors = ["Maximilian Siling <mouse-art@ya.ru>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
# You can also choose "cbor-serializer" or built-in JSON serializer
|
||||||
|
teloxide = { path = "../../", features = ["redis-storage", "bincode-serializer", "macros", "auto-send"] }
|
||||||
|
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
|
|
||||||
# You can also choose "cbor-serializer" or built-in JSON serializer
|
|
||||||
teloxide = { path = "../../", features = ["redis-storage", "bincode-serializer"] }
|
|
||||||
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master" }
|
|
||||||
|
|
||||||
serde = "1.0.104"
|
serde = "1.0.104"
|
||||||
futures = "0.3.5"
|
futures = "0.3.5"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use teloxide_macros::Transition;
|
use teloxide::dispatching::dialogue::Transition;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
use teloxide_macros::teloxide;
|
|
||||||
|
|
||||||
use super::states::*;
|
use super::states::*;
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
teloxide = { path = "../../", features = ["auto-send"] }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
tokio-stream = "0.1.3"
|
tokio-stream = "0.1.3"
|
||||||
teloxide = { path = "../../" }
|
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|
|
@ -7,7 +7,7 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
teloxide = { path = "../../", features = ["macros", "auto-send"] }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
teloxide = { path = "../../", features = ["macros"] }
|
|
||||||
|
|
|
@ -5,14 +5,13 @@ authors = ["Maximilian Siling <mouse-art@ya.ru>", "Sergey Levitin <selevit@gmail
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
# You can also choose "cbor-serializer" or built-in JSON serializer
|
||||||
|
teloxide = { path = "../../", features = ["sqlite-storage", "bincode-serializer", "redis-storage", "macros", "auto-send"] }
|
||||||
|
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
|
||||||
|
|
||||||
# You can also choose "cbor-serializer" or built-in JSON serializer
|
|
||||||
teloxide = { path = "../../", features = ["sqlite-storage", "bincode-serializer", "redis-storage"] }
|
|
||||||
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master" }
|
|
||||||
|
|
||||||
serde = "1.0.104"
|
serde = "1.0.104"
|
||||||
futures = "0.3.5"
|
futures = "0.3.5"
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,13 @@ mod transitions;
|
||||||
use states::*;
|
use states::*;
|
||||||
|
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
dispatching::dialogue::{serializer::JSON, SqliteStorage, Storage},
|
dispatching::dialogue::{serializer::Json, SqliteStorage, Storage},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
RequestError,
|
RequestError,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
type StorageError = <SqliteStorage<JSON> as Storage<Dialogue>>::Error;
|
type StorageError = <SqliteStorage<Json> as Storage<Dialogue>>::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
enum Error {
|
enum Error {
|
||||||
|
@ -48,7 +48,7 @@ async fn main() {
|
||||||
let dialogue = dialogue.expect("std::convert::Infallible");
|
let dialogue = dialogue.expect("std::convert::Infallible");
|
||||||
handle_message(cx, dialogue).await.expect("Something wrong with the bot!")
|
handle_message(cx, dialogue).await.expect("Something wrong with the bot!")
|
||||||
},
|
},
|
||||||
SqliteStorage::open("db.sqlite", JSON).await.unwrap(),
|
SqliteStorage::open("db.sqlite", Json).await.unwrap(),
|
||||||
))
|
))
|
||||||
.dispatch()
|
.dispatch()
|
||||||
.await;
|
.await;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use teloxide_macros::Transition;
|
use teloxide::macros::Transition;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
use teloxide_macros::teloxide;
|
use teloxide::macros::teloxide;
|
||||||
|
|
||||||
use super::states::*;
|
use super::states::*;
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ pub trait Serializer<D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The JSON serializer for memory storages.
|
/// The JSON serializer for memory storages.
|
||||||
pub struct JSON;
|
pub struct Json;
|
||||||
|
|
||||||
impl<D> Serializer<D> for JSON
|
impl<D> Serializer<D> for Json
|
||||||
where
|
where
|
||||||
D: Serialize + DeserializeOwned,
|
D: Serialize + DeserializeOwned,
|
||||||
{
|
{
|
||||||
|
@ -34,12 +34,12 @@ where
|
||||||
#[cfg(feature = "cbor-serializer")]
|
#[cfg(feature = "cbor-serializer")]
|
||||||
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
||||||
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))]
|
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))]
|
||||||
pub struct CBOR;
|
pub struct Cbor;
|
||||||
|
|
||||||
#[cfg(feature = "cbor-serializer")]
|
#[cfg(feature = "cbor-serializer")]
|
||||||
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
||||||
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))]
|
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))]
|
||||||
impl<D> Serializer<D> for CBOR
|
impl<D> Serializer<D> for Cbor
|
||||||
where
|
where
|
||||||
D: Serialize + DeserializeOwned,
|
D: Serialize + DeserializeOwned,
|
||||||
{
|
{
|
||||||
|
|
|
@ -182,11 +182,11 @@ where
|
||||||
for update in &updates {
|
for update in &updates {
|
||||||
if let Err((value, e)) = update {
|
if let Err((value, e)) = update {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Cannot parse an update.\nError: {:?}\nValue: {}\n\
|
"Cannot parse an update.\nError: {:?}\nValue: {}\n\
|
||||||
This is a bug in teloxide-core, please open an issue here: \
|
This is a bug in teloxide-core, please open an issue here: \
|
||||||
https://github.com/teloxide/teloxide-core/issues.",
|
https://github.com/teloxide/teloxide-core/issues.",
|
||||||
e,
|
e,
|
||||||
value
|
value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,11 @@ pub use teloxide_core::*;
|
||||||
#[cfg(feature = "macros")]
|
#[cfg(feature = "macros")]
|
||||||
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
||||||
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
|
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
|
||||||
|
pub use teloxide_macros as macros;
|
||||||
|
|
||||||
|
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
||||||
|
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
|
||||||
|
#[cfg(feature = "macros")]
|
||||||
pub use teloxide_macros::teloxide;
|
pub use teloxide_macros::teloxide;
|
||||||
|
|
||||||
#[cfg(all(feature = "nightly", doctest))]
|
#[cfg(all(feature = "nightly", doctest))]
|
||||||
|
|
|
@ -12,14 +12,19 @@ pub use crate::{
|
||||||
respond,
|
respond,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use teloxide_core::{
|
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
||||||
adaptors::AutoSend,
|
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
|
||||||
types::{
|
#[cfg(feature = "macros")]
|
||||||
CallbackQuery, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, Poll,
|
pub use crate::teloxide;
|
||||||
PollAnswer, PreCheckoutQuery, ShippingQuery,
|
|
||||||
},
|
pub use teloxide_core::types::{
|
||||||
|
CallbackQuery, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, Poll, PollAnswer,
|
||||||
|
PreCheckoutQuery, ShippingQuery,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "auto-send")]
|
||||||
|
pub use crate::adaptors::AutoSend;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use teloxide_core::prelude::*;
|
pub use teloxide_core::prelude::*;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ use teloxide::dispatching::dialogue::{RedisStorage, Serializer, Storage};
|
||||||
async fn test_redis_json() {
|
async fn test_redis_json() {
|
||||||
let storage = RedisStorage::open(
|
let storage = RedisStorage::open(
|
||||||
"redis://127.0.0.1:7777",
|
"redis://127.0.0.1:7777",
|
||||||
teloxide::dispatching::dialogue::serializer::JSON,
|
teloxide::dispatching::dialogue::serializer::Json,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -31,7 +31,7 @@ async fn test_redis_bincode() {
|
||||||
async fn test_redis_cbor() {
|
async fn test_redis_cbor() {
|
||||||
let storage = RedisStorage::open(
|
let storage = RedisStorage::open(
|
||||||
"redis://127.0.0.1:7779",
|
"redis://127.0.0.1:7779",
|
||||||
teloxide::dispatching::dialogue::serializer::CBOR,
|
teloxide::dispatching::dialogue::serializer::Cbor,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -8,7 +8,7 @@ use teloxide::dispatching::dialogue::{Serializer, SqliteStorage, Storage};
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn test_sqlite_json() {
|
async fn test_sqlite_json() {
|
||||||
let storage =
|
let storage =
|
||||||
SqliteStorage::open("./test_db1.sqlite", teloxide::dispatching::dialogue::serializer::JSON)
|
SqliteStorage::open("./test_db1.sqlite", teloxide::dispatching::dialogue::serializer::Json)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
test_sqlite(storage).await;
|
test_sqlite(storage).await;
|
||||||
|
@ -28,7 +28,7 @@ async fn test_sqlite_bincode() {
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn test_sqlite_cbor() {
|
async fn test_sqlite_cbor() {
|
||||||
let storage =
|
let storage =
|
||||||
SqliteStorage::open("./test_db3.sqlite", teloxide::dispatching::dialogue::serializer::CBOR)
|
SqliteStorage::open("./test_db3.sqlite", teloxide::dispatching::dialogue::serializer::Cbor)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
test_sqlite(storage).await;
|
test_sqlite(storage).await;
|
||||||
|
|
Loading…
Reference in a new issue