Files
customer-server/controller/webhook_controller.go
2026-03-14 10:02:49 +08:00

42 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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
}