github.com/matthieudolci/hatcher@v0.2.8/help/help.go (about)

     1  package help
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	log "github.com/Sirupsen/logrus"
     8  	"github.com/matthieudolci/hatcher/common"
     9  	"github.com/slack-go/slack"
    10  )
    11  
    12  func AskHelp(s *common.Slack, ev *slack.MessageEvent) error {
    13  
    14  	text := ev.Text
    15  	text = strings.TrimSpace(text)
    16  	text = strings.ToLower(text)
    17  
    18  	acceptedHelp := map[string]bool{
    19  		"help": true,
    20  	}
    21  
    22  	if acceptedHelp[text] {
    23  		attachment := slack.Attachment{
    24  			Pretext: "Welcome to the help center",
    25  			Color:   "#87cefa",
    26  			Text:    "Here are the different commands you can pass to Hatcher:",
    27  			Fields: []slack.AttachmentField{
    28  				{
    29  					Title: "hello",
    30  					Value: "The command `hello` will start the setup of your user with Hatcher\nThis command needs to be passed before any other ones",
    31  				},
    32  				{
    33  					Title: "standup",
    34  					Value: "The command `standup` starts a new standup in case you missed the scheduled one\nThis command needs to be pass in a direct message to Hatcher",
    35  				},
    36  				{
    37  					Title: "remove",
    38  					Value: "The command `remove` removes your user from Hatcher\nThis command needs to be pass in a direct message to Hatcher",
    39  				},
    40  			},
    41  			CallbackID: fmt.Sprintf("askHelp_%s", ev.User),
    42  		}
    43  
    44  		params := slack.MsgOptionAttachments(attachment)
    45  
    46  		_, _, err := s.Client.PostMessage(ev.Channel, params)
    47  		if err != nil {
    48  			log.WithError(err).Error("Failed to post help")
    49  		}
    50  		log.WithFields(log.Fields{
    51  			"userid": ev.User,
    52  		}).Info("Help message posted")
    53  	}
    54  	return nil
    55  }