44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { sendMessageDiscord, sendPollDiscord } from "../../../discord/send.js";
|
|
import type { ChannelOutboundAdapter } from "../types.js";
|
|
import { missingTargetError } from "../../../infra/outbound/target-errors.js";
|
|
|
|
export const discordOutbound: ChannelOutboundAdapter = {
|
|
deliveryMode: "direct",
|
|
chunker: null,
|
|
textChunkLimit: 2000,
|
|
pollMaxOptions: 10,
|
|
resolveTarget: ({ to }) => {
|
|
const trimmed = to?.trim();
|
|
if (!trimmed) {
|
|
return {
|
|
ok: false,
|
|
error: missingTargetError("Discord", "<channelId|user:ID|channel:ID>"),
|
|
};
|
|
}
|
|
return { ok: true, to: trimmed };
|
|
},
|
|
sendText: async ({ to, text, accountId, deps, replyToId }) => {
|
|
const send = deps?.sendDiscord ?? sendMessageDiscord;
|
|
const result = await send(to, text, {
|
|
verbose: false,
|
|
replyTo: replyToId ?? undefined,
|
|
accountId: accountId ?? undefined,
|
|
});
|
|
return { channel: "discord", ...result };
|
|
},
|
|
sendMedia: async ({ to, text, mediaUrl, accountId, deps, replyToId }) => {
|
|
const send = deps?.sendDiscord ?? sendMessageDiscord;
|
|
const result = await send(to, text, {
|
|
verbose: false,
|
|
mediaUrl,
|
|
replyTo: replyToId ?? undefined,
|
|
accountId: accountId ?? undefined,
|
|
});
|
|
return { channel: "discord", ...result };
|
|
},
|
|
sendPoll: async ({ to, poll, accountId }) =>
|
|
await sendPollDiscord(to, poll, {
|
|
accountId: accountId ?? undefined,
|
|
}),
|
|
};
|