Example #1
0
func main() {
	api := slack.New("YOUR_TOKEN_HERE")
	params := slack.PostMessageParameters{}
	attachment := slack.Attachment{
		Pretext: "some pretext",
		Text:    "some text",
		// Uncomment the following part to send a field too
		/*
			Fields: []slack.AttachmentField{
				slack.AttachmentField{
					Title: "a",
					Value: "no",
				},
			},
		*/
	}
	params.Attachments = []slack.Attachment{attachment}
	channelId, timestamp, err := api.PostMessage("CHANNEL_ID", "Some text", params)
	if err != nil {
		fmt.Printf("%s\n", err)
		return
	}
	fmt.Printf("Message successfully sent to channel %s at %s", channelId, timestamp)
}
Example #2
0
func (self *Standup) Run() {
	self.userIds = make([]string, 0, len(self.Channel.Members))

	for _, userId := range self.Channel.Members {
		if userId != self.client.UserId && self.userManager.StartStandup(self, userId) {
			self.userIds = append(self.userIds, userId)
		}
	}

	go self.startTheClock()

	_ = <-self.finishedChan
	self.Finished = true
	DebugLog.Print("sending summary...")

	var msg bytes.Buffer

	msg.WriteString("<!here>: *BARKBARKBARK Stand-up done!*\nQuestions were:\n")
	for _, q := range self.Questions {
		msg.WriteString("• ")
		msg.WriteString(q)
		msg.WriteString("\n")
	}
	msg.WriteString("\n")

	for user, anyReply := range self.userReplies {
		userName := fmt.Sprintf("<@%s|%s>", user.Info.Id, user.Info.Name)
		switch reply := anyReply.(type) {
		case userAnswersReply:
			msg.WriteString(userName)
			msg.WriteString(" answered:\n")
			for _, a := range reply {
				if a == "" {
					msg.WriteString("but didn't respond to the rest.\n")
					break
				}
				msg.WriteString("• ")
				msg.WriteString(a)
				msg.WriteString("\n")
			}
		case userAbsentReply:
			msg.WriteString(userName)
			msg.WriteString(" never replied to me :disappointed:")
		case userSkippedReply:
			msg.WriteString(userName)
			msg.WriteString(" skipped this stand-up.")
		case userErrorReply:
			msg.WriteString("There was an error when trying to chat with ")
			msg.WriteString(userName)
		default:
			msg.WriteString("I don't know what ")
			msg.WriteString(userName)
			msg.WriteString(" did. It is a mystery to me. :no_mouth:")
		}
		msg.WriteString("\n")
	}

	var params slack.PostMessageParameters
	params = DefaultMessageParameters
	params.Parse = "none"
	params.LinkNames = 0
	params.EscapeText = false

	_, _, err := self.client.PostMessage(self.Channel.Id, msg.String(), params)
	if err == nil {
		DebugLog.Print("summary sent")
	} else {
		DebugLog.Printf("error posting summary: %s", err.Error())
	}

	self.reportedWaitGroup.Done()
}