feat: directly add customer service friend
Deploy olons-server production / deploy (push) Successful in 3m26s

This commit is contained in:
richjohnrambo
2026-10-20 22:24:56 +08:00
parent 78165b7a15
commit 47b545d050
4 changed files with 85 additions and 51 deletions
+17
View File
@@ -107,6 +107,11 @@ type Conversation struct {
CanSend bool `json:"can_send"`
}
type DirectFriendResult struct {
Relationship string `json:"relationship"`
Topic string `json:"topic"`
}
func New(cfg config.IMConfig) *Client {
timeout := cfg.Timeout
if timeout <= 0 {
@@ -229,6 +234,18 @@ func (c *Client) CreateFriendRequest(ctx context.Context, token, userID, idempot
return &out, err
}
// AddFriendDirect establishes a trusted server-side friendship without
// creating a user-visible friend request. The IM internal API authenticates
// this operation with the configured internal secret.
func (c *Client) AddFriendDirect(ctx context.Context, userID, peerUserID string) (*DirectFriendResult, error) {
var out DirectFriendResult
path := "/internal/admin-query/tenants/" + url.PathEscape(c.cfg.TenantCode) + "/friends/direct"
err := c.internalJSON(ctx, http.MethodPost, path, map[string]any{
"user_id": userID, "peer_user_id": peerUserID,
}, &out)
return &out, err
}
func (c *Client) EnsureP2P(ctx context.Context, token, userID, idempotencyKey string) (*Conversation, error) {
var out Conversation
err := c.productJSON(ctx, http.MethodPost, "/conversations/p2p", token, idempotencyKey,