Skip to content

Commit 43cbf63

Browse files
update: add app command for test
1 parent dbad795 commit 43cbf63

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/cdk/resources/Apis.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ export class Apis extends Construct {
3737
lambdaFunction: props.functions.slackBot
3838
})
3939

40+
// Create the '/slack/commands' POST endpoint for Slack Events API
41+
// This endpoint will handle slash commands, such as /test
42+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
43+
const slackCommandsEndpoint = new LambdaEndpoint(this, "SlackCommandsEndpoint", {
44+
parentResource: slackResource,
45+
resourceName: "commands",
46+
method: HttpMethod.POST,
47+
restApiGatewayRole: apiGateway.role,
48+
lambdaFunction: props.functions.slackBot
49+
})
50+
4051
this.apis = {
4152
api: apiGateway
4253
}

packages/slackBotFunction/app/slack/slack_handlers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def setup_handlers(app: App) -> None:
4141
app.event("message")(ack=respond_to_events, lazy=[unified_message_handler])
4242
app.action("feedback_yes")(ack=respond_to_action, lazy=[feedback_handler])
4343
app.action("feedback_no")(ack=respond_to_action, lazy=[feedback_handler])
44-
app.command("test")(ack=respond_to_command, lazy=[feedback_handler])
44+
app.command("test")(ack=respond_to_command, lazy=[prompt_test_handler])
4545
for i in range(1, 10):
4646
app.action(f"cite_{i}")(ack=respond_to_action, lazy=[feedback_handler])
4747

@@ -133,3 +133,14 @@ def unified_message_handler(client: WebClient, event: Dict[str, Any], body: Dict
133133
process_async_slack_event(event=event, event_id=event_id, client=client)
134134
except Exception:
135135
logger.error("Error triggering async processing", extra={"error": traceback.format_exc()})
136+
137+
138+
def prompt_test_handler(body: Dict[str, Any], event: Dict[str, Any], client: WebClient) -> None:
139+
"""Handle /test command to prompt the bot to respond."""
140+
try:
141+
event_id = gate_common(event=event, body=body)
142+
logger.debug("logging result of gate_common", extra={"event_id": event_id, "body": body})
143+
if not event_id:
144+
return
145+
except Exception as e:
146+
logger.error(f"Error handling /test command: {e}", extra={"error": traceback.format_exc()})

0 commit comments

Comments
 (0)