https://github.com/H1rono/traq-bot-http-rs
traQ BOTのHTTPリクエストパーサー
https://github.com/H1rono/traq-bot-http-rs
rust traq traq-bot
Last synced: about 2 months ago
JSON representation
traQ BOTのHTTPリクエストパーサー
- Host: GitHub
- URL: https://github.com/H1rono/traq-bot-http-rs
- Owner: H1rono
- License: mit
- Created: 2023-02-15T10:55:28.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-01T13:42:28.000Z (7 months ago)
- Last Synced: 2024-11-01T14:31:43.506Z (7 months ago)
- Topics: rust, traq, traq-bot
- Language: Rust
- Homepage: https://crates.io/crates/traq-bot-http
- Size: 489 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# traq-bot-http-rs
[](https://github.com/H1rono/traq-bot-http-rs/actions/workflows/rust.yml)
[](https://codecov.io/gh/H1rono/traq-bot-http-rs)
[](https://github.com/H1rono/traq-bot-http-rs/actions/workflows/release.yml)
[](https://docs.rs/traq-bot-http/latest/traq_bot_http/)[](https://github.com/H1rono/traq-bot-http-rs/blob/main/LICENSE)
[](https://crates.io/crates/traq-bot-http)
[](https://github.com/H1rono/traq-bot-http-rs/releases/latest)
[](https://crates.io/crates/traq-bot-http)traQ BOTのPOSTリクエストをパースするライブラリです。
## example
`Cargo.toml`
```toml
# ...[dependencies]
http = "1"
tower = "0.4"
axum = "0.7"
tokio = { version = "1", features = ["full"] }
traq-bot-http = { version = "0.11", features = ["tower"] }
````main.rs`
```rust
use std::{env, net::SocketAddr};use axum::{routing::post_service, Router};
use http::StatusCode;
use tokio::net::TcpListener;
use tower::service_fn;use traq_bot_http::{payloads, RequestParser};
#[tokio::main]
async fn main() {
let verification_token = env::var("VERIFICATION_TOKEN").unwrap();
let parser = RequestParser::new(&verification_token);
let handler = parser
.into_handler()
.on_message_created(service_fn(on_message_created));
let app = Router::new().route(
"/",
post_service(handler).handle_error(|_| async { StatusCode::INTERNAL_SERVER_ERROR }),
);
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
let server = TcpListener::bind(addr).await.unwrap();
axum::serve(server, app).await.unwrap();
}async fn on_message_created(
payload: payloads::MessageCreatedPayload,
) -> Result<(), std::convert::Infallible> {
print!(
"{}さんがメッセージを投稿しました。\n内容: {}\n",
payload.message.user.display_name, payload.message.text
);
Ok(())
}
```## Features
feature | 機能 | バージョン
:-- | :-- | :--
`uuid` | ペイロードのUUID値が[`uuid::Uuid`](https://docs.rs/uuid/latest/uuid/struct.Uuid.html)型に | [v0.4.0](https://github.com/H1rono/traq-bot-http-rs/releases/tag/v0.4.0)から
`time` | ペイロードのタイムスタンプ値([RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.6))が[`time::OffsetDateTime`](https://docs.rs/time/latest/time/struct.OffsetDateTime.html)型に | [v0.5.0](https://github.com/H1rono/traq-bot-http-rs/releases/tag/v0.5.0)から
`chrono` | ペイロードのタイムスタンプ値が[`chrono::DateTime`](https://docs.rs/chrono/latest/chrono/struct.DateTime.html)型に | [v0.6.0](https://github.com/H1rono/traq-bot-http-rs/releases/tag/v0.6.0)から
`http` | [`http::Request`](https://docs.rs/http/latest/http/request/struct.Request.html)型のサポート | [v0.10.0](https://github.com/H1rono/traq-bot-http-rs/releases/tag/v0.10.0)から
`tower` | [`Handler`](https://docs.rs/traq-bot-http/latest/traq_bot_http/struct.Handler.html)構造体 | [v0.10.1](https://github.com/H1rono/traq-bot-http-rs/releases/tag/v0.10.1)から※`time`よりも`chrono`の方が優先されます
## Supported Rust Version
現行の MSRV(Minimum Supported Rust Version) は **1.76.0** です。
将来的にMSRVは変更される可能性がありますが、minorバージョンの更新で導入されます。
## Contributing
Issue, Pull Requestは大歓迎です。
## Blogs about this repository
- [Rustでライブラリを作った | 東京科学大学デジタル創作同好会traP](https://trap.jp/post/1819/)
- [Rustでライブラリを作った 続編 | 東京科学大学デジタル創作同好会traP](https://trap.jp/post/2438/)