|
|
@ -49,8 +49,6 @@ func Start() { |
|
|
switch event.Type { |
|
|
switch event.Type { |
|
|
// handle EventInteractive events
|
|
|
// handle EventInteractive events
|
|
|
case socketmode.EventTypeInteractive: |
|
|
case socketmode.EventTypeInteractive: |
|
|
//fmt.Println("Recivimos un Interactive!", event)
|
|
|
|
|
|
|
|
|
|
|
|
callback, ok := event.Data.(slack.InteractionCallback) |
|
|
callback, ok := event.Data.(slack.InteractionCallback) |
|
|
|
|
|
|
|
|
if !ok { |
|
|
if !ok { |
|
|
@ -60,9 +58,7 @@ func Start() { |
|
|
socketClient.Ack(*event.Request) |
|
|
socketClient.Ack(*event.Request) |
|
|
switch callback.Type { |
|
|
switch callback.Type { |
|
|
case slack.InteractionTypeInteractionMessage: |
|
|
case slack.InteractionTypeInteractionMessage: |
|
|
//fmt.Println("type:", callback.Type, "callBackId:", callback.CallbackID, "aactions[0]", *callback.ActionCallback.AttachmentActions[0])
|
|
|
|
|
|
action := *callback.ActionCallback.AttachmentActions[0] |
|
|
action := *callback.ActionCallback.AttachmentActions[0] |
|
|
//fmt.Println("Value:", action.Value)
|
|
|
|
|
|
var output string |
|
|
var output string |
|
|
var err error |
|
|
var err error |
|
|
|
|
|
|
|
|
@ -73,18 +69,15 @@ func Start() { |
|
|
replyToAction(callback.Channel.ID, finalMessage, client) |
|
|
replyToAction(callback.Channel.ID, finalMessage, client) |
|
|
} |
|
|
} |
|
|
case slack.InteractionTypeMessageAction: |
|
|
case slack.InteractionTypeMessageAction: |
|
|
//fmt.Println("is a message action?")
|
|
|
|
|
|
|
|
|
|
|
|
case slack.InteractionTypeBlockActions: |
|
|
case slack.InteractionTypeBlockActions: |
|
|
// See https://api.slack.com/apis/connections/socket-implement#button
|
|
|
// See https://api.slack.com/apis/connections/socket-implement#button
|
|
|
|
|
|
|
|
|
//fmt.Println("button clicked!")
|
|
|
|
|
|
case slack.InteractionTypeShortcut: |
|
|
case slack.InteractionTypeShortcut: |
|
|
case slack.InteractionTypeViewSubmission: |
|
|
case slack.InteractionTypeViewSubmission: |
|
|
// See https://api.slack.com/apis/connections/socket-implement#modal
|
|
|
// See https://api.slack.com/apis/connections/socket-implement#modal
|
|
|
case slack.InteractionTypeDialogSubmission: |
|
|
case slack.InteractionTypeDialogSubmission: |
|
|
default: |
|
|
default: |
|
|
//fmt.Println("Don't know what type it is")
|
|
|
|
|
|
} |
|
|
} |
|
|
// handle EventAPI events
|
|
|
// handle EventAPI events
|
|
|
case socketmode.EventTypeEventsAPI: |
|
|
case socketmode.EventTypeEventsAPI: |
|
|
@ -104,7 +97,6 @@ func Start() { |
|
|
// log.Fatal(err)
|
|
|
// log.Fatal(err)
|
|
|
} |
|
|
} |
|
|
default: |
|
|
default: |
|
|
//fmt.Println("Event received no matching TYPE:", event.Type, "event:", event)
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
@ -121,7 +113,6 @@ func handleEventMessage(event slackevents.EventsAPIEvent, client *slack.Client) |
|
|
case slackevents.CallbackEvent: |
|
|
case slackevents.CallbackEvent: |
|
|
|
|
|
|
|
|
innerEvent := event.InnerEvent |
|
|
innerEvent := event.InnerEvent |
|
|
// fmt.Println("We received an event!", innerEvent)
|
|
|
|
|
|
// Yet Another Type switch on the actual Data to see if its an AppMentionEvent
|
|
|
// Yet Another Type switch on the actual Data to see if its an AppMentionEvent
|
|
|
switch ev := innerEvent.Data.(type) { |
|
|
switch ev := innerEvent.Data.(type) { |
|
|
case *slackevents.AppMentionEvent: |
|
|
case *slackevents.AppMentionEvent: |
|
|
@ -132,7 +123,6 @@ func handleEventMessage(event slackevents.EventsAPIEvent, client *slack.Client) |
|
|
//log.Println("MessageEvent!", ev)
|
|
|
//log.Println("MessageEvent!", ev)
|
|
|
handleAppMessagedEvent(ev, client) |
|
|
handleAppMessagedEvent(ev, client) |
|
|
default: |
|
|
default: |
|
|
//fmt.Println("Not handled EventMessage!:", ev)
|
|
|
|
|
|
} |
|
|
} |
|
|
default: |
|
|
default: |
|
|
return errors.New("unsupported event type") |
|
|
return errors.New("unsupported event type") |
|
|
@ -141,7 +131,6 @@ func handleEventMessage(event slackevents.EventsAPIEvent, client *slack.Client) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func executeAction(actionName string) (string, error) { |
|
|
func executeAction(actionName string) (string, error) { |
|
|
//fmt.Println("executeAction actionName:", actionName, "actions:", config.Config.Actions)
|
|
|
|
|
|
var output_str string |
|
|
var output_str string |
|
|
var err error |
|
|
var err error |
|
|
for _, action := range config.Config.Actions { |
|
|
for _, action := range config.Config.Actions { |
|
|
@ -172,28 +161,26 @@ func executeScript(scriptPath string) (string, error) { |
|
|
// The error returned by cmd.Output() will be OS specific based on what
|
|
|
// The error returned by cmd.Output() will be OS specific based on what
|
|
|
// happens when a process is killed.
|
|
|
// happens when a process is killed.
|
|
|
if ctx.Err() == context.DeadlineExceeded { |
|
|
if ctx.Err() == context.DeadlineExceeded { |
|
|
fmt.Println("Command timed out") |
|
|
log.Println("Command timed out") |
|
|
return "", context.DeadlineExceeded |
|
|
return "", context.DeadlineExceeded |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// If there's no context error, we know the command completed (or errored).
|
|
|
// If there's no context error, we know the command completed (or errored).
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("Non-zero exit code:", err) |
|
|
log.Println("Non-zero exit code:", err) |
|
|
} |
|
|
} |
|
|
output_str := string(out) |
|
|
output_str := string(out) |
|
|
// fmt.Println("Output:", output_str)
|
|
|
|
|
|
return output_str, nil |
|
|
return output_str, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func replyToAction(channelName string, message string, client *slack.Client) error { |
|
|
func replyToAction(channelName string, message string, client *slack.Client) error { |
|
|
//fmt.Println("replyToAction channel:", channelName, "Message:", message)
|
|
|
|
|
|
attachment := slack.Attachment{} |
|
|
attachment := slack.Attachment{} |
|
|
attachment.Text = message |
|
|
attachment.Text = message |
|
|
attachment.Color = "#4af030" |
|
|
attachment.Color = "#4af030" |
|
|
_, _, err := client.PostMessage(channelName, slack.MsgOptionAttachments(attachment)) |
|
|
_, _, err := client.PostMessage(channelName, slack.MsgOptionAttachments(attachment)) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
//fmt.Println("failed to post message:", err)
|
|
|
log.Println("failed to post message:", err) |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
@ -213,7 +200,6 @@ func getAttachmentButtons() []slack.AttachmentAction{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func handleAppMessagedEvent(event *slackevents.MessageEvent, client *slack.Client) error { |
|
|
func handleAppMessagedEvent(event *slackevents.MessageEvent, client *slack.Client) error { |
|
|
//fmt.Println("handleAppMessagedEvent event:", event, "BotID:", event.BotID)
|
|
|
|
|
|
if event.BotID != "" { |
|
|
if event.BotID != "" { |
|
|
// We're not interested in messages from ourselves or other bots
|
|
|
// We're not interested in messages from ourselves or other bots
|
|
|
return nil |
|
|
return nil |
|
|
@ -239,8 +225,6 @@ func handleAppMessagedEvent(event *slackevents.MessageEvent, client *slack.Clien |
|
|
|
|
|
|
|
|
// handleAppMentionEvent is used to take care of the AppMentionEvent when the bot is mentioned
|
|
|
// handleAppMentionEvent is used to take care of the AppMentionEvent when the bot is mentioned
|
|
|
func handleAppMentionEvent(event *slackevents.AppMentionEvent, client *slack.Client) error { |
|
|
func handleAppMentionEvent(event *slackevents.AppMentionEvent, client *slack.Client) error { |
|
|
// fmt.Println("handleAppMentionEvent event:", event)
|
|
|
|
|
|
|
|
|
|
|
|
var err error |
|
|
var err error |
|
|
// Create the attachment and assigned based on the message
|
|
|
// Create the attachment and assigned based on the message
|
|
|
attachment := slack.Attachment{} |
|
|
attachment := slack.Attachment{} |
|
|
@ -251,7 +235,6 @@ func handleAppMentionEvent(event *slackevents.AppMentionEvent, client *slack.Cli |
|
|
attachment.Pretext = fmt.Sprintf("Como te puedo ayudar?") |
|
|
attachment.Pretext = fmt.Sprintf("Como te puedo ayudar?") |
|
|
attachment.Color = "#3d3d3d" |
|
|
attachment.Color = "#3d3d3d" |
|
|
actions := getAttachmentButtons() |
|
|
actions := getAttachmentButtons() |
|
|
//fmt.Println(actions)
|
|
|
|
|
|
attachment.Actions = actions |
|
|
attachment.Actions = actions |
|
|
|
|
|
|
|
|
// Send the message to the channel
|
|
|
// Send the message to the channel
|
|
|
|