1
This commit is contained in:
41
controller/webhook_controller.go
Normal file
41
controller/webhook_controller.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Package controller - Webhook控制器
|
||||
// 功能:接收平台(小红书、抖音)的webhook消息
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"customer-server/model/dto"
|
||||
"customer-server/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
var Webhook = new(webhook)
|
||||
|
||||
type webhook struct{}
|
||||
|
||||
// Receive 接收Webhook消息
|
||||
// 参数: req - Webhook消息请求,包含平台、用户ID、内容等
|
||||
// 返回: res - 处理结果
|
||||
// 功能: 接收来自各平台的Webhook消息推送,统一处理后推送到Redis Stream
|
||||
func (c *webhook) Receive(ctx context.Context, req *dto.WebhookReceiveReq) (res *dto.WebhookReceiveRes, err error) {
|
||||
res, err = service.Webhook.Receive(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Verify 平台回调验证
|
||||
// 参数: req - 回调请求,包含echostr等
|
||||
// 返回: res - 处理结果
|
||||
// 功能: 验证平台回调请求,返回echostr
|
||||
func (c *webhook) Verify(ctx context.Context, req *dto.WebhookCallbackReq) (res *dto.WebhookCallbackRes, err error) {
|
||||
r := g.RequestFromCtx(ctx)
|
||||
// 直接返回 echostr(微信/抖音等平台验证方式)
|
||||
r.Response.Write(req.Echostr)
|
||||
return
|
||||
}
|
||||
|
||||
// History 查询对话记录
|
||||
func (c *webhook) History(ctx context.Context, req *dto.ConversationListReq) (res *dto.ConversationListRes, err error) {
|
||||
res, err = service.Webhook.GetHistory(ctx, req)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user