Feat: turn msg_type to interactive for native markdown support#155
Feat: turn msg_type to interactive for native markdown support#155wjc1207 wants to merge 1 commit intomemovai:mainfrom
Conversation
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip CodeRabbit can enforce grammar and style rules using `languagetool`.Configure the |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
main/channels/feishu/feishu_bot.c (1)
845-863: Consider defensive null checks for intermediate cJSON objects.If
body,elements, ormdallocation 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
📒 Files selected for processing (1)
main/channels/feishu/feishu_bot.c
|
cc @crispyberry |
|
Thanks! Have your checked that this is a general value? |
@IRONICBo I've checked it's a general value that supports markdown syntax. |
msg_type: "interactive" (卡片消息) in feishu natively support markdown syntax
Summary by CodeRabbit