Last active
October 15, 2020 12:46
-
-
Save gnyman/888b8e73fe674eee3fc7c7d772ddfa93 to your computer and use it in GitHub Desktop.
minmal slack bot which adds emoji's to messages that matches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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