From ec6c501004f785edf7cbfb3013c2519ea634cdc6 Mon Sep 17 00:00:00 2001 From: Naoko Nishimura Date: Sun, 29 Sep 2024 14:23:15 -0700 Subject: [PATCH 1/2] Add block_suggestion event support --- .../listener/interaction_events.rs | 25 ++++++++++++++ src/models/events/interaction.rs | 34 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/hyper_tokio/listener/interaction_events.rs b/src/hyper_tokio/listener/interaction_events.rs index 54be18e..2f77b6c 100644 --- a/src/hyper_tokio/listener/interaction_events.rs +++ b/src/hyper_tokio/listener/interaction_events.rs @@ -85,6 +85,21 @@ impl SlackClientEventsHyperListener< } } + } + Ok(block_suggestion_event@SlackInteractionEvent::BlockSuggestion(_)) => { + match interaction_service_fn(block_suggestion_event.clone(), sc.clone(), thread_user_state_storage.clone()).await { + Ok(response) => { + response.to_http_response(&block_suggestion_event) + } + Err(err) => { + let status_code = thread_error_handler(err, sc, thread_user_state_storage); + Response::builder() + .status(status_code) + .body(Empty::new().boxed()) + .map_err(|e| e.into()) + } + } + } Ok(interaction_event) => { match interaction_service_fn(interaction_event.clone(), sc.clone(), thread_user_state_storage.clone()).await { @@ -145,3 +160,13 @@ impl SlackInteractionEventResponse for SlackViewSubmissionResponse { .body(Full::new(json_str.into()).boxed())?) } } + +impl SlackInteractionEventResponse for SlackBlockSuggestionResponse { + fn to_http_response(&self, _event: &SlackInteractionEvent) -> AnyStdResult> { + let json_str = serde_json::to_string(&self)?; + Ok(Response::builder() + .status(StatusCode::OK) + .header("content-type", "application/json; charset=utf-8") + .body(Full::new(json_str.into()).boxed())?) + } +} diff --git a/src/models/events/interaction.rs b/src/models/events/interaction.rs index f579565..1e97a2d 100644 --- a/src/models/events/interaction.rs +++ b/src/models/events/interaction.rs @@ -12,6 +12,8 @@ use std::collections::HashMap; pub enum SlackInteractionEvent { #[serde(rename = "block_actions")] BlockActions(SlackInteractionBlockActionsEvent), + #[serde(rename = "block_suggestion")] + BlockSuggestion(SlackInteractionBlockSuggestionEvent), #[serde(rename = "dialog_submission")] DialogSubmission(SlackInteractionDialogueSubmissionEvent), #[serde(rename = "message_action")] @@ -40,6 +42,19 @@ pub struct SlackInteractionBlockActionsEvent { pub state: Option, } +#[skip_serializing_none] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)] +pub struct SlackInteractionBlockSuggestionEvent { + pub team: SlackBasicTeamInfo, + pub user: SlackBasicUserInfo, + pub api_app_id: SlackAppId, + pub block_id: SlackBlockId, + pub action_id: SlackActionId, + pub container: SlackInteractionActionContainer, + pub view: Option, + pub value: String, +} + #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[serde(tag = "type")] pub enum SlackInteractionActionContainer { @@ -131,3 +146,22 @@ pub struct SlackInteractionViewClosedEvent { pub view: SlackStatefulView, pub trigger_id: Option, } + +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum SlackBlockSuggestionResponse { + Options(SlackBlockSuggestionOptions), + OptionGroups(SlackBlockSuggestionOptionGroups), +} + +#[skip_serializing_none] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)] +pub struct SlackBlockSuggestionOptions { + pub options: Vec>, +} + +#[skip_serializing_none] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)] +pub struct SlackBlockSuggestionOptionGroups { + pub option_groups: Vec>, +} From c01951d83975675b0286488ea85c3464e852483f Mon Sep 17 00:00:00 2001 From: Naoko Nishimura Date: Tue, 1 Oct 2024 22:55:40 -0700 Subject: [PATCH 2/2] Add message to SlackInteractionBlockSuggestionEvent --- src/models/events/interaction.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/models/events/interaction.rs b/src/models/events/interaction.rs index 1e97a2d..44f7e1b 100644 --- a/src/models/events/interaction.rs +++ b/src/models/events/interaction.rs @@ -53,6 +53,7 @@ pub struct SlackInteractionBlockSuggestionEvent { pub container: SlackInteractionActionContainer, pub view: Option, pub value: String, + pub message: Option, } #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]