Exemplo n.º 1
0
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)
	// 	}
	// }
}
Exemplo n.º 2
0
func AttachmentsHandler(ctx context.Context, bot *slackbot.Bot, evt *slack.MessageEvent) {
	txt := "Beep Beep Boop is a ridiculously simple hosting platform for your Slackbots."
	attachment := slack.Attachment{
		Pretext:   "We bring bots to life. :sunglasses: :thumbsup:",
		Title:     "Host, deploy and share your bot in seconds.",
		TitleLink: "https://beepboophq.com/",
		Text:      txt,
		Fallback:  txt,
		ImageURL:  "https://storage.googleapis.com/beepboophq/_assets/bot-1.22f6fb.png",
		Color:     "#7CD197",
	}

	// supports multiple attachments
	attachments := []slack.Attachment{attachment}
	bot.ReplyWithAttachments(evt, attachments, WithTyping)
}
Exemplo n.º 3
0
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)
	}

	// 	}
	// }
}