mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
fix(discord): fix component parsing and modal field typing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import type { DiscordActionConfig } from "../../config/config.js";
|
||||
import type { DiscordSendComponents, DiscordSendEmbeds } from "../../discord/send.shared.js";
|
||||
import { readDiscordComponentSpec } from "../../discord/components.js";
|
||||
import {
|
||||
createThreadDiscord,
|
||||
deleteMessageDiscord,
|
||||
|
||||
@@ -34,8 +34,17 @@ export async function handleDiscordMessageAction(
|
||||
|
||||
if (action === "send") {
|
||||
const to = readStringParam(params, "to", { required: true });
|
||||
const asVoice = params.asVoice === true;
|
||||
const rawComponents = params.components;
|
||||
const components =
|
||||
rawComponents &&
|
||||
(Array.isArray(rawComponents) ||
|
||||
typeof rawComponents === "function" ||
|
||||
(typeof rawComponents === "object" && !Array.isArray(rawComponents)))
|
||||
? rawComponents
|
||||
: undefined;
|
||||
const content = readStringParam(params, "message", {
|
||||
required: true,
|
||||
required: !asVoice && !components,
|
||||
allowEmpty: true,
|
||||
});
|
||||
// Support media, path, and filePath for media URL
|
||||
@@ -44,14 +53,8 @@ export async function handleDiscordMessageAction(
|
||||
readStringParam(params, "path", { trim: false }) ??
|
||||
readStringParam(params, "filePath", { trim: false });
|
||||
const replyTo = readStringParam(params, "replyTo");
|
||||
const rawComponents = params.components;
|
||||
const components =
|
||||
Array.isArray(rawComponents) || typeof rawComponents === "function"
|
||||
? rawComponents
|
||||
: undefined;
|
||||
const rawEmbeds = params.embeds;
|
||||
const embeds = Array.isArray(rawEmbeds) ? rawEmbeds : undefined;
|
||||
const asVoice = params.asVoice === true;
|
||||
const silent = params.silent === true;
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
|
||||
@@ -43,7 +43,11 @@ export function buildDirectLabel(author: User, tagOverride?: string) {
|
||||
return `${username ?? "unknown"} user id:${author.id}`;
|
||||
}
|
||||
|
||||
export function buildGuildLabel(params: { guild?: Guild; channelName: string; channelId: string }) {
|
||||
export function buildGuildLabel(params: {
|
||||
guild?: Guild<true> | Guild;
|
||||
channelName: string;
|
||||
channelId: string;
|
||||
}) {
|
||||
const { guild, channelName, channelId } = params;
|
||||
return `${guild?.name ?? "Guild"} #${channelName} channel id:${channelId}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user