|
|
@ -64,16 +64,9 @@ func Start() { |
|
|
//fmt.Println("Value:", action.Value)
|
|
|
//fmt.Println("Value:", action.Value)
|
|
|
var output string |
|
|
var output string |
|
|
var err error |
|
|
var err error |
|
|
switch action.Value { |
|
|
output, err = executeAction(action.Value) |
|
|
case "poweron": |
|
|
|
|
|
// fmt.Println("Encender!")
|
|
|
|
|
|
output, err = executeAction(action.Value) |
|
|
|
|
|
case "poweroff": |
|
|
|
|
|
// fmt.Println("Apagar!")
|
|
|
|
|
|
output, err = executeAction(action.Value) |
|
|
|
|
|
} |
|
|
|
|
|
if err == nil { |
|
|
if err == nil { |
|
|
finalMessage := fmt.Sprintf("Chi chi chi chi amo! Output: %s", output) |
|
|
finalMessage := fmt.Sprintf("Chi chi chi chi amo!\n*Output*\n```\n%s\n```", output) |
|
|
replyToAction(callback.Channel.ID, finalMessage, client) |
|
|
replyToAction(callback.Channel.ID, finalMessage, client) |
|
|
} |
|
|
} |
|
|
case slack.InteractionTypeMessageAction: |
|
|
case slack.InteractionTypeMessageAction: |
|
|
@ -145,10 +138,11 @@ 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 |
|
|
switch actionName { |
|
|
for _, action := range config.Config.Actions { |
|
|
case "poweron": |
|
|
if action.Name == actionName { |
|
|
cmd := exec.Command("/bin/bash", os.Getenv("POWERON_SCRIPT_PATH")) |
|
|
cmd := exec.Command("/bin/bash", action.Path) |
|
|
output, err := cmd.Output() |
|
|
output, err := cmd.Output() |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
@ -156,20 +150,8 @@ func executeAction(actionName string) (string, error) { |
|
|
return "", err |
|
|
return "", err |
|
|
} |
|
|
} |
|
|
output_str = string(output) |
|
|
output_str = string(output) |
|
|
//fmt.Println("output:", output_str)
|
|
|
} |
|
|
// return output
|
|
|
|
|
|
case "poweroff": |
|
|
|
|
|
cmd := exec.Command("/bin/bash", os.Getenv("POWEROFF_SCRIPT_PATH")) |
|
|
|
|
|
output, err := cmd.Output() |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
fmt.Printf("error %s", err) |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
output_str = string(output) |
|
|
|
|
|
//fmt.Println("output:", output_str)
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return output_str, nil |
|
|
return output_str, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -186,6 +168,19 @@ func replyToAction(channelName string, message string, client *slack.Client) err |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getAttachmentButtons() []slack.AttachmentAction{ |
|
|
|
|
|
var actions []slack.AttachmentAction |
|
|
|
|
|
for _, action := range config.Config.Actions { |
|
|
|
|
|
slackAction := slack.AttachmentAction{} |
|
|
|
|
|
slackAction.Name = action.Name |
|
|
|
|
|
slackAction.Value = action.Name |
|
|
|
|
|
slackAction.Text = action.DisplayName |
|
|
|
|
|
slackAction.Type = "button" |
|
|
|
|
|
actions=append(actions, slackAction) |
|
|
|
|
|
} |
|
|
|
|
|
return actions |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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)
|
|
|
//fmt.Println("handleAppMessagedEvent event:", event, "BotID:", event.BotID)
|
|
|
if event.BotID != "" { |
|
|
if event.BotID != "" { |
|
|
@ -199,20 +194,7 @@ func handleAppMessagedEvent(event *slackevents.MessageEvent, client *slack.Clien |
|
|
attachment.Text = "Por el momento esto es lo que se hacer" |
|
|
attachment.Text = "Por el momento esto es lo que se hacer" |
|
|
attachment.Pretext = fmt.Sprintf("Como te puedo ayudar?") |
|
|
attachment.Pretext = fmt.Sprintf("Como te puedo ayudar?") |
|
|
attachment.Color = "#3d3d3d" |
|
|
attachment.Color = "#3d3d3d" |
|
|
powerOnAction := slack.AttachmentAction{} |
|
|
actions := getAttachmentButtons() |
|
|
powerOnAction.Name = "poweron" |
|
|
|
|
|
powerOnAction.Text = "Encender" |
|
|
|
|
|
powerOnAction.Value = "poweron" |
|
|
|
|
|
powerOnAction.Type = "button" |
|
|
|
|
|
|
|
|
|
|
|
powerOffAction := slack.AttachmentAction{} |
|
|
|
|
|
powerOffAction.Name = "poweroff" |
|
|
|
|
|
powerOffAction.Text = "Apagar" |
|
|
|
|
|
powerOffAction.Value = "poweroff" |
|
|
|
|
|
powerOffAction.Type = "button" |
|
|
|
|
|
powerOffAction.Style = "danger" |
|
|
|
|
|
|
|
|
|
|
|
actions := []slack.AttachmentAction{powerOnAction, powerOffAction} |
|
|
|
|
|
attachment.Actions = actions |
|
|
attachment.Actions = actions |
|
|
|
|
|
|
|
|
// Send the message to the channel
|
|
|
// Send the message to the channel
|
|
|
@ -237,20 +219,7 @@ func handleAppMentionEvent(event *slackevents.AppMentionEvent, client *slack.Cli |
|
|
attachment.Text = "Por el momento esto es lo que se hacer" |
|
|
attachment.Text = "Por el momento esto es lo que se hacer" |
|
|
attachment.Pretext = fmt.Sprintf("Como te puedo ayudar?") |
|
|
attachment.Pretext = fmt.Sprintf("Como te puedo ayudar?") |
|
|
attachment.Color = "#3d3d3d" |
|
|
attachment.Color = "#3d3d3d" |
|
|
powerOnAction := slack.AttachmentAction{} |
|
|
actions := getAttachmentButtons() |
|
|
powerOnAction.Name = "poweron" |
|
|
|
|
|
powerOnAction.Text = "Encender" |
|
|
|
|
|
powerOnAction.Value = "poweron" |
|
|
|
|
|
powerOnAction.Type = "button" |
|
|
|
|
|
|
|
|
|
|
|
powerOffAction := slack.AttachmentAction{} |
|
|
|
|
|
powerOffAction.Name = "poweroff" |
|
|
|
|
|
powerOffAction.Text = "Apagar" |
|
|
|
|
|
powerOffAction.Value = "poweroff" |
|
|
|
|
|
powerOffAction.Type = "button" |
|
|
|
|
|
powerOffAction.Style = "danger" |
|
|
|
|
|
|
|
|
|
|
|
actions := []slack.AttachmentAction{powerOnAction, powerOffAction} |
|
|
|
|
|
//fmt.Println(actions)
|
|
|
//fmt.Println(actions)
|
|
|
attachment.Actions = actions |
|
|
attachment.Actions = actions |
|
|
|
|
|
|
|
|
|