惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
博客园 - 【当耐特】
B
Blog
Stack Overflow Blog
Stack Overflow Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园 - 司徒正美
博客园 - 叶小钗
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(line): cap carousel column text at 60 chars when a ti...
harjothkhara · 2026-06-16 · via Recent Commits to openclaw:main

@@ -13,6 +13,9 @@ type CarouselColumn = messagingApi.CarouselColumn;

1313

type ImageCarouselTemplate = messagingApi.ImageCarouselTemplate;

1414

type ImageCarouselColumn = messagingApi.ImageCarouselColumn;

151516+

const COMPACT_TEMPLATE_TEXT_LIMIT = 60;

17+

const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });

18+1619

type TemplatePayloadAction = {

1720

type?: "uri" | "postback" | "message";

1821

uri?: string;

@@ -30,6 +33,48 @@ function buildTemplatePayloadAction(action: TemplatePayloadAction): Action {

3033

return messageAction(action.label, action.data ?? action.label);

3134

}

323536+

function resolveTemplateTextLimit(params: {

37+

title?: string;

38+

thumbnailImageUrl?: string;

39+

textOnlyLimit: number;

40+

}): number {

41+

return params.title !== undefined || params.thumbnailImageUrl !== undefined

42+

? COMPACT_TEMPLATE_TEXT_LIMIT

43+

: params.textOnlyLimit;

44+

}

45+46+

function truncateTemplateText(text: string, limit: number): string {

47+

let result = "";

48+

for (const { segment } of graphemeSegmenter.segment(text)) {

49+

if (result.length + segment.length > limit) {

50+

// A pathological grapheme can exceed LINE's whole field limit. Preserve

51+

// graphemes normally, but keep required text non-empty without splitting

52+

// a surrogate pair when the first grapheme alone cannot fit.

53+

if (!result) {

54+

for (const codePoint of segment) {

55+

if (result.length + codePoint.length > limit) {

56+

break;

57+

}

58+

result += codePoint;

59+

}

60+

}

61+

break;

62+

}

63+

result += segment;

64+

}

65+

return result;

66+

}

67+68+

function formatProductCarouselText(description: string, price?: string): string {

69+

if (!price) {

70+

return description;

71+

}

72+

const priceText = truncateTemplateText(price, COMPACT_TEMPLATE_TEXT_LIMIT);

73+

const descriptionLimit = Math.max(0, COMPACT_TEMPLATE_TEXT_LIMIT - priceText.length - 1);

74+

const descriptionText = truncateTemplateText(description, descriptionLimit);

75+

return descriptionText ? `${descriptionText}\n${priceText}` : priceText;

76+

}

77+3378

/**

3479

* Create a confirm template (yes/no style dialog)

3580

*/

@@ -68,12 +113,15 @@ export function createButtonTemplate(

68113

altText?: string;

69114

},

70115

): TemplateMessage {

71-

const hasThumbnail = Boolean(options?.thumbnailImageUrl?.trim());

72-

const textLimit = hasThumbnail ? 160 : 60;

116+

const textLimit = resolveTemplateTextLimit({

117+

title,

118+

thumbnailImageUrl: options?.thumbnailImageUrl,

119+

textOnlyLimit: 160,

120+

});

73121

const template: ButtonsTemplate = {

74122

type: "buttons",

75123

title: title.slice(0, 40), // LINE limit

76-

text: text.slice(0, textLimit), // LINE limit (60 if no thumbnail, 160 with thumbnail)

124+

text: truncateTemplateText(text, textLimit),

77125

actions: actions.slice(0, 4), // LINE limit: max 4 actions

78126

thumbnailImageUrl: options?.thumbnailImageUrl,

79127

imageAspectRatio: options?.imageAspectRatio ?? "rectangle",

@@ -125,9 +173,14 @@ export function createCarouselColumn(params: {

125173

imageBackgroundColor?: string;

126174

defaultAction?: Action;

127175

}): CarouselColumn {

176+

// LINE caps a carousel column's text at 60 chars when the column carries a

177+

// title or thumbnail image, and 120 chars otherwise. Sending an over-length

178+

// text makes LINE reject the whole carousel, so mirror the conditional limit

179+

// the buttons template already applies above.

180+

const textLimit = resolveTemplateTextLimit({ ...params, textOnlyLimit: 120 });

128181

return {

129182

title: params.title?.slice(0, 40),

130-

text: params.text.slice(0, 120), // LINE limit

183+

text: truncateTemplateText(params.text, textLimit),

131184

actions: params.actions.slice(0, 3), // LINE limit: max 3 actions per column

132185

thumbnailImageUrl: params.thumbnailImageUrl,

133186

imageBackgroundColor: params.imageBackgroundColor,

@@ -256,9 +309,7 @@ export function createProductCarousel(

256309257310

return createCarouselColumn({

258311

title: product.title,

259-

text: product.price

260-

? `${product.description}\n${product.price}`.slice(0, 120)

261-

: product.description,

312+

text: formatProductCarouselText(product.description, product.price),

262313

thumbnailImageUrl: product.imageUrl,

263314

actions,

264315

});