Skip to main content

Crate dingtalk_stream

Crate dingtalk_stream 

Source
Expand description

DingTalk Stream SDK for Rust

A Rust implementation of the DingTalk Stream SDK, based on the Node.js and Python SDKs.

§Quick Start

use dingtalk_stream::{Credential, DingTalkStream, CallbackHandler, MessageTopic, TOPIC_ROBOT};
use dingtalk_stream::handlers::{Resp, Error, ErrorCode};
use async_trait::async_trait;
use dingtalk_stream::frames::{CallbackMessage, CallbackWebhookMessage};
use tokio::sync::mpsc::Sender;

// Define a handler for robot messages
struct MyRobotHandler(MessageTopic);

#[async_trait]
impl CallbackHandler for MyRobotHandler {
    async fn process(&self, message: &CallbackMessage, cb_webhook_msg_sender: Option<Sender<CallbackWebhookMessage>>) -> Result<Resp, Error> {
        // Process the message and return a response
        Ok(Resp::Text("Hello from DingTalk SDK!".to_string()))
    }

    fn topic(&self) -> &MessageTopic {
        &self.0
    }
}

#[tokio::main]
async fn main() -> Result<()> {
    let credential = Credential::new(
        "your-client-id".to_string(),
        "your-client-secret".to_string(),
    );

    let mut client = DingTalkStream::new(credential)
        .register_callback_handler(MyRobotHandler(
            MessageTopic::Callback(TOPIC_ROBOT.to_string()),
        ));

    client.start().await;
    Ok(())
}

Re-exports§

pub use client::ClientConfig;
pub use client::DingTalkStream;
pub use credential::Credential;

Modules§

client
DingTalk Stream Client
credential
Credential module for DingTalk Stream SDK
frames
Frames module for DingTalk Stream SDK
handlers
Handlers module for DingTalk Stream SDK
utils
Utility functions for DingTalk Stream SDK

Constants§

GATEWAY_URL
The DingTalk gateway URL for opening connections
GET_TOKEN_URL
The DingTalk API endpoint for getting access tokens
MEDIA_UPLOAD_URL
MESSAGE_FILES_DOWNLOAD_URL
ROBOT_SEND_GROUP_MESSAGE
ROBOT_SEND_PRIVATE_MESSAGE
TOPIC_CARD
The topic for card callback
TOPIC_ROBOT
The topic for robot message callbacks
TOPIC_ROBOT_DELEGATE
The topic for robot delegate message callbacks
VERSION
SDK version

Type Aliases§

Result