feat #1 增加readme
This commit is contained in:
parent
53bfbab986
commit
d3c27236ba
57
README.md
57
README.md
|
|
@ -1,2 +1,57 @@
|
||||||
# dingtalk-stream-sdk-go
|
# DingTalk Stream Mode 介绍
|
||||||
|
|
||||||
Go SDK for DingTalk Stream Mode API, Compared with the webhook mode, it is easier to access the DingTalk chatbot
|
Go SDK for DingTalk Stream Mode API, Compared with the webhook mode, it is easier to access the DingTalk chatbot
|
||||||
|
|
||||||
|
钉钉支持 Stream 模式接入事件推送、机器人收消息以及卡片回调,该 SDK 实现了 Stream 模式。相比 Webhook 模式,Stream 模式可以更简单的接入各类事件和回调。
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 准备工作
|
||||||
|
|
||||||
|
* Go语言开发环境,https://www.go.dev/
|
||||||
|
* 钉钉开发者账号,具备创建企业内部应用的权限,详见[成为钉钉开发者](https://open.dingtalk.com/document/orgapp/become-a-dingtalk-developer)
|
||||||
|
|
||||||
|
### 快速开始指南
|
||||||
|
|
||||||
|
1、创建企业内部应用
|
||||||
|
|
||||||
|
进入[钉钉开发者后台](https://open-dev.dingtalk.com/),创建企业内部应用,获取ClientID(即 AppKey)和ClientSecret( 即AppSecret)。
|
||||||
|
|
||||||
|
发布应用:在开发者后台左侧导航中,点击“版本管理与发布”,点击“确认发布”,并在接下来的可见范围设置中,选择“全部员工”,或者按需选择部分员工。
|
||||||
|
|
||||||
|
|
||||||
|
2、Stream 模式的机器人(可选)
|
||||||
|
|
||||||
|
如果不需要使用机器人功能的话,可以不用创建。
|
||||||
|
|
||||||
|
在应用管理的左侧导航中,选择“消息推送”,打开机器人能力,设置机器人基本信息。
|
||||||
|
|
||||||
|
注意:消息接收模式中,选择 “Stream 模式”
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
点击“点击调试”按钮,可以创建测试群进行测试。
|
||||||
|
|
||||||
|
3、启动应用
|
||||||
|
|
||||||
|
修改参数,启动应用
|
||||||
|
```Shell
|
||||||
|
go run example/*.go -client_id "your-client-id" -client_secret "your-client-secret"
|
||||||
|
```
|
||||||
|
|
||||||
|
测试效果:
|
||||||
|

|
||||||
|
|
||||||
|
### 事件订阅切换到 Stream 模式(可选)
|
||||||
|
|
||||||
|
进入钉钉开发者后台,选择企业内部应用,在应用管理的左侧导航中,选择“事件与回调”。
|
||||||
|
“订阅管理”中,“推送方式”选项中,选择 “Stream 模式”,并保存
|
||||||
|
|
||||||
|
|
||||||
|
### 技术支持
|
||||||
|
|
||||||
|
可以搜索共创群,答疑交流。共创群ID:35365014813 (钉钉搜索群号入群);
|
||||||
|
|
||||||
|
也可以扫码入群:
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ func OnChatReceive(ctx context.Context, data *chatbot.BotCallbackDataModel) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunBotListener() {
|
func RunBotListener(clientId, clientSecret string) {
|
||||||
logger.SetLogger(logger.NewStdTestLogger())
|
logger.SetLogger(logger.NewStdTestLogger())
|
||||||
|
|
||||||
cli := client.NewStreamClient(
|
cli := client.NewStreamClient(
|
||||||
client.WithAppCredential(client.NewAppCredentialConfig("your-client-id", "your-client-secret")),
|
client.WithAppCredential(client.NewAppCredentialConfig(clientId, clientSecret)),
|
||||||
client.WithUserAgent(client.NewDingtalkGoSDKUserAgent()),
|
client.WithUserAgent(client.NewDingtalkGoSDKUserAgent()),
|
||||||
client.WithSubscription(utils.SubscriptionTypeKCallback, payload.BotMessageCallbackTopic, chatbot.NewDefaultChatBotFrameHandler(OnChatReceive).OnEventReceived),
|
client.WithSubscription(utils.SubscriptionTypeKCallback, payload.BotMessageCallbackTopic, chatbot.NewDefaultChatBotFrameHandler(OnChatReceive).OnEventReceived),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ import (
|
||||||
* @Date 2023/3/22 18:30
|
* @Date 2023/3/22 18:30
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func RunEventListener() {
|
func RunEventListener(clientId, clientSecret string) {
|
||||||
logger.SetLogger(logger.NewStdTestLogger())
|
logger.SetLogger(logger.NewStdTestLogger())
|
||||||
|
|
||||||
eventHandler := event.NewDefaultEventFrameHandler(event.EventHandlerDoNothing)
|
eventHandler := event.NewDefaultEventFrameHandler(event.EventHandlerDoNothing)
|
||||||
|
|
||||||
cli := client.NewStreamClient(
|
cli := client.NewStreamClient(
|
||||||
client.WithAppCredential(client.NewAppCredentialConfig("your-client-id", "your-client-secret")),
|
client.WithAppCredential(client.NewAppCredentialConfig(clientId, clientSecret)),
|
||||||
client.WithUserAgent(client.NewDingtalkGoSDKUserAgent()),
|
client.WithUserAgent(client.NewDingtalkGoSDKUserAgent()),
|
||||||
client.WithSubscription(utils.SubscriptionTypeKEvent, "*", eventHandler.OnEventReceived),
|
client.WithSubscription(utils.SubscriptionTypeKEvent, "*", eventHandler.OnEventReceived),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,22 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author linya.jj
|
* @Author linya.jj
|
||||||
* @Date 2023/3/22 18:30
|
* @Date 2023/3/22 18:30
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
RunBotListener()
|
var clientId, clientSecret string
|
||||||
|
flag.StringVar(&clientId, "client_id", "", "your-client-id")
|
||||||
|
flag.StringVar(&clientSecret, "client_secret", "", "your-client-secret")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
RunBotListener(clientId, clientSecret)
|
||||||
|
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue