mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-04 11:22:17 +08:00
feat: add webhook example
This commit is contained in:
parent
98d3646167
commit
5c3b66aad6
@ -315,9 +315,9 @@ iosPush:
|
|||||||
# Timeout in seconds
|
# Timeout in seconds
|
||||||
# Whether to continue execution if callback fails
|
# Whether to continue execution if callback fails
|
||||||
callback:
|
callback:
|
||||||
url: ""
|
url: "http://127.0.0.1:10002/msg"
|
||||||
beforeSendSingleMsg:
|
beforeSendSingleMsg:
|
||||||
enable: ${CALLBACK_ENABLE}
|
enable: true
|
||||||
timeout: ${CALLBACK_TIMEOUT}
|
timeout: ${CALLBACK_TIMEOUT}
|
||||||
failedContinue: ${CALLBACK_FAILED_CONTINUE}
|
failedContinue: ${CALLBACK_FAILED_CONTINUE}
|
||||||
beforeUpdateUserInfoEx:
|
beforeUpdateUserInfoEx:
|
||||||
|
|||||||
@ -27,6 +27,8 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
@ -377,3 +379,65 @@ func (m *MessageApi) SearchMsg(c *gin.Context) {
|
|||||||
func (m *MessageApi) GetServerTime(c *gin.Context) {
|
func (m *MessageApi) GetServerTime(c *gin.Context) {
|
||||||
a2r.Call(msg.MsgClient.GetServerTime, m.Client, c)
|
a2r.Call(msg.MsgClient.GetServerTime, m.Client, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MessageApi) CallbackExample(c *gin.Context) {
|
||||||
|
// 1. 通过 url 获取具体信息
|
||||||
|
// 2. 返回继续向下执行的命令
|
||||||
|
// 3. 获取一个系统通知号
|
||||||
|
// 4. 构造一个发消息的结构体
|
||||||
|
// 5. 使用这个系统通知号发送消息
|
||||||
|
|
||||||
|
var req callbackstruct.CallbackBeforeSendSingleMsgReq
|
||||||
|
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
log.ZError(c, "CallbackExample BindJSON failed", err)
|
||||||
|
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.ZInfo(c, "CallbackExample", "req", req)
|
||||||
|
|
||||||
|
resp := &callbackstruct.CallbackBeforeSendSingleMsgResp{
|
||||||
|
CommonCallbackResp: callbackstruct.CommonCallbackResp{
|
||||||
|
ActionCode: 0,
|
||||||
|
ErrCode: 200,
|
||||||
|
ErrMsg: "success",
|
||||||
|
ErrDlt: "successful",
|
||||||
|
NextCode: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
apiresp.GinSuccess(c, resp)
|
||||||
|
|
||||||
|
user, err := m.userRpcClient.GetUserInfo(c, config.Config.IMAdmin.UserID[0])
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(c, "GetUserInfo failed", err)
|
||||||
|
apiresp.GinError(c, errs.ErrDatabase.WithDetail(err.Error()).Wrap())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
time := time.Now().Unix()
|
||||||
|
msgInfo := &sdkws.MsgData{
|
||||||
|
SendID: user.UserID,
|
||||||
|
RecvID: req.RecvID,
|
||||||
|
ClientMsgID: req.ClientMsgID,
|
||||||
|
ServerMsgID: req.ServerMsgID,
|
||||||
|
SenderPlatformID: req.SenderPlatformID,
|
||||||
|
SenderNickname: user.Nickname,
|
||||||
|
SenderFaceURL: user.UserID,
|
||||||
|
SessionType: req.SessionType,
|
||||||
|
MsgFrom: req.MsgFrom,
|
||||||
|
ContentType: req.ContentType,
|
||||||
|
Content: []byte(req.Content),
|
||||||
|
Seq: int64(req.Seq),
|
||||||
|
SendTime: time,
|
||||||
|
CreateTime: time,
|
||||||
|
Status: req.Status,
|
||||||
|
}
|
||||||
|
rsp, err := m.Message.Client.SendMsg(c, &msg.SendMsgReq{MsgData: msgInfo})
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(c, "SendMsg failed", err)
|
||||||
|
apiresp.GinError(c, errs.ErrDatabase.WithDetail(err.Error()).Wrap())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
apiresp.GinSuccess(c, rsp)
|
||||||
|
}
|
||||||
|
|||||||
@ -200,6 +200,8 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
|||||||
msgGroup.POST("/batch_send_msg", m.BatchSendMsg)
|
msgGroup.POST("/batch_send_msg", m.BatchSendMsg)
|
||||||
msgGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess)
|
msgGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess)
|
||||||
msgGroup.POST("/get_server_time", m.GetServerTime)
|
msgGroup.POST("/get_server_time", m.GetServerTime)
|
||||||
|
|
||||||
|
msgGroup.POST("/callbackBeforeSendSingleMsgCommand", m.CallbackExample)
|
||||||
}
|
}
|
||||||
// Conversation
|
// Conversation
|
||||||
conversationGroup := r.Group("/conversation", ParseToken)
|
conversationGroup := r.Group("/conversation", ParseToken)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user