MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / NotifyUser

Function NotifyUser

service/user_notify.go:19–56  ·  view source on GitHub ↗
(userId int, userEmail string, userSetting dto.UserSetting, data dto.Notify)

Source from the content-addressed store, hash-verified

17}
18
19func NotifyUser(userId int, userEmail string, userSetting dto.UserSetting, data dto.Notify) error {
20 notifyType := userSetting.NotifyType
21 if notifyType == "" {
22 notifyType = dto.NotifyTypeEmail
23 }
24
25 // Check notification limit
26 canSend, err := CheckNotificationLimit(userId, data.Type)
27 if err != nil {
28 common.SysError(fmt.Sprintf("failed to check notification limit: %s", err.Error()))
29 return err
30 }
31 if !canSend {
32 return fmt.Errorf("notification limit exceeded for user %d with type %s", userId, notifyType)
33 }
34
35 switch notifyType {
36 case dto.NotifyTypeEmail:
37 // check setting email
38 userEmail = userSetting.NotificationEmail
39 if userEmail == "" {
40 common.SysLog(fmt.Sprintf("user %d has no email, skip sending email", userId))
41 return nil
42 }
43 return sendEmailNotify(userEmail, data)
44 case dto.NotifyTypeWebhook:
45 webhookURLStr := userSetting.WebhookUrl
46 if webhookURLStr == "" {
47 common.SysError(fmt.Sprintf("user %d has no webhook url, skip sending webhook", userId))
48 return nil
49 }
50
51 // 获取 webhook secret
52 webhookSecret := userSetting.WebhookSecret
53 return SendWebhookNotify(webhookURLStr, webhookSecret, data)
54 }
55 return nil
56}
57
58func sendEmailNotify(userEmail string, data dto.Notify) error {
59 // make email content

Callers 2

NotifyRootUserFunction · 0.85
checkAndSendQuotaNotifyFunction · 0.85

Calls 6

SysErrorFunction · 0.92
SysLogFunction · 0.92
CheckNotificationLimitFunction · 0.85
sendEmailNotifyFunction · 0.85
SendWebhookNotifyFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected