Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external select menu support #290

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>,
abdolence marked this conversation as resolved.
Show resolved Hide resolved
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>>,
}