feat(channels): add Shangwutong connector

This commit is contained in:
2026-08-03 10:13:40 +08:00
parent 96f5c796a6
commit 897b4e018f
126 changed files with 20207 additions and 272 deletions
@@ -5,9 +5,13 @@ import (
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/gochat/gochat/internal/middleware"
"github.com/gochat/gochat/internal/model"
"gorm.io/gorm"
)
func bindJSONWrappedOrRaw(c *gin.Context, wrapperKey string, target any) error {
@@ -213,3 +217,27 @@ func getPageSize(c *gin.Context) int {
}
return n
}
func requireConnectorShangwutongConversation(c *gin.Context, db *gorm.DB, conversation *model.Conversation) bool {
if !middleware.IsConnectorService(c) {
return true
}
if c.GetHeader("X-GoChat-Schema-Version") != "1" || db == nil || conversation == nil {
connectorRouteError(c, http.StatusUnprocessableEntity, "unsupported_schema_version", "X-GoChat-Schema-Version must be 1")
return false
}
var count int64
if err := db.WithContext(c.Request.Context()).Model(&model.Inbox{}).Where(
"id = ? AND account_id = ? AND channel_type = ?", conversation.InboxID, conversation.AccountID, "shangwutong",
).Count(&count).Error; err != nil || count != 1 {
connectorRouteError(c, http.StatusForbidden, "forbidden", "connector cannot access this conversation")
return false
}
return true
}
func connectorRouteError(c *gin.Context, status int, code, message string) {
c.AbortWithStatusJSON(status, gin.H{"error": gin.H{
"code": code, "message": message, "retryable": false, "request_id": c.GetString("request_id"),
}})
}