func LeadHandler(ctx context.Context, bot *slackbot.Bot, sfo *services.SalesforceLead) {
	// log := logger.WithField("method", "LeadHandler")
	//
	// sf := salesforce.Salesforce{}
	// cfg := config.GetConfigFromContext(globalContext)
	// log.Infof("config %v", cfg)
	// oauth := salesforce.GetOauthFromContext(globalContext)
	// log.Infof("oauth %v", oauth)
	// leadResponse, err := sf.GetLead(globalContext, sfo.Id)
	// if err != nil {
	// 	logger.WithError(err).Error("Unable to get lead")
	// } else {
	// 	fmt.Printf("\n\nlead from SF:\n%#v\n", leadResponse)
	// }

	logger.Infof("LeadHandler for %s", sfo.Company)
	// channels, err := bot.Client.GetChannels(true)
	// if err != nil {
	// 	logger.Errorf("Couldn't get Channels from LeadHandler, err - %s", err)
	// 	return
	// }
	//
	// for _, channel := range channels {
	// 	if channel.IsMember {
	// 		evt := &slack.MessageEvent{}
	// 		evt.Channel = channel.ID
	// txt := fmt.Sprintf("Salesforce Opportunity just went into: %s", sfo.StageName)
	fields := []slack.AttachmentField{
		{Title: "Email", Value: sfo.Email, Short: true},
		{Title: "Phone", Value: sfo.Phone, Short: true},
	}

	ownedByTxt := ""
	if sfo.OwnerName != "" {
		ownedByTxt = fmt.Sprintf(", owned by: %s", sfo.OwnerName)
	}
	pretxt := fmt.Sprintf("Lead was %s%s", sfo.Op, ownedByTxt)
	if sfo.Op == "Created" {
		pretxt = ""
		channel_txt := "@channel Shotgun! :gun: A new lead is available!\nType \"<@" + bot.BotUserID() + "> mine\" to claim."
		bot.Reply(bot.Get(SalesKey), channel_txt, WithoutTyping)
		lastNewLead = sfo
	}
	attachment := slack.Attachment{
		Pretext:   pretxt,
		Title:     fmt.Sprintf("%s %s - %s", sfo.FirstName, sfo.LastName, sfo.Company),
		TitleLink: fmt.Sprintf("https://cs14.salesforce.com/%s", sfo.Id),
		// Text:      txt,
		// Fallback:  txt,
		Fields: fields,
		Color:  "#663399",
	}

	// supports multiple attachments
	attachments := []slack.Attachment{attachment}
	bot.ReplyWithAttachments(bot.Get(SalesKey), attachments, WithoutTyping)
	// 	}
	// }
}
示例#2
0
func HelloHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	rand.Seed(time.Now().UnixNano())
	msg := greetingPrefixes[rand.Intn(len(greetingPrefixes))] + " <@" + evt.User + ">!"
	bot.Reply(evt, msg, WithTyping)

	if slackbot.IsDirectMessage(evt) {
		dmMsg := "It's nice to talk to you directly."
		bot.Reply(evt, dmMsg, WithoutTyping)
	}
}
示例#3
0
func RespondRequestHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	// TODO: Respond to a `server <IP>` request
	fmt.Println("DEBUG: User sent: ", evt.Msg.Text)
	arrOfWords := strings.Fields(evt.Msg.Text)
	ip := arrOfWords[len(arrOfWords)-1]
	err := CheckServer(ip)
	if err == true {
		bot.Reply(evt, fmt.Sprintf("ONLINE"), slackbot.WithTyping)
	} else {
		bot.Reply(evt, fmt.Sprintf("OFFLINE"), slackbot.WithTyping)
	}
}
示例#4
0
func WeatherHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	parts := strings.Split(evt.Msg.Text, " ")
	if len(parts) != 2 {
		return
	}
	weather, err := GetWeather(parts[1])
	if err != nil {
		fmt.Println("Could not get weather:", err)
		return
	}

	description := ""
	if len(weather.Weather) > 0 {
		description = weather.Weather[0].Description
	}
	bot.Reply(evt, fmt.Sprintf("The current temperature for %s is %.0f degrees farenheight (%s)", weather.Name, weather.Main.Temp, description), slackbot.WithTyping)
}
func ClaimHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	if slackbot.IsMentioned(evt, bot.BotUserID()) {
		if strings.Contains(evt.Text, "mine") {
			if lastNewLead != nil {
				err := AssignNewLeadOwner(ctx, evt.User)
				if err != nil {
					bot.Reply(evt.Channel, err.Error(), WithoutTyping)
				} else {
					bot.Reply(evt.Channel, fmt.Sprintf("@%s staked their claim! :pick:", evt.User), WithoutTyping)
					bot.Reply(evt.Channel, fmt.Sprintf("*%s* is now in your hands, make the most it!\nRemember what our buddy Zig says:\n> _\"You were born to win, but to be a winner, you must plan to win, prepare to win, and expect to win.\"_", lastNewLead.FirstName), WithTyping)
				}
			} else {
				bot.Reply(evt.Channel, "I'm sorry, I don't know of any new leads you can claim. :disappointed:", WithTyping)
			}
		} else {
			bot.Reply(evt.Channel, "You really do care about me. :heart:", WithTyping)
		}
	}
}
func SFNoteHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	log := logger.WithField("method", "SFNoteHandler")

	noteText := evt.Msg.Text
	log.Infof("Creating note: %s", noteText)
	note := salesforce.Note{
		//TODO don't hardcode parent ID
		ParentID: "006c000000EMa77AAD",
		Title:    fmt.Sprintf("from @sfbot on behalf of %s", evt.User),
		Body:     noteText,
	}
	sf := salesforce.Salesforce{}
	cfg := config.GetConfigFromContext(globalContext)
	log.Infof("config %v", cfg)
	oauth := salesforce.GetOauthFromContext(globalContext)
	log.Infof("oauth %v", oauth)
	_, err := sf.CreateNote(globalContext, note)
	if err != nil {
		logger.WithError(err).Error("Unable to create note")
		bot.Reply(evt.Channel, "Error creating note in salesforce", WithTyping)
	}
	log.Info("Note created")
	bot.Reply(evt.Channel, "Note created. Thanks for making sure this project is setup for success, I’ll let you know when it closes so the team can get started :unicorn_face:", WithTyping)
}
示例#7
0
func HelloHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	bot.Reply(evt, "Oh hello!", slackbot.WithTyping)
}
示例#8
0
func ConfusedHandler(ctx context.Context, bot *slackbot.Bot, msg *slack.MessageEvent) {
	bot.Reply(msg, "I don't understand 😰", slackbot.WithTyping)
}
示例#9
0
func HowAreYouHandler(ctx context.Context, bot *slackbot.Bot, msg *slack.MessageEvent) {
	bot.Reply(msg, "A bit tired. You get it? A bit?", slackbot.WithTyping)
}
示例#10
0
func HelpHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	bot.Reply(evt, HelpText, WithTyping)
}
示例#11
0
func MentionHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	if slackbot.IsMentioned(evt, bot.BotUserID()) {
		bot.Reply(evt, "You really do care about me. :heart:", WithTyping)
	}
}
示例#12
0
func CatchAllHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	msg := fmt.Sprintf("I'm sorry, I don't know how to: `%s`.\n%s", evt.Text, HelpText)
	bot.Reply(evt, msg, WithTyping)
}
func JoinChannelHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.RTMEvent) {
	joinedEvent := evt.Data.(*slack.ChannelJoinedEvent)
	log := logger.WithField("method", "JoinChannelHandler")
	log.Infof("Event: %#v", joinedEvent)
	sales := bot.Get(SalesKey)
	finance := bot.Get(FinanceKey)
	ops := bot.Get(OpsKey)
	bot.Reply(joinedEvent.Channel.ID, "Hello", WithTyping)
	bot.Reply(joinedEvent.Channel.ID, "I'm your friendly neighborhood Salesforce bot!", WithTyping)

	if sales == "" || finance == "" || ops == "" {

		bot.Reply(joinedEvent.Channel.ID, "Please take a moment and setup your notification channel preferences", WithTyping)
		if sales == "" {
			bot.Reply(joinedEvent.Channel.ID, "say \"<@"+bot.BotUserID()+"> set sales #channel\"", WithTyping)
		} else {
			bot.Reply(joinedEvent.Channel.ID, "sales team messages go to <#"+sales+">", WithTyping)
		}

		if finance == "" {
			bot.Reply(joinedEvent.Channel.ID, "say \"<@"+bot.BotUserID()+"> set finance #channel\"", WithTyping)
		} else {
			bot.Reply(joinedEvent.Channel.ID, "finance team messages go to <#"+finance+">", WithTyping)
		}

		if ops == "" {
			bot.Reply(joinedEvent.Channel.ID, "say \"<@"+bot.BotUserID()+"> set ops #channel\"", WithTyping)
		} else {
			bot.Reply(joinedEvent.Channel.ID, "ops team messages go to <#"+ops+">", WithTyping)
		}
	}
}
func OpportunityHandler(ctx context.Context, bot *slackbot.Bot, sfo *services.SalesforceOpportunity) {
	logger.Infof("OpportunityHandler for %s", sfo.Name)
	// channels, err := bot.Client.GetChannels(true)
	// if err != nil {
	// 	logger.Errorf("Couldn't get Channels from OpportunityHandler, err - %s", err)
	// 	return
	// }

	// for _, channel := range channels {
	// 	if channel.IsMember {
	// 		evt := &slack.MessageEvent{}
	// evt.Channel = channel.ID

	if sfo.StageName == "Contracts in Legal" {
		winMsg := fmt.Sprintf("We are #winning! *%s* just got the %s - %s to legal!\n ... as Zig says, _there is no elevator to success_ - congrats on the good work!\nNow make sure to get that legal team whatever they need. :file_cabinet:",
			sfo.OwnerName,
			sfo.AccountName,
			sfo.Name,
		)
		bot.Reply(bot.Get(SalesKey), winMsg, WithTyping)

		// txt := fmt.Sprintf("Salesforce Opportunity just went into: %s", sfo.StageName)
		fields := []slack.AttachmentField{
			{Title: "Stage", Value: sfo.StageName, Short: true},
			{Title: "Total Hours", Value: strconv.Itoa(sfo.Hours), Short: true},
		}
		if sfo.Ampersand > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Ampersand", Value: strconv.Itoa(sfo.Ampersand), Short: true})
		}
		if sfo.ApplicationDesign > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Application Design", Value: strconv.Itoa(sfo.ApplicationDesign), Short: true})
		}
		if sfo.VisualDesign > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Visual Design", Value: strconv.Itoa(sfo.VisualDesign), Short: true})
		}
		if sfo.PMHours > 0 {
			fields = append(fields, slack.AttachmentField{Title: "PM Hours", Value: strconv.Itoa(sfo.PMHours), Short: true})
		}
		if sfo.RobotiOSHours > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Robot iOS", Value: strconv.Itoa(sfo.RobotiOSHours), Short: true})
		}
		if sfo.RobotAndroidHours > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Robot Android", Value: strconv.Itoa(sfo.RobotAndroidHours), Short: true})
		}
		if sfo.RobotServerHours > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Robot Server", Value: strconv.Itoa(sfo.RobotServerHours), Short: true})
		}
		if sfo.RobotsBA > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Robot BA", Value: strconv.Itoa(sfo.RobotsBA), Short: true})
		}
		if sfo.PencilsDesign > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Pencils Design", Value: strconv.Itoa(sfo.PencilsDesign), Short: true})
		}
		if sfo.PencilsUX > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Pencils UX", Value: strconv.Itoa(sfo.PencilsUX), Short: true})
		}
		if sfo.WebDevelopment > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Web Development", Value: strconv.Itoa(sfo.WebDevelopment), Short: true})
		}
		if sfo.RobotsSA > 0 {
			fields = append(fields, slack.AttachmentField{Title: "Robots SA", Value: strconv.Itoa(sfo.RobotsSA), Short: true})
		}
		if sfo.PMOProgramManager > 0 {
			fields = append(fields, slack.AttachmentField{Title: "PMO Program Manager", Value: strconv.Itoa(sfo.PMOProgramManager), Short: true})
		}

		attachment := slack.Attachment{
			Pretext:   ":speaking_head_in_silhouette: New work is on the way!",
			Title:     fmt.Sprintf("Opportunity - %s for %s", sfo.Name, sfo.AccountName),
			TitleLink: fmt.Sprintf("https://cs14.salesforce.com/%s", sfo.Id),
			// Text:      txt,
			// Fallback:  txt,
			Fields: fields,
			Color:  "#1798c1",
		}

		// supports multiple attachments
		attachments := []slack.Attachment{attachment}
		bot.ReplyWithAttachments(bot.Get(OpsKey), attachments, WithoutTyping)

		// TODO: Find actual mappings of categorized hours in Opportunity to slack users designated as leads for category
		// msgToLeads := ":speaking_head_in_silhouette: Calling all relevant talent leads: @mike.brevoort, @curtis.allen, @randall.barnhart\n" +
		// 	"Can you all talk to your guilds and assign team members to this project to fufill the projected hour estimates?"
		// bot.Reply(evt.Channel, msgToLeads, WithTyping)

		promptForNote := "Who on your team wants to work on it? Respond with your assignment by typing “add note talent type Talent Name”"
		bot.Reply(bot.Get(OpsKey), promptForNote, WithTyping)
	} else if sfo.StageName == "Closed Won" {
		// message finance
		finWonMsg := fmt.Sprintf("@channel :moneybag: %s just closed a deal from %s to do %s for $%.2f!\nPlease create a billing code in Harvest for #project-managers.",
			sfo.OwnerName,
			sfo.AccountName,
			sfo.Name,
			sfo.Revenue,
		)
		bot.Reply(bot.Get(FinanceKey), finWonMsg, WithTyping)

		// message sales
		salesWonMsg := fmt.Sprintf("%s just closed the %s %s deal!\n... as Sun Tzu says _“Victory is reserved for those who are willing to pay it’s price.”_\nThanks for that. :sunrise:",
			sfo.OwnerName,
			sfo.AccountName,
			sfo.Name,
		)
		bot.Reply(bot.Get(SalesKey), salesWonMsg, WithTyping)

		// message ops
		opsWonMsg := fmt.Sprintf("%s %s has closed!\nI have automatically created a channel called #%s-%s.\nSo let’s start talking about how to get this thing going! :horse_racing:",
			sfo.AccountName,
			sfo.Name,
			sfo.AccountName,
			sfo.Name,
		)
		bot.Reply(bot.Get(OpsKey), opsWonMsg, WithTyping)

	} else {
		oppLink := fmt.Sprintf("https://cs14.salesforce.com/%s", sfo.Id)
		oppUpdated := fmt.Sprintf("Opportunity - %s for %s updated, see: %s - Owner: %s", sfo.Name, sfo.AccountName, oppLink, sfo.OwnerName)
		bot.Reply(bot.Get(SalesKey), oppUpdated, WithTyping)
	}

	// 	}
	// }
}
func HelloHandler(ctx context.Context, bot *slackbot.Bot, msg *slack.MessageEvent) {
	bot.Reply(msg.Channel, "Oh hello!", slackbot.WithTyping)
}