Skip to content

Commit

Permalink
added custom response to slack-collector
Browse files Browse the repository at this point in the history
  • Loading branch information
ca7alindev committed Sep 23, 2024
1 parent d7a4b9c commit b9baf4b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions example/composition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
apiVersion: kndp.io/v1alpha1
kind: Poll
providerConfigRef: "kndp-kubernetes-provider-config"
deploymentImage: "ghcr.io/kndpio/function-poll/slack-collector:c9def"
cronJobImage: "ghcr.io/kndpio/function-poll/slack-notify:c9def"
deploymentImage: "ghcr.io/kndpio/function-poll/slack-collector:d7a4b"
cronJobImage: "ghcr.io/kndpio/function-poll/slack-notify:d7a4b"
deploymentName: "slack-collector"
serviceAccountName: "slack-collector"
2 changes: 1 addition & 1 deletion example/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ metadata:
# render.crossplane.io/runtime: Development
spec:
# This is ignored when using the Development runtime.
package: ghcr.io/kndpio/function-poll:c9def
package: ghcr.io/kndpio/function-poll:d7a4b
runtimeConfigRef:
name: poll-function-runtime
3 changes: 3 additions & 0 deletions example/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ rules:
- apiGroups: ["kndp.io"]
resources: ["polls"]
verbs: ["*"]
- apiGroups: ["kndp.io"]
resources: ["polls/status"]
verbs: ["*"]
- apiGroups: ["v1"]
resources: ["services"]
verbs: ["*"]
Expand Down
2 changes: 1 addition & 1 deletion example/xr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: meal
spec:
deliveryTime: 0
dueOrderTime: 10
dueOrderTime: 15
dueTakeTime: 0
voters: []
title: "meal"
Expand Down
11 changes: 6 additions & 5 deletions internal/slack-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ type Poll struct {
}

var (
api = slack.New(os.Getenv("SLACK_API_TOKEN"))
path = os.Getenv("SLACK_COLLECTOR_PATH")
port = os.Getenv("SLACK_COLLECTOR_PORT")
api = slack.New(os.Getenv("SLACK_API_TOKEN"))
path = os.Getenv("SLACK_COLLECTOR_PATH")
port = os.Getenv("SLACK_COLLECTOR_PORT")
response string
)

// handleEventsEndpoint handles the events endpoint.
Expand Down Expand Up @@ -114,7 +115,7 @@ func patchVoterStatus(user, pollSlackName, selectedOption string, dynamicClient
if err != nil {
return err
}

response = pollResource.Spec.Messages.Response
foundUser := false
for i := range pollResource.Spec.Voters {
if pollResource.Spec.Voters[i].Name == user {
Expand Down Expand Up @@ -170,7 +171,7 @@ func respondMsg(userID string, userName string, selectedOption string, pollName
attachment := slack.Attachment{
Color: "#f9a41b",
CallbackID: pollName,
Text: "\n Selected: " + selectedOption,
Text: response + "\n Selected: " + selectedOption,
Fields: []slack.AttachmentField{},
Actions: []slack.AttachmentAction{},
MarkdownIn: []string{},
Expand Down

0 comments on commit b9baf4b

Please sign in to comment.