4 stable releases

Uses new Rust 2024

1.0.3 Mar 2, 2025
1.0.1 Feb 26, 2025
1.0.0 Sep 10, 2024

#1 in #ding-talk

Download history 5/week @ 2024-12-04 3/week @ 2024-12-11 8/week @ 2025-02-05 475/week @ 2025-02-26 55/week @ 2025-03-05

530 downloads per month
Used in dingtalk-cli

MIT license

28KB
483 lines

Table of Contents↗️

dingtalk-sdk-rust

Dingtalk SDK for Rust.


This project is a DingTalk API SDK written in Rust, providing convenient tools for sending messages via DingTalk robots (Webhook and Enterprise Bots). It leverages asynchronous programming using Tokio, offering straightforward and efficient interaction with DingTalk services.

Features

  • Async Support: Built using Tokio for efficient asynchronous communication.
  • Webhook Robot: Supports various message types such as Text, Link, Markdown, ActionCard, and FeedCard.
  • Enterprise Robot: Send messages to groups and individuals using DingTalk Enterprise API.
  • Automatic Signature: Automatically generates signatures for secured Webhook interactions.
  • Comprehensive Error Handling: Robust error reporting with clear error types and messages.

Supported Message Types

Webhook Robot

  • Text Messages
  • Link Messages
  • Markdown Messages
  • ActionCard Messages (Single and Multi-Button)
  • FeedCard Messages

Enterprise Robot

  • Group Messages
  • Private (OTO) Messages
  • Automatic message reply handling based on message context

Installation

Add the following to your Cargo.toml:

[dependencies]
dingtalk-sdk = "1"

Quick Example

Webhook Robot

use dingtalk_sdk::DingTalkRobot;

#[tokio::main]
async fn main() {
    let robot = DingTalkRobot::new("your_token".into(), Some("your_secret".into()));

    match robot.send_text_message("Hello from Rust!", None, None, Some(false)).await {
        Ok(response) => println!("Sent successfully: {}", response),
        Err(e) => eprintln!("Error sending message: {}", e),
    }
}

Enterprise Robot

use dingtalk_sdk::EnterpriseDingTalkRobot;

#[tokio::main]
async fn main() {
    let robot = EnterpriseDingTalkRobot::new("appkey".into(), "appsecret".into(), "robot_code".into());

    match robot.send_group_message("open_conversation_id", "Greetings", "Hello group from Rust!").await {
        Ok(response) => println!("Message sent: {}", response),
        Err(e) => eprintln!("Error sending message: {}", e),
    }
}

License

This project is licensed under the MIT License.

Dependencies

~5–21MB
~219K SLoC