#slack #webhook #messaging #hook

slack-hook

通过 webhooks 向 Slack 发送消息的 Rust crate

14 个版本 (8 个破坏性更新)

使用旧的 Rust 2015

0.8.0 2018 年 10 月 23 日
0.6.0 2017 年 9 月 26 日
0.5.0 2017 年 7 月 24 日
0.3.0 2017 年 2 月 26 日
0.0.1 2014 年 12 月 30 日

#1514 in 网页编程

Download history 918/week @ 2024-03-14 1043/week @ 2024-03-21 1045/week @ 2024-03-28 748/week @ 2024-04-04 939/week @ 2024-04-11 916/week @ 2024-04-18 1031/week @ 2024-04-25 1098/week @ 2024-05-02 1143/week @ 2024-05-09 1060/week @ 2024-05-16 883/week @ 2024-05-23 1325/week @ 2024-05-30 1446/week @ 2024-06-06 1169/week @ 2024-06-13 935/week @ 2024-06-20 688/week @ 2024-06-27

4,430 每月下载量
用于 6 个 crates (5 直接)

MIT/Apache

41KB
882

rust-slack

Travis Build Status Documentation crates.io MIT licensed Apache licensed

通过 webhooks 向 Slack 发送消息的 Rust crate。

Slack 是一个团队协作的消息平台。

正在升级?请查看 变更日志

需要 rust 1.17 或更高版本。

用法

将此添加到您的 Cargo.toml

[dependencies]
slack-hook = "0.7"

将 crate 添加到您的现有项目中

extern crate slack_hook;
use slack_hook::{Slack, PayloadBuilder};

fn main() {
    let slack = Slack::new("https://hooks.slack.com/services/abc/123/45z").unwrap();
    let p = PayloadBuilder::new()
      .text("test message")
      .channel("#testing")
      .username("My Bot")
      .icon_emoji(":chart_with_upwards_trend:")
      .build()
      .unwrap();

    let res = slack.send(&p);
    match res {
        Ok(()) => println!("ok"),
        Err(x) => println!("ERR: {:?}",x)
    }
}

附件

创建仅包含附件的有效负载

extern crate slack_hook;
use slack_hook::{PayloadBuilder, AttachmentBuilder};

fn main() {
  let _ = PayloadBuilder::new()
    .attachments(vec![AttachmentBuilder::new("my text").color("#b13d41").build().unwrap()])
    .build()
    .unwrap();
}

Slack 消息 API 允许您在文本中发送链接。然而,由于不同的格式化规则,这些文本片段需要如下指定

extern crate slack_hook;
use slack_hook::{PayloadBuilder, SlackTextContent, SlackLink};
use slack_hook::SlackTextContent::{Text, Link};

fn main() {
  let _ = PayloadBuilder::new()
    .text(vec![
      Text("Hello".into()),
      Link(SlackLink::new("https://google.com", "Google")),
      Text(", nice to know you.".into())
    ].as_slice())
    .build()
    .unwrap();
}

发送此有效负载将在 Slack 中打印以下内容(注意:Vec 的每个元素都已用空格分隔)

      Hello Google, nice to know you.

此技术可用于任何具有 Into<SlackText> 特征约束的函数。

许可证

此库以类似 Rust 的条款分发:MIT 许可证和 Apache 许可证(版本 2.0)的双重许可。

请参阅 LICENSE-APACHELICENSE-MITCOPYRIGHT 了解详细信息。

依赖项

~24MB
~510K SLoC