mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-26 21:22:16 +08:00 
			
		
		
		
	* pb * fix: Modifying other fields while setting IsPrivateChat does not take effect * fix: quote message error revoke * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * upgrading pkg tools * fix * fix * optimize log output * feat: support GetLastMessage * feat: support GetLastMessage * feat: s3 switch * feat: s3 switch * fix: GetUsersOnline * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: seq conversion failed without exiting * fix: DeleteDoc crash * fix: fill send time * fix: fill send time * fix: crash caused by withdrawing messages from users who have left the group * fix: user msg timestamp * seq read config * seq read config * fix: the source message of the reference is withdrawn, and the referenced message is deleted * feat: optimize the default notification.yml * fix: shouldPushOffline * fix: the sorting is wrong after canceling the administrator in group settings * feat: Sending messages supports returning fields modified by webhook * feat: Sending messages supports returning fields modified by webhook * feat: Sending messages supports returning fields modified by webhook
		
			
				
	
	
		
			66 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package main
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	"fmt"
 | |
| 	"io"
 | |
| 	"net/http"
 | |
| 	"strings"
 | |
| 
 | |
| 	"github.com/gin-gonic/gin"
 | |
| 	cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
 | |
| 	"github.com/openimsdk/protocol/constant"
 | |
| )
 | |
| 
 | |
| func main() {
 | |
| 	g := gin.Default()
 | |
| 	g.POST("/callbackExample/callbackBeforeMsgModifyCommand", toGin(handlerMsg))
 | |
| 	if err := g.Run(":10006"); err != nil {
 | |
| 		panic(err)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func toGin[R any](fn func(c *gin.Context, req *R)) gin.HandlerFunc {
 | |
| 	return func(c *gin.Context) {
 | |
| 		body, err := io.ReadAll(c.Request.Body)
 | |
| 		if err != nil {
 | |
| 			c.String(http.StatusInternalServerError, err.Error())
 | |
| 			return
 | |
| 		}
 | |
| 		fmt.Printf("HTTP %s %s %s\n", c.Request.Method, c.Request.URL, body)
 | |
| 		var req R
 | |
| 		if err := json.Unmarshal(body, &req); err != nil {
 | |
| 			c.String(http.StatusInternalServerError, err.Error())
 | |
| 			return
 | |
| 		}
 | |
| 		fn(c, &req)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func handlerMsg(c *gin.Context, req *cbapi.CallbackMsgModifyCommandReq) {
 | |
| 	var resp cbapi.CallbackMsgModifyCommandResp
 | |
| 	if req.ContentType != constant.Text {
 | |
| 		c.JSON(http.StatusOK, &resp)
 | |
| 		return
 | |
| 	}
 | |
| 	var textElem struct {
 | |
| 		Content string `json:"content"`
 | |
| 	}
 | |
| 	if err := json.Unmarshal([]byte(req.Content), &textElem); err != nil {
 | |
| 		c.String(http.StatusInternalServerError, err.Error())
 | |
| 		return
 | |
| 	}
 | |
| 	const word = "xxx"
 | |
| 	if strings.Contains(textElem.Content, word) {
 | |
| 		textElem.Content = strings.ReplaceAll(textElem.Content, word, strings.Repeat("*", len(word)))
 | |
| 		content, err := json.Marshal(&textElem)
 | |
| 		if err != nil {
 | |
| 			c.String(http.StatusInternalServerError, err.Error())
 | |
| 			return
 | |
| 		}
 | |
| 		tmp := string(content)
 | |
| 		resp.Content = &tmp
 | |
| 	}
 | |
| 	c.JSON(http.StatusOK, &resp)
 | |
| }
 |