Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 24, 2025

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 #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 AI and others added 2 commits September 24, 2025 15:25
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] ContentValue类支持说明文字控件Tips控件 Add convenience methods for Tips control with clickable links in ContentValue Sep 24, 2025
@Copilot Copilot AI requested a review from binarywang September 24, 2025 15:33
Copilot finished work on behalf of binarywang September 24, 2025 15:33
@binarywang binarywang marked this pull request as ready for review September 27, 2025 09:01
@binarywang
Copy link
Owner

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

@binarywang binarywang added this to the 4.7.9 milestone Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ContentValue类支持说明文字控件Tips控件
2 participants