mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-31 03:41:51 +00:00
refactor(mattermost): define post schema once
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/infra-runtime";
|
||||
import { z } from "openclaw/plugin-sdk/zod";
|
||||
|
||||
export type MattermostClient = {
|
||||
baseUrl: string;
|
||||
@@ -25,17 +26,21 @@ export type MattermostChannel = {
|
||||
team_id?: string | null;
|
||||
};
|
||||
|
||||
export type MattermostPost = {
|
||||
id: string;
|
||||
user_id?: string | null;
|
||||
channel_id?: string | null;
|
||||
message?: string | null;
|
||||
file_ids?: string[] | null;
|
||||
type?: string | null;
|
||||
root_id?: string | null;
|
||||
create_at?: number | null;
|
||||
props?: Record<string, unknown> | null;
|
||||
};
|
||||
export const MattermostPostSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
user_id: z.string().nullable().optional(),
|
||||
channel_id: z.string().nullable().optional(),
|
||||
message: z.string().nullable().optional(),
|
||||
file_ids: z.array(z.string()).nullable().optional(),
|
||||
type: z.string().nullable().optional(),
|
||||
root_id: z.string().nullable().optional(),
|
||||
create_at: z.number().nullable().optional(),
|
||||
props: z.record(z.string(), z.unknown()).nullable().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type MattermostPost = z.infer<typeof MattermostPostSchema>;
|
||||
|
||||
export type MattermostFileInfo = {
|
||||
id: string;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { safeParseJsonWithSchema, safeParseWithSchema } from "openclaw/plugin-sdk/extension-shared";
|
||||
import { z } from "openclaw/plugin-sdk/zod";
|
||||
import WebSocket from "ws";
|
||||
import { z } from "zod";
|
||||
import type { ChannelAccountSnapshot, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { MattermostPost } from "./client.js";
|
||||
import { MattermostPostSchema, type MattermostPost } from "./client.js";
|
||||
import { rawDataToString } from "./monitor-helpers.js";
|
||||
|
||||
export type MattermostEventPayload = {
|
||||
@@ -36,11 +36,6 @@ export type MattermostWebSocketLike = {
|
||||
|
||||
export type MattermostWebSocketFactory = (url: string) => MattermostWebSocketLike;
|
||||
|
||||
const MattermostPostSchema = z.record(
|
||||
z.string(),
|
||||
z.unknown(),
|
||||
) as unknown as z.ZodType<MattermostPost>;
|
||||
|
||||
const MattermostEventPayloadSchema = z.object({
|
||||
event: z.string().optional(),
|
||||
data: z
|
||||
|
||||
Reference in New Issue
Block a user