增加stream插件消息处理逻辑和example
This commit is contained in:
parent
b46abaf516
commit
8e2b1452b3
|
|
@ -29,7 +29,7 @@ func OnChatBotMessageReceived(ctx context.Context, data *chatbot.BotCallbackData
|
|||
}
|
||||
|
||||
// 简单的插件处理实现
|
||||
func OnPluginMessageReceived(ctx context.Context, message *plugin.DingTalkPluginMessage) (interface{}, error) {
|
||||
func OnPluginMessageReceived(ctx context.Context, message *plugin.PluginMessage) (interface{}, error) {
|
||||
//可以根据message中的PluginId、PluginVersion、AbilityKey路由到具体一个能力
|
||||
if message.AbilityKey == "echo" {
|
||||
echoRequest := &EchoRequest{}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"reflect"
|
||||
)
|
||||
|
||||
type DingTalkPluginMessage struct {
|
||||
type PluginMessage struct {
|
||||
PluginId string `json:"pluginId"`
|
||||
PluginVersion string `json:"pluginVersion"`
|
||||
AbilityKey string `json:"abilityKey"`
|
||||
|
|
@ -15,7 +15,7 @@ type DingTalkPluginMessage struct {
|
|||
}
|
||||
|
||||
// 用于将数据转换成插件的请求参数
|
||||
func (req *DingTalkPluginMessage) ParseData(model interface{}) (err error) {
|
||||
func (req *PluginMessage) ParseData(model interface{}) (err error) {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
err = errors.New(fmt.Sprintf("parse data error: %v", e))
|
||||
|
|
@ -36,7 +36,7 @@ func (req *DingTalkPluginMessage) ParseData(model interface{}) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
type DingTalkPluginResponse struct {
|
||||
type PluginResponse struct {
|
||||
Result interface{} `json:"result"`
|
||||
RequestId string `json:"requestId"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ type CallbackResponse struct {
|
|||
Response interface{} `json:"response"`
|
||||
}
|
||||
|
||||
type IPluginMessageHandler func(c context.Context, data *DingTalkPluginMessage) (interface{}, error)
|
||||
type IPluginMessageHandler func(c context.Context, data *PluginMessage) (interface{}, error)
|
||||
|
||||
type DefaultPluginFrameHandler struct {
|
||||
defaultHandler IPluginMessageHandler
|
||||
|
|
@ -23,7 +23,7 @@ func NewDefaultPluginFrameHandler(defaultHandler IPluginMessageHandler) *Default
|
|||
}
|
||||
|
||||
func (h *DefaultPluginFrameHandler) OnEventReceived(ctx context.Context, df *payload.DataFrame) (*payload.DataFrameResponse, error) {
|
||||
msgData := &DingTalkPluginMessage{}
|
||||
msgData := &PluginMessage{}
|
||||
err := json.Unmarshal([]byte(df.Data), msgData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -37,8 +37,8 @@ func (h *DefaultPluginFrameHandler) OnEventReceived(ctx context.Context, df *pay
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dingTalkPluginResponse := &DingTalkPluginResponse{RequestId: msgData.RequestId, Result: result}
|
||||
callbackResponse := &CallbackResponse{Response: dingTalkPluginResponse}
|
||||
pluginResponse := &PluginResponse{RequestId: msgData.RequestId, Result: result}
|
||||
callbackResponse := &CallbackResponse{Response: pluginResponse}
|
||||
frameResp := payload.NewSuccessDataFrameResponse()
|
||||
frameResp.SetJson(callbackResponse)
|
||||
return frameResp, nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue