fix(onebot): accept compatible JSON card payloads (#325)

This commit is contained in:
DrSmoothl committed 2026-08-08 10:14:39 +08:00
1 parent 751217c13d
commit 65683bb44d
5 files changed
+97 -18

No files matched your search

@@ -318,11 +318,14 @@ export const ELEMENT_CODECS = {
return { type: 'json', data: { data: element.text ?? '' } };
},
async fromSegment(data) {
const text = data.data;
const raw = data.data;
const text = typeof raw === 'object' && raw !== null && !Array.isArray(raw)
? JSON.stringify(raw)
: raw;
if (typeof text !== 'string' || !text.trim()) {
throw new MessageElementValidationError(
'INVALID_FIELD',
'message segment "json" field "data" must be a non-empty JSON string',
'message segment "json" field "data" must be a JSON object or non-empty JSON string',
'json',
'data',
);