Skip to content

Commit

Permalink
Initial files support in incoming Slack messages (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence authored Mar 12, 2022
1 parent 456a029 commit c4f91bd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/models/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub struct SlackAppId(pub String);
#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct SlackChannelId(pub String);

#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct SlackClientMessageId(pub String);

impl SlackTextFormat for SlackChannelId {
fn to_slack_format(&self) -> String {
format!("<#{}>", self.value())
Expand Down Expand Up @@ -157,3 +160,6 @@ pub struct SlackTeamUrl(pub Url);

#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct SlackUnfurlId(pub String);

#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct SlackMimeType(pub String);
53 changes: 53 additions & 0 deletions src/models/src/files/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::*;

use rsb_derive::Builder;
use rvstruct::*;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use url::Url;

#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct SlackFileId(pub String);

#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct SlackFileType(pub String);

#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct SlackFilePrettyType(pub String);

#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, ValueStruct)]
pub struct SlackFileExternalType(pub String);

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackFile {
id: SlackFileId,
created: SlackDateTime,
timestamp: SlackDateTime,
name: String,
title: Option<String>,
mimetype: Option<SlackMimeType>,
filetype: Option<SlackFileType>,
pretty_type: Option<SlackFilePrettyType>,
external_type: Option<SlackFileExternalType>,
user: Option<SlackUserId>,
username: Option<String>,
url_private: Option<Url>,
url_private_download: Option<Url>,
permalink: Option<Url>,
permalink_public: Option<Url>,
#[serde(flatten)]
flags: SlackFileFlags,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackFileFlags {
editable: Option<bool>,
is_external: Option<bool>,
is_public: Option<bool>,
public_url_shared: Option<bool>,
display_as_bot: Option<bool>,
is_starred: Option<bool>,
has_rich_preview: Option<bool>,
}
2 changes: 2 additions & 0 deletions src/models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ mod common;

pub mod blocks;
pub mod events;
pub mod files;
mod messages;
pub mod socket_mode;

pub use common::*;
pub use files::*;
pub use messages::*;
5 changes: 5 additions & 0 deletions src/models/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde_with::skip_serializing_none;

mod templates;

use crate::SlackFile;
pub use templates::*;

#[skip_serializing_none]
Expand All @@ -16,6 +17,7 @@ pub struct SlackMessageOrigin {
pub channel: Option<SlackChannelId>,
pub channel_type: Option<SlackChannelType>,
pub thread_ts: Option<SlackTs>,
pub client_msg_id: Option<SlackClientMessageId>,
}

#[skip_serializing_none]
Expand All @@ -24,6 +26,8 @@ pub struct SlackMessageContent {
pub text: Option<String>,
pub blocks: Option<Vec<SlackBlock>>,
pub attachments: Option<Vec<SlackMessageAttachment>>,
pub upload: Option<bool>,
pub files: Option<Vec<SlackFile>>,
}

#[skip_serializing_none]
Expand All @@ -32,6 +36,7 @@ pub struct SlackMessageSender {
pub user: Option<SlackUserId>,
pub bot_id: Option<SlackBotId>,
pub username: Option<String>,
pub display_as_bot: Option<bool>,
}

#[skip_serializing_none]
Expand Down

0 comments on commit c4f91bd

Please sign in to comment.