traq-bot-http

Crates.iotraq-bot-http
lib.rstraq-bot-http
version0.10.1
sourcesrc
created_at2023-02-22 13:07:59.831042
updated_at2024-11-09 14:38:03.661639
descriptionLibrary to parse POST requests of traQ BOT event
homepagehttps://github.com/H1rono/traq-bot-http-rs
repositoryhttps://github.com/H1rono/traq-bot-http-rs
max_upload_size
id791801
size156,425
H1rono_K (H1rono)

documentation

README

traq-bot-http-rs

Rust codecov Release docs.rs

GitHub Crates.io GitHub release (with filter) Crates.io

traQ BOTのPOSTリクエストをパースするライブラリです。

example

Cargo.toml

# ...

[dependencies]
http = "1"
tower = "0.4"
axum = "0.7"
tokio = { version = "1", features = ["full"] }
traq-bot-http = { version = "0.10.1", features = ["tower"] }

main.rs

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型に | v0.4.0から time | ペイロードのタイムスタンプ値(RFC3339 format)がtime::OffsetDateTime型に | v0.5.0から chrono | ペイロードのタイムスタンプ値がchrono::DateTime<chrono::Utc>型に | v0.6.0から http | http::Request型のサポート | v0.10.0

timeよりもchronoの方が優先されます

Contributing

Issue, Pull Requestは大歓迎です。

Commit count: 468

cargo fmt