plexus_comms/activations/slack/
activation.rs1use super::types::*;
2use crate::config::SlackConfig;
3use async_stream::stream;
4use futures::Stream;
5
6use plexus_core::plexus;
8use plexus_core::serde_helpers;
9
10#[derive(Clone)]
11pub struct Slack {
12 bot_token: String,
13 client: reqwest::Client,
14}
15
16impl Slack {
17 pub async fn new(config: SlackConfig) -> Result<Self, String> {
18 Ok(Self {
19 bot_token: config.bot_token,
20 client: reqwest::Client::new(),
21 })
22 }
23}
24
25#[plexus_macros::hub_methods(
26 namespace = "slack",
27 version = "1.0.0",
28 description = "Send messages and interact with Slack workspaces"
29)]
30impl Slack {
31 #[plexus_macros::hub_method(
32 description = "Send a message to a channel",
33 params(
34 channel = "Channel ID or name",
35 text = "Message text",
36 thread_ts = "Thread timestamp for replies (optional)",
37 attachments = "Message attachments (optional)"
38 )
39 )]
40 async fn send_message(
41 &self,
42 channel: String,
43 text: String,
44 thread_ts: Option<String>,
45 attachments: Option<Vec<serde_json::Value>>,
46 ) -> impl Stream<Item = SendMessageEvent> + Send + 'static {
47 let _params = SendMessageParams {
48 channel: channel.clone(),
49 text,
50 thread_ts,
51 attachments,
52 };
53
54 stream! {
55 yield SendMessageEvent::Sent {
57 ts: chrono::Utc::now().timestamp().to_string(),
58 channel,
59 };
60 }
61 }
62
63 #[plexus_macros::hub_method(
64 description = "Create a new channel",
65 params(
66 name = "Channel name",
67 is_private = "Whether the channel is private (optional, default: false)"
68 )
69 )]
70 async fn create_channel(
71 &self,
72 name: String,
73 is_private: Option<bool>,
74 ) -> impl Stream<Item = ChannelEvent> + Send + 'static {
75 let _params = CreateChannelParams {
76 name: name.clone(),
77 is_private,
78 };
79
80 stream! {
81 yield ChannelEvent::Created {
82 channel_id: format!("C{}", uuid::Uuid::new_v4().to_string().replace('-', "")),
83 name,
84 };
85 }
86 }
87
88 #[plexus_macros::hub_method(
89 streaming,
90 description = "Listen for Slack events (messages, reactions, etc.)"
91 )]
92 async fn listen_events(&self) -> impl Stream<Item = SlackEvent> + Send + 'static {
93 stream! {
94 yield SlackEvent::Error {
96 message: "Not implemented yet".to_string(),
97 };
98 }
99 }
100}