Skip to content

Instantly share code, notes, and snippets.

@gnyman
Last active October 15, 2020 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnyman/888b8e73fe674eee3fc7c7d772ddfa93 to your computer and use it in GitHub Desktop.
Save gnyman/888b8e73fe674eee3fc7c7d772ddfa93 to your computer and use it in GitHub Desktop.
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