WxJava icon indicating copy to clipboard operation
WxJava copied to clipboard

Add convenience methods for Tips control with clickable links in ContentValue

Open Copilot opened this issue 2 months ago • 1 comments

Problem

Users reported that Tips controls in WeChat Work approval flows could not render URLs as clickable links ("Tips控件无法将url渲染为可点击的链接"). While the underlying ContentValue.NewTips structure supported the necessary JSON format for clickable links, creating Tips with mixed text and link content required verbose nested object creation, making it difficult for developers to implement properly.

Solution

This PR adds three static factory methods to ContentValue.NewTips to simplify creation of Tips controls with clickable links:

New Methods

// Simple plain text tip
NewTips.ofText("zh_CN", "This is a text tip")

// Single clickable link  
NewTips.ofLink("zh_CN", "Visit WeChat Work", "https://work.weixin.qq.com")

// Mixed content with text and links
NewTips.of("zh_CN", "For help, please ", linkObject, " or contact support.")

Generated JSON Structure

The methods generate the correct WeChat Work API JSON format with proper type differentiation:

{
  "tips_content": [{
    "text": {
      "sub_text": [
        {"type": 1, "content": {"plain_text": {"content": "Plain text"}}},
        {"type": 2, "content": {"link": {"title": "Link Title", "url": "https://example.com"}}}
      ]
    },
    "lang": "zh_CN"
  }]
}

Key Features

  • Backward Compatible: All existing code continues to work unchanged
  • Type Safety: Proper handling of type: 1 (plain text) vs type: 2 (clickable links)
  • Easy to Use: Reduces complex nested object creation to simple method calls
  • Well Tested: Comprehensive unit tests and usage examples included

Example Usage

Before (verbose manual creation):

ContentValue.NewTips tips = new ContentValue.NewTips();
ContentValue.NewTips.TipsContent content = new ContentValue.NewTips.TipsContent();
ContentValue.NewTips.TipsContent.Text text = new ContentValue.NewTips.TipsContent.Text();
// ... 15+ more lines of nested object setup

After (simple and intuitive):

// Create mixed content tip with text and clickable link
ContentValue.NewTips.TipsContent.SubText.Content.Link helpLink = 
    new ContentValue.NewTips.TipsContent.SubText.Content.Link();
helpLink.setTitle("查看帮助");
helpLink.setUrl("https://work.weixin.qq.com/help");

ContentValue.NewTips tip = ContentValue.NewTips.of("zh_CN",
    "需要帮助?请", helpLink, "了解详情。");

Files Changed

  • ContentValue.java: Added convenience factory methods and required imports
  • ContentValueTipsTest.java (new): Comprehensive unit tests
  • TipsUsageExample.java (new): Usage examples and demonstrations

This enhancement makes it significantly easier for developers to create Tips controls with clickable links that render properly in WeChat Work approval flows.

Fixes binarywang/WxJava#3418


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Sep 24 '25 15:09 Copilot

这个和issue反馈的问题对不上,issue反馈link没生效,但是【调用发起审批流】是不能设置tips的link的,怀疑是提问者没搞清楚。 8d3b65bba00b23449e322cd311c3c27a

binarywang avatar Sep 27 '25 09:09 binarywang

@copilot 请参考源issue说明,不需要做任何处理

binarywang avatar Nov 17 '25 02:11 binarywang

@copilot 请参考源issue说明,不需要做任何处理

已理解。根据企业微信API文档,Tips控件在调用审批流API时是只读展示控件,不能通过代码设置其link内容。已在提交 37fc798 中撤销所有更改,将代码恢复到原始状态。

Copilot avatar Nov 17 '25 02:11 Copilot