Skip to content

Commit

Permalink
Add external select menu support (#290)
Browse files Browse the repository at this point in the history
* Add block_suggestion event support

* Add message to SlackInteractionBlockSuggestionEvent
  • Loading branch information
nnishimura authored Oct 2, 2024
1 parent 7182c12 commit 42de20e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/hyper_tokio/listener/interaction_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ impl<H: 'static + Send + Sync + Connect + Clone> 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 {
Expand Down Expand Up @@ -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<Response<Body>> {
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())?)
}
}
35 changes: 35 additions & 0 deletions src/models/events/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -40,6 +42,20 @@ pub struct SlackInteractionBlockActionsEvent {
pub state: Option<SlackActionState>,
}

#[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<SlackView>,
pub value: String,
pub message: Option<SlackHistoryMessage>,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum SlackInteractionActionContainer {
Expand Down Expand Up @@ -131,3 +147,22 @@ pub struct SlackInteractionViewClosedEvent {
pub view: SlackStatefulView,
pub trigger_id: Option<SlackTriggerId>,
}

#[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<SlackBlockChoiceItem<SlackBlockPlainTextOnly>>,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackBlockSuggestionOptionGroups {
pub option_groups: Vec<SlackBlockOptionGroup<SlackBlockPlainTextOnly>>,
}

0 comments on commit 42de20e

Please sign in to comment.