예제 #1
0
func AssignNewLeadOwner(ctx context.Context, slackUserName string) error {
	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)

	// TODO: replace this with search into Salesforce with user by name
	var newOwner salesforce.Owner
	switch slackUserName {
	case "tracey.zimmerman":
		newOwner = salesforce.Owner{OwnerID: "005F0000003nFZ"}
	case "curtis.allen":
		newOwner = salesforce.Owner{OwnerID: "005c0000002Z6ta"}
	case "U03DANV0Q": // randall
		newOwner = salesforce.Owner{OwnerID: "005c0000002Z6tb"}
	case "alexander.shumski":
		newOwner = salesforce.Owner{OwnerID: "005F0000005QGer"}
	default:
		logger.Errorf("Unmapped Slack Username: %s", slackUserName)
		// return errors.New("I couldn't find username mapped to Salesforce owner id. :confounded:")
		newOwner = salesforce.Owner{OwnerID: "005F0000003nFZ"} // default to Tracey
	}

	leadResponse, err := sf.AssignLeadOwner(globalContext, lastNewLead.Id, newOwner)
	if err != nil {
		logger.WithError(err).Error("Unable to update lead")
		// return errors.New("I failed to assign new owner to lead in Salesforce. :sob:")
		return nil
	} else {
		fmt.Printf("\n\nlead from SF:\n%#v\n", leadResponse)
		return nil
	}
}