I am trying to use the Slack API to send notifications when one of my company's Loan Specialists or Risk Analysts are assigned to a casefile.
Here is the Update function that sends Updates to a casefile to our database, which is where I call the slack notification functions I mention above.
func (r *Routes) UpdateCasefile(c echo.Context) error {
var ur update.UpdateRequest
err := c.Bind(&ur)
if err != nil {
return handleErr(err, "Error binding JSONUpdateRequest")
}
if err := ur.ToGorm(r.db, &casefile.Casefile{}).Error; err != nil {
return handleErr(err, "Error updating Casefile")
}
var updated casefile.Casefile
if err := r.db.Where("id = ?", ur.EntityID).First(&updated).Error;
err != nil {
return handleErr(err, "Error recalling updated Casefile")
}
cf := &casefile.Casefile{
ID: updated.ID,
Name: updated.Name,
LoanAmount: updated.LoanAmount,
AssignedLoanSpecialist: updated.AssignedLoanSpecialist,
AssignedRiskAnalyst: updated.AssignedRiskAnalyst,
Business: updated.Business,
}
if ur.Updates["assigned_risk_analyst"] != nil {
NotifyRiskAnalyst(cf)
}
if ur.Updates["assigned_loan_specialist"] != nil {
NotifyLoanSpecialist(cf)
}
go func() {
events.Bus.Events <- &events.EventMessage{
EventType: events.EventActivity,
Payload: &casefile.Activity{
CasefileID: ur.EntityID,
Type: "UPDATE",
User: auth.GetEmail(c),
Message: ur.FormatUpdateMessage(),
},
}
}()
return c.JSON(http.StatusOK, updated)
}
Here are the functions that are supposed to send notifications via one of our slack channels when a Loan Specialist or Risk Analyst are assigned to a casefile.
func NotifyRiskAnalyst(cf *casefile.Casefile) {
title := fmt.Sprintf("Casefile <https://COMPANYWEBSITE/case/%s|%s>, assigned to <@%s> at %s", cf.ID, cf.Name, cf.AssignedRiskAnalyst, cf.CreatedAt.Format("2006-01-02 15:04 -0700 MST"))
err := common.NewSlackNotifier("#test").Notify(common.SlackMessage{
Attachments: []common.SlackAttachment{
{
Color: "#008BF8",
Fallback: title,
Pretext: title,
Fields: []common.SlackField{
{
Title: cf.Name,
Value: fmt.Sprintf("https:/COMPANYWEBSITE/case/%s", cf.ID),
},
},
},
}})
if err != nil {
logrus.WithError(err).Error("Error sending Slack message")
}
}
func NotifyLoanSpecialist(cf *casefile.Casefile) {
title := fmt.Sprintf("Casefile <https://COMPANYWEBSITE/case/%s|%s>, assigned to <@%s> at %s", cf.ID, cf.Name, cf.AssignedLoanSpecialist, cf.CreatedAt.Format("2006-01-02 15:04 -0700 MST"))
err := common.NewSlackNotifier("#test").Notify(common.SlackMessage{
Attachments: []common.SlackAttachment{
{
Color: "#008BF8",
Fallback: title,
Pretext: title,
Fields: []common.SlackField{
{
Title: cf.Name,
Value: fmt.Sprintf("https://COMPANYWEBSITE.io/case/%s", cf.ID),
},
},
},
}})
if err != nil {
logrus.WithError(err).Error("Error sending Slack message")
}
}
I'm not getting any errors in my terminal, but the slack notifications aren't sending. I'm not entirely sure where I'm going wrong, but any help will be much appreciated!