我正在尝试创建Slack通知,以发送通知结构中可用的数据,即通知结构将是数据源。我很难将通知结构正确插入附件。请参阅下面的代码。有人知道我能做什么吗?非常感谢您的帮助。
我的预期结果(即Slack通知)将如下所示:
UserID: 99
Type: Slack or Email
Level: Warning
Received: time.Time (now)
Originator: Originator Name
Immediate: false
Data: interface{}
Recipients: {email@gmail.com; Recipient Name}
Customer: {1, Customer Name}
package main
import (
"fmt"
"time"
"github.com/parnurzeal/gorequest"
)
//NotificationType is enum of available notification types
type NotificationType string
const (
//Email should be sent via email protocols
Email NotificationType = "email"
)
//NotificationLevel is enum of notification levels
type NotificationLevel string
//Notification levels represent the importance of the notification
const (
Error NotificationLevel = "error"
Warning NotificationLevel = "warning"
Info NotificationLevel = "info"
)
//Recipient represents the recipient of the notification
type Recipient struct {
Email string
Name string
}
//Customer represents the customer the notification is about
type Customer struct {
ID int
Name string
}
//Notification is struct containing all information about notification
//This will be used as Datasource in the Attachment
type Notification struct {
UserID int
Type NotificationType
Level NotificationLevel
Received time.Time
Originator string
Immediate bool
Data interface{}
// following field are populated by notification service itself
Recipients []*Recipient
Customer *Customer
}
//Field defines fields to be used in the notification
type Field struct {
Title string
Value []*Notification
}
// Attachment holds data used in payload
type Attachment struct {
Text *string //`json:"text"`
Fields []*Field //`json:"fields"`
}
//Payload defines the notification structure
type Payload struct {
Text string `json:"text,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
}
慕村9548890
相关分类