|
|
|
@ -52,13 +52,42 @@ func main() { |
|
|
|
switch event.Type { |
|
|
|
// handle EventInteractive events
|
|
|
|
case socketmode.EventTypeInteractive: |
|
|
|
fmt.Println("Recivimos un Interactive!", event) |
|
|
|
eventsInteractive, ok := event.Data.(slackevents.EventsAPICallbackEvent) |
|
|
|
// fmt.Println("Recivimos un Interactive!", event)
|
|
|
|
|
|
|
|
callback, ok := event.Data.(slack.InteractionCallback) |
|
|
|
|
|
|
|
if !ok { |
|
|
|
log.Printf("Could not type cast the event to the EventsAPICallbackEvent: %v\n", event) |
|
|
|
log.Printf("Could not type cast the event to the MessageAction: %v\n", event) |
|
|
|
continue |
|
|
|
} |
|
|
|
fmt.Println("Se pudo castear!!", eventsInteractive) |
|
|
|
socketClient.Ack(*event.Request) |
|
|
|
switch callback.Type { |
|
|
|
case slack.InteractionTypeInteractionMessage: |
|
|
|
//fmt.Println("type:", callback.Type, "callBackId:", callback.CallbackID, "aactions[0]", *callback.ActionCallback.AttachmentActions[0])
|
|
|
|
action := *callback.ActionCallback.AttachmentActions[0] |
|
|
|
//fmt.Println("Value:", action.Value)
|
|
|
|
switch action.Value { |
|
|
|
case "poweron": |
|
|
|
fmt.Println("Encender!") |
|
|
|
case "poweroff": |
|
|
|
fmt.Println("Apagar!") |
|
|
|
} |
|
|
|
|
|
|
|
replyToAction(callback.Channel.Name, "Chi chi chi chi amo!", client) |
|
|
|
case slack.InteractionTypeMessageAction: |
|
|
|
fmt.Println("is a message action?") |
|
|
|
|
|
|
|
case slack.InteractionTypeBlockActions: |
|
|
|
// See https://api.slack.com/apis/connections/socket-implement#button
|
|
|
|
|
|
|
|
fmt.Println("button clicked!") |
|
|
|
case slack.InteractionTypeShortcut: |
|
|
|
case slack.InteractionTypeViewSubmission: |
|
|
|
// See https://api.slack.com/apis/connections/socket-implement#modal
|
|
|
|
case slack.InteractionTypeDialogSubmission: |
|
|
|
default: |
|
|
|
|
|
|
|
} |
|
|
|
// handle EventAPI events
|
|
|
|
case socketmode.EventTypeEventsAPI: |
|
|
|
// The Event sent on the channel is not the same as the EventAPI events so we need to type cast it
|
|
|
|
@ -70,7 +99,7 @@ func main() { |
|
|
|
// We need to send an Acknowledge to the slack server
|
|
|
|
socketClient.Ack(*event.Request) |
|
|
|
// Now we have an Events API event, but this event type can in turn be many types, so we actually need another type switch
|
|
|
|
log.Println(eventsAPIEvent) |
|
|
|
// log.Println(eventsAPIEvent)
|
|
|
|
err := handleEventMessage(eventsAPIEvent, client) |
|
|
|
if err != nil { |
|
|
|
// Replace with actual err handeling
|
|
|
|
@ -92,7 +121,7 @@ func handleEventMessage(event slackevents.EventsAPIEvent, client *slack.Client) |
|
|
|
case slackevents.CallbackEvent: |
|
|
|
|
|
|
|
innerEvent := event.InnerEvent |
|
|
|
fmt.Println("We received an event!", innerEvent) |
|
|
|
// fmt.Println("We received an event!", innerEvent)
|
|
|
|
// Yet Another Type switch on the actual Data to see if its an AppMentionEvent
|
|
|
|
switch ev := innerEvent.Data.(type) { |
|
|
|
case *slackevents.AppMentionEvent: |
|
|
|
@ -106,6 +135,17 @@ func handleEventMessage(event slackevents.EventsAPIEvent, client *slack.Client) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func replyToAction(channelName string, message string, client *slack.Client) error { |
|
|
|
attachment := slack.Attachment{} |
|
|
|
attachment.Text = message |
|
|
|
attachment.Color = "#4af030" |
|
|
|
_, _, err := client.PostMessage(channelName, slack.MsgOptionAttachments(attachment)) |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("failed to post message: %w", err) |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// handleAppMentionEvent is used to take care of the AppMentionEvent when the bot is mentioned
|
|
|
|
func handleAppMentionEvent(event *slackevents.AppMentionEvent, client *slack.Client) error { |
|
|
|
|
|
|
|
|