Skip to content

V4 #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

V4 #65

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
efd3ee3
feat(refactor): add first version /message /private/publish.json
Jan 22, 2024
936ff77
feat(refactor): add more chatroom functions
Jan 26, 2024
2fe5fcb
fix: chatroom message priority query path
Jan 26, 2024
ae8ccb6
feat: add custom http header to context
Jan 26, 2024
67a807f
fix: message literal type to pointer type(*)
Jan 26, 2024
018e7e5
fix: rename utils pointer func, e.g. String() to StringPtr()
Jan 26, 2024
7dd7642
feat: move chatroom unit test to examples
Jan 29, 2024
129730d
feat: add chatroom entry/whitelist/ban funcs
Jan 30, 2024
b78c192
feat: add chatroom user ban whitelist
Jan 30, 2024
e92370f
feat: refactor message module
Feb 2, 2024
f608424
feat: Add ultra group funcs
Feb 6, 2024
f262a85
feat: Add ultraGroup userGroup channel bind funcs
Feb 7, 2024
1d591d9
feat: conversation refactor complete
Feb 7, 2024
271f113
feat: Add group remarks functions
Feb 7, 2024
620637c
feat: Add GroupUserGag UserGroup functions
Feb 8, 2024
63142c7
feat: Add group ban whitelist functions
Feb 18, 2024
d1b78e7
feat: Add push functions
Feb 19, 2024
678e064
feat: Add sensitiveWord functions
Feb 19, 2024
bf06bd7
feat: Add user functions
Feb 26, 2024
68e049d
feat: apply http options
Feb 26, 2024
8fa9b44
feat: Refactor README.md
Feb 26, 2024
ed1a50c
feat: Refactor user README.md
Feb 26, 2024
d4eb215
feat: Refactor chatroom/conversation/group README.md
Feb 26, 2024
83de63b
feat: Refactor push/sensitive/ultragroup README.md
Feb 26, 2024
f41e28f
fix: remove RCMsg EncodeValues function
Feb 27, 2024
f58a7be
fix: README.md typo
Feb 27, 2024
1f9e1c9
fix: custom message example don't start with `RC:`
Feb 27, 2024
3b0fe84
feat: Add custom message tip to README.md
Feb 27, 2024
e9cc3e8
fix: SetHttpTransport not assign to httpClient
Feb 27, 2024
3d3a66c
feat: Add UltraGroupMsgModify function
Feb 27, 2024
6df63cb
feat: add installation README.md
Feb 28, 2024
190c62e
fix: README.md typo
Apr 9, 2024
0937367
Merge branch 'master' into v4
Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vet:
go vet ./rongcloud

mod:
go mod tidy
199 changes: 57 additions & 142 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion doc.go

This file was deleted.

3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## RongCloud Go Server SDK Example

当前目录下保留sdk使用示例, 如需更多示例, 非常欢迎提交PR。
41 changes: 41 additions & 0 deletions examples/chatroom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## 聊天室

### 方法列表
| 方法名 | 说明 | 调用示例 |
|----------------------------------|---------------|------------------------------------------------|
| ChatroomBanAdd | 设置聊天室全体禁言 | [chatroomban.go](./chatroomban.go) |
| ChatroomBanQuery | 查询聊天室全体禁言列表 | [chatroomban.go](./chatroomban.go) |
| ChatroomBanRollback | 取消聊天室全体禁言 | [chatroomban.go](./chatroomban.go) |
| ChatroomUserBanWhitelistAdd | 加入聊天室全体禁言白名单 | [chatroomban.go](./chatroomban.go) |
| ChatroomUserBanWhitelistQuery | 查询聊天室全体禁言白名单 | [chatroomban.go](./chatroomban.go) |
| ChatroomUserBanWhitelistRollback | 移出聊天室全体禁言白名单 | [chatroomban.go](./chatroomban.go) |
| ChatroomEntrySet | 设置聊天室属性(KV) | [chatroomentry.go.go](./chatroomentry.go.go) |
| ChatroomEntryBatchSet | 批量设置聊天室属性(KV) | [chatroomentry.go](./chatroomentry.go) |
| ChatroomEntryRemove | 删除聊天室属性(KV) | [chatroomentry.go](./chatroomentry.go) |
| ChatroomDestroySet | 设置聊天室销毁类型 | [chatroommeta.go.go](./chatroommeta.go.go) |
| ChatroomGet | 查询聊天室信息 | [chatroommeta.go](./chatroommeta.go) |
| ChatroomDestroy | 销毁聊天室 | [chatroommeta.go](./chatroommeta.go) |
| ChatroomUserExist | 查询用户是否在聊天室中 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUsersExist | 批量查询用户是否在聊天室中 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserQuery | 获取聊天室成员 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserBlockAdd | 封禁聊天室用户 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserBlockList | 查询聊天室封禁用户 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserBlockRollback | 解除封禁聊天室用户 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserBanAdd | 全局禁言用户 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserBanQuery | 查询全局禁言用户列表 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserBanRemove | 取消全局禁言用户 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserGagAdd | 禁言指定聊天室用户 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserGagList | 查询聊天室禁言用户列表 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomUserGagRollback | 取消禁言指定聊天室用户 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomMessagePriorityAdd | 添加低级别消息类型 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomMessagePriorityQuery | 查询低级别消息类型 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomMessagePriorityRemove | 移除低级别消息类型 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomKeepaliveAdd | 保活聊天室 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomKeepaliveQuery | 查询保活聊天室 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomKeepaliveRemove | 取消保活聊天室 | [chatroomuser.go](./chatroomuser.go) |
| ChatroomWhitelistAdd | 加入聊天室消息白名单 | [chatroomwhitelist.go](./chatroomwhitelist.go) |
| ChatroomWhitelistQuery | 查询聊天室消息白名单 | [chatroomwhitelist.go](./chatroomwhitelist.go) |
| ChatroomWhitelistRemove | 移出聊天室消息白名单 | [chatroomwhitelist.go](./chatroomwhitelist.go) |
| ChatroomUserWhitelistAdd | 加入聊天室用户白名单 | [chatroomwhitelist.go](./chatroomwhitelist.go) |
| ChatroomUserWhitelistQuery | 查询聊天室用户白名单 | [chatroomwhitelist.go](./chatroomwhitelist.go) |
| ChatroomUserWhitelistRemove | 移出聊天室用户白名单 | [chatroomwhitelist.go](./chatroomwhitelist.go) |
109 changes: 109 additions & 0 deletions examples/chatroom/chatroomban.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"context"
"encoding/json"
"log"
"os"

"github.com/rongcloud/server-sdk-go/v4/rongcloud"
)

func main() {
rc := rongcloud.NewRongCloud(os.Getenv("APP_KEY"), os.Getenv("APP_SECRET"))
ctx := context.Background()

chatroomBan(ctx, rc)
}

func chatroomBan(ctx context.Context, rc *rongcloud.RongCloud) {
grp := "grp1"
// 创建测试chatroom
_, err := rc.ChatroomCreateNew(ctx, &rongcloud.ChatroomCreateNewRequest{ChatroomId: rongcloud.StringPtr(grp)})
if err != nil {
log.Fatalf("chatroom create error %s", err)
}

banReq := rongcloud.ChatroomBanRequest{
ChatroomId: rongcloud.StringPtr(grp),
Extra: rongcloud.StringPtr(""),
NeedNotify: rongcloud.BoolPtr(true),
}

// 设置聊天室全体禁言
banAddRequest := &rongcloud.ChatroomBanAddRequest{
ChatroomBanRequest: banReq,
}
_, err = rc.ChatroomBanAdd(ctx, banAddRequest)
if err != nil {
log.Fatalf("chatroom ban add error %s", err)
}

// 查询聊天室全体禁言列表
banQueryResp, err := rc.ChatroomBanQuery(ctx, &rongcloud.ChatroomBanQueryRequest{
Size: rongcloud.IntPtr(50),
Page: rongcloud.IntPtr(1),
})
if err != nil {
log.Fatalf("chatroom ban query error %s", err)
}
banQueryRespData, _ := json.Marshal(banQueryResp)
log.Printf("chatroom ban query resp data: %s", banQueryRespData)

banCheckResp, err := rc.ChatroomBanCheck(ctx, &rongcloud.ChatroomBanCheckRequest{ChatroomId: rongcloud.StringPtr(grp)})
if err != nil {
log.Fatalf("chatroom ban check error %s", err)
}
banCheckRespData, _ := json.Marshal(banCheckResp)
log.Printf("chatroom ban check resp data: %s", banCheckRespData)

// 取消聊天室全体禁言
banRollbackRequest := &rongcloud.ChatroomBanRollbackRequest{
ChatroomBanRequest: banReq,
}
_, err = rc.ChatroomBanRollback(ctx, banRollbackRequest)
if err != nil {
log.Fatalf("chatroom ban rollback error %s", err)
}

// 加入聊天室全体禁言白名单
userBanWhiteListReq := rongcloud.ChatroomUserBanWhitelistRequest{
ChatroomId: rongcloud.StringPtr(grp),
UserIds: []string{"u01", "u02"},
Extra: rongcloud.StringPtr(""),
NeedNotify: rongcloud.BoolPtr(true),
}
userBanWhitelistAddReq := &rongcloud.ChatroomUserBanWhitelistAddRequest{
ChatroomUserBanWhitelistRequest: userBanWhiteListReq,
}
_, err = rc.ChatroomUserBanWhitelistAdd(ctx, userBanWhitelistAddReq)
if err != nil {
log.Fatalf("chatroom user ban whitelist add error %s", err)
}

// 查询聊天室全体禁言白名单
userBanWhitelistQueryReq := &rongcloud.ChatroomUserBanWhitelistQueryRequest{
ChatroomId: rongcloud.StringPtr(grp),
}
userBanWhitelistQueryResp, err := rc.ChatroomUserBanWhitelistQuery(ctx, userBanWhitelistQueryReq)
if err != nil {
log.Fatalf("chatroom user ban whitelist query error %s", err)
}
userBanWhitelistQueryRespData, _ := json.Marshal(userBanWhitelistQueryResp)
log.Printf("chatroom user ban whitelist query resp data: %s", userBanWhitelistQueryRespData)

// 移出聊天室全体禁言白名单
userBanWhitelistRollbackReq := &rongcloud.ChatroomUserBanWhitelistRollbackRequest{
ChatroomUserBanWhitelistRequest: userBanWhiteListReq,
}
_, err = rc.ChatroomUserBanWhitelistRollback(ctx, userBanWhitelistRollbackReq)
if err != nil {
log.Fatalf("chatroom user ban whitelist rollback error %s", err)
}

// 销毁测试chatroom
_, err = rc.ChatroomDestroy(ctx, &rongcloud.ChatroomDestroyRequest{ChatroomIds: []string{grp}})
if err != nil {
log.Fatalf("chatroom create error %s", err)
}
}
90 changes: 90 additions & 0 deletions examples/chatroom/chatroomentry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package main

import (
"context"
"encoding/json"
"log"
"os"

"github.com/rongcloud/server-sdk-go/v4/rongcloud"
)

func main() {
rc := rongcloud.NewRongCloud(os.Getenv("APP_KEY"), os.Getenv("APP_SECRET"))
ctx := context.Background()

chatroomEntry(ctx, rc)
}

func chatroomEntry(ctx context.Context, rc *rongcloud.RongCloud) {
grp := "grp1"
_, err := rc.ChatroomCreateNew(ctx, &rongcloud.ChatroomCreateNewRequest{
ChatroomId: rongcloud.StringPtr(grp),
})
if err != nil {
log.Fatalf("chatroom create error: %s", err)
}

// 设置聊天室属性(KV)
_, err = rc.ChatroomEntrySet(ctx, &rongcloud.ChatroomEntrySetRequest{
ChatroomId: rongcloud.StringPtr(grp),
UserId: rongcloud.StringPtr("u01"),
Key: rongcloud.StringPtr("key1"),
Value: rongcloud.StringPtr("val1"),
AutoDelete: rongcloud.IntPtr(1),
RCMsg: &rongcloud.ChrmKVNotiMsg{
Type: 1,
Key: "key1",
Value: "val1",
Extra: "extra info",
},
})
if err != nil {
log.Fatalf("chatroom entry set err %s", err)
}

// 批量设置聊天室属性(KV)
_, err = rc.ChatroomEntryBatchSet(ctx, &rongcloud.ChatroomEntryBatchSetRequest{
ChatroomId: rongcloud.StringPtr(grp),
AutoDelete: rongcloud.IntPtr(1),
EntryOwnerId: rongcloud.StringPtr("u01"),
EntryInfo: map[string]string{"k1": "k2"},
})
if err != nil {
log.Fatalf("chatroom entry batch set err %s", err)
}

entryQueryResp, err := rc.ChatroomEntryQuery(ctx, &rongcloud.ChatroomEntryQueryRequest{
ChatroomId: rongcloud.StringPtr(grp),
Keys: []string{"key1"},
})
if err != nil {
log.Fatalf("chatroom entry query error %s", err)
}
entryQueryRespData, err := json.Marshal(entryQueryResp)
log.Printf("chatroom entry query resp: %s", entryQueryRespData)

// 删除聊天室属性(KV)
_, err = rc.ChatroomEntryRemove(ctx, &rongcloud.ChatroomEntryRemoveRequest{
ChatroomId: rongcloud.StringPtr(grp),
UserId: rongcloud.StringPtr("u01"),
Key: rongcloud.StringPtr("key1"),
RCMsg: &rongcloud.ChrmKVNotiMsg{
Type: 2,
Key: "key1",
Value: "val1",
Extra: "extra info",
},
})
if err != nil {
log.Fatalf("chatroom entry remove %s", err)
}

// 销毁测试聊天室
_, err = rc.ChatroomDestroy(ctx, &rongcloud.ChatroomDestroyRequest{
ChatroomIds: []string{grp},
})
if err != nil {
log.Fatalf("chatroom destroy error: %s", err)
}
}
60 changes: 60 additions & 0 deletions examples/chatroom/chatroommeta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"context"
"encoding/json"
"log"
"os"

"github.com/rongcloud/server-sdk-go/v4/rongcloud"
)

func main() {
rc := rongcloud.NewRongCloud(os.Getenv("APP_KEY"), os.Getenv("APP_SECRET"))
ctx := context.Background()

chatroomMetaOp(ctx, rc)
}

func chatroomMetaOp(ctx context.Context, rc *rongcloud.RongCloud) {
// create chatroom
resp, err := rc.ChatroomCreateNew(ctx, &rongcloud.ChatroomCreateNewRequest{
ChatroomId: rongcloud.StringPtr("grp1"),
})
if err != nil {
log.Fatalf("chatroom create err %s", err)
}
b, _ := json.Marshal(resp)
log.Printf("chat room create resp: %s", b)
log.Printf("http response get %+v", resp.GetHttpResponse())

// 设置聊天室销毁类型
destroySetResp, err := rc.ChatroomDestroySet(ctx, &rongcloud.ChatroomDestroySetRequest{
ChatroomId: rongcloud.StringPtr("grp1"),
DestroyTime: rongcloud.IntPtr(60),
DestroyType: rongcloud.IntPtr(1),
})
if err != nil {
log.Fatalf("chatroom destroy set err %s", err)
}
destroySetData, _ := json.Marshal(destroySetResp)
log.Printf("chatroom destroy set resp: %s", destroySetData)

// 查询聊天室信息
chatroomGetResp, err := rc.ChatroomGet(ctx, &rongcloud.ChatroomGetRequest{ChatroomId: rongcloud.StringPtr("grp1")})
if err != nil {
log.Fatalf("chatroom get err %s", err)
}
chatroomGetData, _ := json.Marshal(chatroomGetResp)
log.Printf("chatroom get resp: %s", chatroomGetData)

// 销毁聊天室
destroyChatroomResp, err := rc.ChatroomDestroy(ctx, &rongcloud.ChatroomDestroyRequest{
ChatroomIds: []string{"grp1", "grp2"},
})
if err != nil {
log.Fatalf("chatroom destroy err %s", err)
}
destroyChatRoomData, _ := json.Marshal(destroyChatroomResp)
log.Printf("chatroom destroy: %s", destroyChatRoomData)
}
Loading