mirror of https://github.com/openclaw/openclaw.git
fix(mattermost): restore 2D→1D button flattening and empty-name filter
The core sends buttons as Array<Array<Button>> (2D for Telegram row layout). The consolidation from #18151 into #19957 lost the flatMap that flattens to 1D and the .filter() that drops malformed buttons. Without flatMap, each "button" is actually a row array — btn.text is undefined, producing empty-name buttons that render as white boxes with a blue left border in Mattermost.
This commit is contained in:
parent
921a8aaa50
commit
e85bda87be
|
|
@ -167,15 +167,24 @@ const mattermostMessageActions: ChannelMessageActionAdapter = {
|
|||
if (account.botToken) setInteractionSecret(account.botToken);
|
||||
const callbackUrl = resolveInteractionCallbackUrl(account.accountId, cfg);
|
||||
|
||||
const buttons = (params.buttons as Array<Record<string, unknown>>).map((btn) => ({
|
||||
id: String(btn.id ?? btn.callback_data ?? ""),
|
||||
name: String(btn.text ?? btn.name ?? btn.label ?? ""),
|
||||
style: (btn.style as "default" | "primary" | "danger") ?? "default",
|
||||
context:
|
||||
typeof btn.context === "object" && btn.context !== null
|
||||
? (btn.context as Record<string, unknown>)
|
||||
: undefined,
|
||||
}));
|
||||
// Flatten 2D array (rows of buttons) to 1D — core schema sends Array<Array<Button>>
|
||||
// but Mattermost doesn't have row layout, so we flatten all rows into a single list.
|
||||
// Also supports 1D arrays for backward compatibility.
|
||||
const rawButtons = (params.buttons as Array<unknown>).flatMap((item) =>
|
||||
Array.isArray(item) ? item : [item],
|
||||
) as Array<Record<string, unknown>>;
|
||||
|
||||
const buttons = rawButtons
|
||||
.map((btn) => ({
|
||||
id: String(btn.id ?? btn.callback_data ?? ""),
|
||||
name: String(btn.text ?? btn.name ?? btn.label ?? ""),
|
||||
style: (btn.style as "default" | "primary" | "danger") ?? "default",
|
||||
context:
|
||||
typeof btn.context === "object" && btn.context !== null
|
||||
? (btn.context as Record<string, unknown>)
|
||||
: undefined,
|
||||
}))
|
||||
.filter((btn) => btn.id && btn.name);
|
||||
|
||||
const attachmentText =
|
||||
typeof params.attachmentText === "string" ? params.attachmentText : undefined;
|
||||
|
|
|
|||
Loading…
Reference in New Issue