feat: add DingTalk answer feedback workflow
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sdkcard "github.com/open-dingtalk/dingtalk-stream-sdk-go/card"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot"
|
||||
dtsdk "github.com/open-dingtalk/dingtalk-stream-sdk-go/client"
|
||||
)
|
||||
@@ -232,7 +233,7 @@ type StreamClient struct {
|
||||
// credential and registers the chatbot callback router. The handler is
|
||||
// invoked synchronously from the SDK callback; its return value only
|
||||
// acknowledges the frame, replies always go through the session webhook.
|
||||
func NewStreamClient(config StreamConfig, handler *Handler) (*StreamClient, error) {
|
||||
func NewStreamClient(config StreamConfig, handler *Handler, feedbackHandlers ...*CardFeedbackHandler) (*StreamClient, error) {
|
||||
if err := config.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -242,6 +243,12 @@ func NewStreamClient(config StreamConfig, handler *Handler) (*StreamClient, erro
|
||||
if handler == nil {
|
||||
return nil, errors.New("dingtalk stream: handler is required")
|
||||
}
|
||||
if len(feedbackHandlers) > 1 {
|
||||
return nil, errors.New("dingtalk stream: at most one card feedback handler is allowed")
|
||||
}
|
||||
if len(feedbackHandlers) == 1 && feedbackHandlers[0] == nil {
|
||||
return nil, errors.New("dingtalk stream: card feedback handler is nil")
|
||||
}
|
||||
cred := dtsdk.NewAppCredentialConfig(strings.TrimSpace(config.ClientID), strings.TrimSpace(config.ClientSecret))
|
||||
// Keep the SDK default AutoReconnect=true so runtime disconnects
|
||||
// reconnect automatically; Close flips it off before closing.
|
||||
@@ -258,6 +265,11 @@ func NewStreamClient(config StreamConfig, handler *Handler) (*StreamClient, erro
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
if len(feedbackHandlers) == 1 {
|
||||
inner.RegisterCardCallbackRouter(func(ctx context.Context, request *sdkcard.CardRequest) (*sdkcard.CardResponse, error) {
|
||||
return feedbackHandlers[0].HandleSDK(ctx, request)
|
||||
})
|
||||
}
|
||||
return &StreamClient{inner: inner}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user