Skip to content

Instantly share code, notes, and snippets.

@gnyman
Last active October 15, 2020 12:46
Embed
What would you like to do?
minmal slack bot which adds emoji's to messages that matches
package main
import (
"strings"
"github.com/shomali11/slacker"
"github.com/slack-go/slack"
)
func main() {
bot := slacker.NewClient("xoxb-YOUR-API-KEY")
rtm := bot.RTM()
go rtm.ManageConnection()
for msg := range rtm.IncomingEvents {
switch ev := msg.Data.(type) {
case *slack.MessageEvent:
for _, att := range ev.Msg.Attachments {
if strings.Contains(att.Pretext, "was added as a new device.") {
t := slack.NewRefToMessage(ev.Msg.Channel, ev.Msg.Timestamp)
rtm.AddReaction("lock_with_ink_pen", t)
}
}
if strings.Contains(ev.Msg.Text, "was added as a new device.") {
t := slack.NewRefToMessage(ev.Msg.Channel, ev.Msg.Timestamp)
rtm.AddReaction("lock_with_ink_pen", t)
}
default:
// Ignore other events..
//fmt.Printf("Unexpected: %v\n", msg.Data)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment