func main() { bot := slackbot.New(os.Getenv("SLACK_TOKEN")) toMe := bot.Messages(slackbot.DirectMessage, slackbot.DirectMention).Subrouter() toMe.Hear("(?i)(hi|hello).*").MessageHandler(HelloHandler) bot.Run() }
func main() { bot := slackbot.New(os.Getenv("SLACK_TOKEN")) toMe := bot.Messages(slackbot.DirectMessage, slackbot.DirectMention).Preprocess(WitPreprocess).Subrouter() toMe.AddMatcher(&IntentMatcher{intent: "hello"}).MessageHandler(HelloHandler) toMe.AddMatcher(&IntentMatcher{intent: "how_are_you"}).MessageHandler(HowAreYouHandler) toMe.MessageHandler(ConfusedHandler) bot.Run() }
func main() { bot := slackbot.New(os.Getenv("SLACK_TOKEN")) toMe := bot.Messages(slackbot.DirectMessage, slackbot.DirectMention).Subrouter() toMe.Hear("(?i)(hi|hello).*").MessageHandler(HelloHandler) bot.Hear("(?i)how are you(.*)").MessageHandler(HowAreYouHandler) bot.Hear("(?)attachment").MessageHandler(AttachmentsHandler) bot.Run() }
func main() { bot := slackbot.New(os.Getenv("SLACK_TOKEN")) toMe := bot.Messages(slackbot.DirectMessage, slackbot.DirectMention).Subrouter() hi := "hi|hello|bot hi|bot hello" toMe.Hear(hi).MessageHandler(HelloHandler) bot.Hear(hi).MessageHandler(HelloHandler) bot.Hear("help|bot help").MessageHandler(HelpHandler) bot.Hear("attachment|bot attachment").MessageHandler(AttachmentsHandler) bot.Hear(`<@([a-zA-z0-9]+)?>`).MessageHandler(MentionHandler) bot.Hear("(bot ).*").MessageHandler(CatchAllHandler) bot.Run() }
func Listen() { bot := slackbot.New(os.Getenv("SLACK_API_TOKEN")) bot.Hear("server (.*)").MessageHandler(RespondRequestHandler) bot.Run() }
func ListenForWeather() { bot := slackbot.New(os.Getenv("SLACK_API_TOKEN")) bot.Hear("(?i)weather (.*)").MessageHandler(WeatherHandler) bot.Run() }
func main() { bot := slackbot.New(os.Getenv("SLACK_TOKEN")) // do something with bot! }
func main() { cfg := config.GetConfig() // Add config to context globalContext = config.AddConfigToContext(globalContext, cfg) sfOppEventService, err := services.NewSalesforceOpportunityEventService(globalContext, cfg.GJSONPath, cfg.GProjectID, cfg.GPSNamespace) if err != nil { logger.Fatalf("Error createing sfOppEventService %s", err.Error()) } bot := slackbot.New(os.Getenv("SLACK_TOKEN")) // poll Pub Sub for messages go func() { for { if events, err := sfOppEventService.WaitForEvents(globalContext); err != nil { logger.Fatal(err.Error()) } else if events == nil || len(events) == 0 { logger.Info("sfOppEventService.WaitForEvents timed out, reinitiating") } else { Loop: for _, event := range events { logger.Infof("Received SalesforceOpportunity %#v", event) // acknowledge the event optimistically. If something causing problems systemwise, avoid backlogging // these notifications. Delivery is not necessarily guarenteed err = sfOppEventService.Ack(globalContext, event.AckID) if err != nil { logger.Errorf("Failed to ack receipt of SalesforceOpportunity message ID=%s, ackID=%s", event.MsgID, event.AckID) break Loop } evtData := event.Data switch evt := evtData.(type) { case *services.SalesforceOpportunity: OpportunityHandler(globalContext, bot, evtData.(*services.SalesforceOpportunity)) case *services.SalesforceLead: LeadHandler(globalContext, bot, evtData.(*services.SalesforceLead)) default: fmt.Printf("\n\nUnknown type from SalesforceEvent: %s", evt) } } } } }() // login to salesforce sfSession := salesforce.NewOAuth( cfg.SFClientID, cfg.SFClientSecret, cfg.SFUsername, cfg.SFPassword, cfg.SFSecurityToken, ) if err := sfSession.Login(); err != nil { logger.WithField("error", err).Fatalf("Problem logging into Salesforce! %s", err.Error()) } token, _ := sfSession.Token() logger.Info(fmt.Sprintf("Got Salesforce token %s", token)) globalContext = salesforce.AddOauthToContext(globalContext, sfSession) toMe := bot.Messages(slackbot.DirectMessage, slackbot.DirectMention).Subrouter() bot.Observe("channel_joined").EventHandler(JoinChannelHandler) toMe.Hear("set sales (.*)").MessageHandler(MapChannelHandler(SalesKey)) toMe.Hear("set finance (.*)").MessageHandler(MapChannelHandler(FinanceKey)) toMe.Hear("set ops (.*)").MessageHandler(MapChannelHandler(OpsKey)) toMe.Hear("mine").MessageHandler(ClaimHandler) bot.Hear("(?i)(add note|create note|put note|note).*").MessageHandler(SFNoteHandler) hi := "hi|hello|bot hi|bot hello" toMe.Hear(hi).MessageHandler(HelloHandler) bot.Hear("help|bot help").MessageHandler(HelpHandler) //bot.Hear("<@([a-zA-z0-9]+)?>").MessageHandler(ClaimHandler) bot.Hear("(bot ).*").MessageHandler(CatchAllHandler) bot.Run() }