import { TELEGRAM_CHANNEL_DEFAULTS } from "../plugin-defaults.js";
//#region extensions/telegram/src/adapters/outbound-adapter.ts
function telegramTextChunker(text, limit) {
	const chunks = [];
	const lines = text.split("\n");
	let current = "";
	for (const line of lines) if ((current + "\n" + line).length > limit) {
		if (current) chunks.push(current);
		current = line;
	} else current = current ? current + "\n" + line : line;
	if (current) chunks.push(current);
	return chunks;
}
function toDelivery(r) {
	return {
		messageId: r.messageId,
		chatId: r.chatId,
		success: r.success,
		error: r.error
	};
}
function createTelegramOutboundSendMethods(send) {
	return {
		sendText: async (ctx) => {
			return toDelivery(await send({
				chatId: ctx.to,
				content: ctx.text,
				accountId: ctx.accountId,
				threadId: ctx.threadId?.toString(),
				replyToMessageId: ctx.replyToId?.toString(),
				silent: ctx.silent
			}));
		},
		sendPayload: async (ctx) => {
			const payload = ctx.payload;
			return toDelivery(await send({
				chatId: ctx.to,
				content: ctx.text,
				type: payload.type,
				accountId: ctx.accountId,
				threadId: ctx.threadId?.toString(),
				replyToMessageId: ctx.replyToId?.toString(),
				silent: ctx.silent,
				mediaUrl: ctx.mediaUrl,
				audioAsVoice: ctx.audioAsVoice
			}));
		},
		sendMedia: async (ctx) => {
			const mediaUrl = ctx.mediaUrl?.trim();
			if (!mediaUrl) return {
				messageId: "",
				chatId: ctx.to,
				success: false,
				error: "No media URL"
			};
			return toDelivery(await send({
				chatId: ctx.to,
				content: ctx.text ?? "",
				accountId: ctx.accountId,
				threadId: ctx.threadId?.toString(),
				replyToMessageId: ctx.replyToId?.toString(),
				silent: ctx.silent,
				mediaUrl,
				mediaType: ctx.mediaType,
				audioAsVoice: ctx.audioAsVoice
			}));
		}
	};
}
const TELEGRAM_OUTBOUND_DEFAULTS = { textChunkLimit: TELEGRAM_CHANNEL_DEFAULTS.outbound.textChunkLimit };
//#endregion
export { TELEGRAM_OUTBOUND_DEFAULTS, createTelegramOutboundSendMethods, telegramTextChunker };

//# sourceMappingURL=outbound-adapter.js.map