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