bot_sdk_line 0.1.0

Line bot sdk for rust.
Documentation

LINE Messaging API SDK for Rust

Introduction

This is a library originating from nanato12/line-bot-sdk-rust, but with more complete api, newer versions of dependencies and more additional features.

The LINE Messaging API SDK for Rust makes it easy to develop bots using LINE Messaging API, and you can create a sample bot within minutes.

Documentation

See the official API documentation for more information.

Requirements

This library requires stable/beta Rust.

Installation

Cargo: Coming soon

Git: Add content below to your Cargo.toml

[dependencies.line_bot_sdk_rust]
git = "https://github.com/Kayxue/LineBotSdkRust.git"
branch = "master"

Web framework support

Extract x-line-signature from the request header.

Use rocket framework

[dependencies.line_bot_sdk_rust]
...
features = ["rocket_support"]
use line_bot_sdk_rust::support::rocket::Signature;
use rocket::{http::Status, post};

#[post("/callback", data = "<body>")]
async fn world(signature: Signature, body: String) -> (Status, &'static str) {
    ...
}

Use actix_web framework

[dependencies.line_bot_sdk_rust]
...
features = ["actix_support"]
use actix_web::{post, web, Error, HttpResponse};
use line_bot_sdk_rust::support::actix::Signature;

#[post("/callback")]
async fn callback(signature: Signature, bytes: web::Bytes) -> Result<HttpResponse, Error> {
    ...
}

Use ntex framework (Additional Support)

[dependencies.line_bot_sdk_rust]
...
features = ["ntex_support"]
use ntex::{
    util::Bytes,
    web::{Responder, WebResponseError, post},
};
use line_bot_sdk_rust::support::ntex::Signature;

#[post("/callback")]
async fn callback(
    signature: Signature,
    bytes: Bytes,
) -> Result<impl Responder, impl WebResponseError> {
    ...
}

Use xitca-web framework (Additional Support)

[dependencies.line_bot_sdk_rust]
...
features = ["xitca_support"]
use xitca_web::{bytes::Bytes, codegen::route, error::Error};
use line_bot_sdk_rust::support::xitca::Signature;

#[route("/callback",method = post)]
async fn callback(signature: Signature<'_>, bytes: Bytes) -> Result<&'static str, Error> {
    ...
}

Configuration

use line_bot_sdk_rust::client::LINE;
use std::env;

fn main() {
    let access_token: &str =
        &env::var("LINE_CHANNEL_ACCESS_TOKEN").expect("Failed to get LINE_CHANNEL_ACCESS_TOKEN");

    let line = LINE::new(access_token.to_string());
}

How to use

The LINE Messaging API uses the JSON data format.

For example, parse body (&str) into Result<CallbackRequest, serde_json::Error>.

let request: Result<CallbackRequest, serde_json::Error> = serde_json::from_str(body);

Or directly parse body from bytes body.

let request: Result<CallbackRequest, serde_json::Error> = serde_json::from_slice(&bytes);

Then:

match request {
    Err(err) => {
        // error handling
    },
    Ok(req) => {
        for e in req.events {
            // Processing for various events
        }
    }
}

Bot Examples

Contributing

Contributions are welcome! And please follow Code of Conduct.

License

Copyright 2025 KayXue

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

---

This project contains code under the Apache License 2.0:
lib/src/client/mod.rs
lib/src/parser/mod.rs
lib/src/parser/signature.rs
lib/src/support/actix.rs
lib/src/support/mod.rs
lib/src/support/rocket.rs

The following license applies to these files:

Apache License 2.0

Copyright (c) 2023 nanato12

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.