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 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)
		}
	}
}
Exemplo n.º 3
0
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)
		}
	}
}
Exemplo n.º 4
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)
	}
}