Crates.io | dingtalk |
lib.rs | dingtalk |
version | 2.0.2 |
source | src |
created_at | 2019-12-17 15:51:33.30933 |
updated_at | 2021-01-08 16:55:40.915241 |
description | DingTalk Robot Util, Send text/markdown/link messages using DingTalk robot, 钉钉机器人 |
homepage | |
repository | https://git.hatter.ink/hatter/dingtalk |
max_upload_size | |
id | 190033 |
size | 32,887 |
DingTalk Robot Util, Send text/markdown/link messages using DingTalk robot
钉钉机器人 Rust SDK
NOTE: From version 1.1.0 dingtalk uses reqwest 0.10.0's async
/.await
API.
Official reference: https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/0fa88adc
Sample 1:
use dingtalk::DingTalk;
#[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
let dt = DingTalk::new("<token>", "");
dt.send_text("Hello world!").await?;
Ok(())
}
Need use crate: tokio = { version = "0.2.6", features = ["full"] }
.
Sample 2 (Read token from file):
#[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
let dt = DingTalk::from_file("~/.dingtalk-token.json")?;
dt.send_text("Hello world!").await?;
Ok(())
}
Sample, send markdown message:
dt.send_markdown("markdown title 001", r#"# markdown content 001
* line 0
* line 1
* line 2"#).await?;
Sample, send link message:
dt.send_link("link title 001", "link content 001", "https://hatter.ink/favicon.png", "https://hatter.ink/").await?;
Sample, send feed card message:
dt.send_message(DingTalkMessage::new_feed_card()
.add_feed_card_link(DingTalkMessageFeedCardLink{
title: "test feed card title 001".into(),
message_url: "https://hatter.ink/".into(),
pic_url: "https://hatter.ink/favicon.png".into(),
})
.add_feed_card_link(DingTalkMessageFeedCardLink{
title: "test feed card title 002".into(),
message_url: "https://hatter.ink/".into(),
pic_url: "https://hatter.ink/favicon.png".into(),
})
).await?;
Sample, send action card message(single btn):
dt.send_message(DingTalkMessage::new_action_card("action card 001", "action card text 001")
.set_action_card_signle_btn(DingTalkMessageActionCardBtn{
title: "test signle btn title".into(),
action_url: "https://hatter.ink/".into(),
})
).await?;
Sample, send action card message(multi btns):
dt.send_message(DingTalkMessage::new_action_card("action card 002", "action card text 002")
.add_action_card_btn(DingTalkMessageActionCardBtn{
title: "test signle btn title 01".into(),
action_url: "https://hatter.ink/".into(),
})
.add_action_card_btn(DingTalkMessageActionCardBtn{
title: "test signle btn title 02".into(),
action_url: "https://hatter.ink/".into(),
})
).await?;
DingTalk config:
{
"access_token": "<access token>",
"sec_token": "<sec token>"
}
WeChat Work config:
{
"type": "wechat",
"access_token": "<token>"
}
'a
life cycleDingTalk::from_token
DingTalk::new_wechat
"type": "wechat"
, supports method DingTalk::send_text
maplit
crateserde
and serde_json
crates, replace json
cratehmac
and sha2
crates, replace rust-crypto
crateDingTalk::from_json
add direct_url
TEXT
-> Text
..., change enum capsActionCard
message, send action card message typedirect_url
for DingTalk
, for outgoing robotFeedCard
message, send feed card message typeDingtalk::from_json
, read token from JSON stringDingTalk::from_file
, read token from fileDefault::default()
supportset_default_webhook_url
, default dingtalk webhook urlDingTalk::send_link(...)
, send link messageDingTalkMessage
, can set at_all
, at_mobiles
now