Exemplo n.º 1
0
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)
}
Exemplo n.º 2
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
	}
}