mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix: make old notify send SDK compatible (#7628)
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/notify"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/notify"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
@@ -30,20 +31,41 @@ func init() {
|
||||
TOPIC string `help:"Topic"`
|
||||
Priority string `help:"Priority"`
|
||||
MESSAGE string `help:"Message"`
|
||||
Oldsdk bool `help:"Old sdk"`
|
||||
}
|
||||
R(&NotificationCreateInput{}, "notify-send", "Send a notify message", func(s *mcclient.ClientSession, args *NotificationCreateInput) error {
|
||||
input := api.NotificationCreateInput{
|
||||
Receivers: args.Receivers,
|
||||
ContactType: args.ContactType,
|
||||
Topic: args.TOPIC,
|
||||
Priority: args.Priority,
|
||||
Message: args.MESSAGE,
|
||||
var (
|
||||
ret jsonutils.JSONObject
|
||||
err error
|
||||
)
|
||||
if args.Oldsdk {
|
||||
msg := notify.SNotifyMessage{
|
||||
Uid: args.Receivers,
|
||||
ContactType: notify.TNotifyChannel(args.ContactType),
|
||||
Topic: args.TOPIC,
|
||||
Priority: notify.TNotifyPriority(args.Priority),
|
||||
Msg: args.MESSAGE,
|
||||
Remark: "",
|
||||
Broadcast: false,
|
||||
}
|
||||
err = notify.Notifications.Send(s, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
input := api.NotificationCreateInput{
|
||||
Receivers: args.Receivers,
|
||||
ContactType: args.ContactType,
|
||||
Topic: args.TOPIC,
|
||||
Priority: args.Priority,
|
||||
Message: args.MESSAGE,
|
||||
}
|
||||
ret, err = modules.Notification.Create(s, jsonutils.Marshal(input))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
}
|
||||
ret, err := modules.Notification.Create(s, jsonutils.Marshal(input))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
type NotificationInput struct {
|
||||
|
||||
@@ -40,7 +40,7 @@ type SNotifyMessage struct {
|
||||
}
|
||||
|
||||
type SNotifyV2Message struct {
|
||||
ReceiverIds []string `json:"receiver_ids"`
|
||||
Receivers []string `json:"receivers"`
|
||||
ContactType string `json:"contact_type"`
|
||||
Topic string `json:"topic"`
|
||||
Priority string `json:"priority"`
|
||||
@@ -73,7 +73,7 @@ func (manager *NotificationManager) Send(s *mcclient.ClientSession, msg SNotifyM
|
||||
receiverIds = append(receiverIds, msg.Uid...)
|
||||
|
||||
v2msg := SNotifyV2Message{
|
||||
ReceiverIds: receiverIds,
|
||||
Receivers: receiverIds,
|
||||
ContactType: string(msg.ContactType),
|
||||
Topic: msg.Topic,
|
||||
Priority: string(msg.Priority),
|
||||
|
||||
Reference in New Issue
Block a user