实现通过HTTP GIN API和MCP API发表评论到小红书Feed的功能: - 新增POST /api/v1/feeds/comment端点 - 新增post_comment_to_feed MCP工具 - 添加PostCommentRequest和PostCommentResponse类型 - 实现PostCommentToFeed服务方法 - 新增CommentFeedAction用于浏览器自动化操作 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package xiaohongshu
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/go-rod/rod"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// CommentFeedAction 表示 Feed 评论动作
|
|
type CommentFeedAction struct {
|
|
page *rod.Page
|
|
}
|
|
|
|
// NewCommentFeedAction 创建 Feed 评论动作
|
|
func NewCommentFeedAction(page *rod.Page) *CommentFeedAction {
|
|
return &CommentFeedAction{page: page}
|
|
}
|
|
|
|
// PostComment 发表评论到 Feed
|
|
func (f *CommentFeedAction) PostComment(ctx context.Context, feedID, xsecToken, content string) error {
|
|
page := f.page.Context(ctx).Timeout(60 * time.Second)
|
|
|
|
// 构建详情页 URL
|
|
url := makeFeedDetailURL(feedID, xsecToken)
|
|
|
|
logrus.Infof("Opening feed detail page: %s", url)
|
|
|
|
// 导航到详情页
|
|
page.MustNavigate(url)
|
|
page.MustWaitDOMStable()
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
elem := page.MustElement("div.input-box div.content-edit span")
|
|
elem.MustClick()
|
|
|
|
elem2 := page.MustElement("div.input-box div.content-edit p.content-input")
|
|
elem2.MustInput(content)
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
submitButton := page.MustElement("div.bottom button.submit")
|
|
submitButton.MustClick()
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
return nil
|
|
}
|