Skip to content

Feat: turn msg_type to interactive for native markdown support#155

Open
wjc1207 wants to merge 1 commit intomemovai:mainfrom
wjc1207:feat/msg_type_interactive
Open

Feat: turn msg_type to interactive for native markdown support#155
wjc1207 wants to merge 1 commit intomemovai:mainfrom
wjc1207:feat/msg_type_interactive

Conversation

@wjc1207
Copy link
Copy Markdown
Contributor

@wjc1207 wjc1207 commented Mar 18, 2026

msg_type: "interactive" (卡片消息) in feishu natively support markdown syntax

Summary by CodeRabbit

  • New Features
    • Messages sent through Feishu integration now display as interactive formatted cards instead of plain text, enhancing message presentation with improved formatting capabilities.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

The Feishu bot module is updated to send messages as interactive cards instead of plain text. A new static helper function builds schema 2.0 card content with markdown elements, which is then used by the send and reply message functions to format outgoing payloads.

Changes

Cohort / File(s) Summary
Feishu Interactive Card Integration
main/channels/feishu/feishu_bot.c
Added feishu_build_card_content() helper to generate Feishu schema 2.0 interactive cards with markdown support. Modified feishu_send_message() and feishu_reply_message() to use interactive card payloads (msg_type = "interactive") instead of plain text format.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 With cards so interactive and fine,
Markdown renders in perfect design,
No more plain text, just schemas so neat,
Each message now wrapped in a visual treat!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: converting message type to interactive for native markdown support in Feishu.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
main/channels/feishu/feishu_bot.c (1)

845-863: Consider defensive null checks for intermediate cJSON objects.

If body, elements, or md allocation fails, the resulting JSON will be incomplete and the Feishu API will reject it. While cJSON handles NULL gracefully (no crash), adding null checks would make failure modes explicit and allow early return with proper cleanup.

🔧 Proposed defensive checks
 static char *feishu_build_card_content(const char *text)
 {
     cJSON *card = cJSON_CreateObject();
     if (!card) return NULL;
+    cJSON *body = cJSON_CreateObject();
+    cJSON *elements = cJSON_CreateArray();
+    cJSON *md = cJSON_CreateObject();
+    if (!body || !elements || !md) {
+        cJSON_Delete(card);
+        cJSON_Delete(body);
+        cJSON_Delete(elements);
+        cJSON_Delete(md);
+        return NULL;
+    }
     cJSON_AddStringToObject(card, "schema", "2.0");
-    cJSON *body = cJSON_CreateObject();
-    cJSON *elements = cJSON_CreateArray();
-    cJSON *md = cJSON_CreateObject();
     cJSON_AddStringToObject(md, "tag", "markdown");
     cJSON_AddStringToObject(md, "content", text);
     cJSON_AddItemToArray(elements, md);
     cJSON_AddItemToObject(body, "elements", elements);
     cJSON_AddItemToObject(card, "body", body);
     char *card_str = cJSON_PrintUnformatted(card);
     cJSON_Delete(card);
     return card_str;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@main/channels/feishu/feishu_bot.c` around lines 845 - 863,
feishu_build_card_content currently assumes cJSON_CreateObject/Array always
succeed; add defensive NULL checks after creating card, body, elements, and md
and on any failure free any previously allocated cJSON objects (using
cJSON_Delete) and return NULL so you don't produce incomplete JSON; specifically
check card, then body, then elements, then md, and on each failure call
cJSON_Delete on any non-NULL earlier objects (card/body/elements) before
returning NULL and only call cJSON_PrintUnformatted when all allocations
succeeded.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@main/channels/feishu/feishu_bot.c`:
- Around line 845-863: feishu_build_card_content currently assumes
cJSON_CreateObject/Array always succeed; add defensive NULL checks after
creating card, body, elements, and md and on any failure free any previously
allocated cJSON objects (using cJSON_Delete) and return NULL so you don't
produce incomplete JSON; specifically check card, then body, then elements, then
md, and on each failure call cJSON_Delete on any non-NULL earlier objects
(card/body/elements) before returning NULL and only call cJSON_PrintUnformatted
when all allocations succeeded.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 18b56f15-9aac-4d04-b16a-a927510f1ddf

📥 Commits

Reviewing files that changed from the base of the PR and between bb10ea0 and afaf5d6.

📒 Files selected for processing (1)
  • main/channels/feishu/feishu_bot.c

@wjc1207
Copy link
Copy Markdown
Contributor Author

wjc1207 commented Mar 18, 2026

cc @crispyberry

@IRONICBo
Copy link
Copy Markdown
Member

Thanks! Have your checked that this is a general value?

@IRONICBo IRONICBo self-requested a review March 20, 2026 10:51
@IRONICBo IRONICBo self-assigned this Mar 20, 2026
@wjc1207
Copy link
Copy Markdown
Contributor Author

wjc1207 commented Mar 22, 2026

Thanks! Have your checked that this is a general value?

@IRONICBo I've checked it's a general value that supports markdown syntax.

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.

2 participants