Skip to content

Commit

Permalink
v2 init
Browse files Browse the repository at this point in the history
  • Loading branch information
amancevice committed Nov 20, 2023
1 parent b2a8a18 commit fab5869
Show file tree
Hide file tree
Showing 67 changed files with 1,085 additions and 2,620 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11.4
3.11.6
9 changes: 8 additions & 1 deletion example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ logs:
apply: | .terraform
terraform apply

.PHONY: logs validate apply
.PHONY: logs validate apply curl

.terraform:
terraform init

curl:
curl -i -d 'payload=%7B%22type%22%3A%22block_actions%22%7D' \
-H 'content-type: application/x-www-form-urlencoded' \
-H 'x-slack-request-timestamp: 1234567890' \
-H 'x-slack-signature: TODO' \
https://slack.beachplum.io/callback
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@

@logger.bind
def handler(event, _):
# Parse request payload
body = event["body"]
if event.get("isBase64Encoded"):
body = base64.b64decode(body).decode()
payload = json.loads(body)
print(json.dumps(payload))

# Handle interaction
for action in iter_actions(payload):
for action in iter_actions(event):
try:
action(payload)
action(event)
except Exception as err:
print(err)

Expand All @@ -26,19 +19,19 @@ def handler(event, _):
return response


def iter_actions(payload):
actions = payload.get("actions") or []
def iter_actions(event):
actions = event.get("actions") or []
for action in actions:
action_id = action.get("action_id")
if action_id == "slack_oauth_scopes":
yield slack_oauth_scopes_action


def slack_oauth_scopes_action(payload):
state = payload["state"]["values"]
def slack_oauth_scopes_action(event):
state = event["state"]["values"]
block = state["slack_oauth_scopes"]["slack_oauth_scopes"]
scope = block["selected_option"]
url = payload["response_url"]
url = event["response_url"]
headers = {"content-type": "application/json; charset=utf-8"}
text = "Choose a Slack OAuth scope to learn more"
blocks = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,18 @@

@logger.bind
def handler(event, _):
# Parse body
if event["isBase64Encoded"]:
body = json.loads(base64.b64decode(event["body"]))
else:
body = json.loads(event["body"])
body_type = body.get("type")
action_id = body.get("action_id")
seachterm = body.get("value")
action_id = event.get("action_id")
seachterm = event.get("value")

# Get menu options
options = []
if body_type == "block_suggestion" and action_id == "slack_oauth_scopes":
if action_id == "slack_oauth_scopes":
options = slack_oauth_scopes(seachterm)
else:
options = []

# Send response
response = {
"statusCode": 200,
"headers": {"content-type": "application/json"},
"body": json.dumps({"options": options}),
}
return response
Expand Down
42 changes: 0 additions & 42 deletions example/region/functions/slash-scopes/src/index.py

This file was deleted.

32 changes: 32 additions & 0 deletions example/region/functions/slash_command/src/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import json

from logger import logger


@logger.bind
def handler(event, _):
command = event["command"]

if command == "/test":
text = "Choose a Slack OAuth scope to learn more"
blocks = [
{
"type": "section",
"text": {"type": "plain_text", "text": text},
},
{
"block_id": "slack_oauth_scopes",
"type": "actions",
"elements": [
{
"type": "external_select",
"action_id": "slack_oauth_scopes",
"placeholder": {"type": "plain_text", "text": "Select scope"},
}
],
},
]
data = {"text": text, "blocks": blocks}
body = json.dumps(data)
resp = {"statusCode": "200", "body": body}
return resp

0 comments on commit fab5869

Please sign in to comment.