mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 12:42:53 +00:00
refactor: share Telegram outbound send context
This commit is contained in:
@@ -96,6 +96,14 @@ async function resolveTelegramSendContext(params: {
|
||||
};
|
||||
}
|
||||
|
||||
async function resolveTelegramOutboundSendContext(
|
||||
params: Parameters<typeof resolveTelegramSendContext>[0] & { to: string },
|
||||
) {
|
||||
const outboundTo = normalizeTelegramOutboundTarget(params.to);
|
||||
const { send, baseOpts } = await resolveTelegramSendContext(params);
|
||||
return { outboundTo, send, baseOpts };
|
||||
}
|
||||
|
||||
export type CreateTelegramOutboundAdapterOptions = {
|
||||
resolveSend?: ResolveTelegramSendFn;
|
||||
loadSendModule?: LoadTelegramSendModuleFn;
|
||||
@@ -246,107 +254,43 @@ export function createTelegramOutboundAdapter(
|
||||
supportsAnonymousPolls: true,
|
||||
...createAttachedChannelResultAdapter({
|
||||
channel: "telegram",
|
||||
sendText: async ({
|
||||
cfg,
|
||||
to,
|
||||
text,
|
||||
accountId,
|
||||
deps,
|
||||
replyToId,
|
||||
threadId,
|
||||
formatting,
|
||||
silent,
|
||||
gatewayClientScopes,
|
||||
}) => {
|
||||
const outboundTo = normalizeTelegramOutboundTarget(to);
|
||||
const { send, baseOpts } = await resolveTelegramSendContext({
|
||||
cfg,
|
||||
deps,
|
||||
accountId,
|
||||
replyToId,
|
||||
threadId,
|
||||
formatting,
|
||||
silent,
|
||||
gatewayClientScopes,
|
||||
sendText: async (params) => {
|
||||
const { outboundTo, send, baseOpts } = await resolveTelegramOutboundSendContext({
|
||||
...params,
|
||||
resolveSend,
|
||||
});
|
||||
return await send(outboundTo, text, {
|
||||
return await send(outboundTo, params.text, {
|
||||
...baseOpts,
|
||||
});
|
||||
},
|
||||
sendMedia: async ({
|
||||
cfg,
|
||||
to,
|
||||
text,
|
||||
mediaUrl,
|
||||
mediaLocalRoots,
|
||||
mediaReadFile,
|
||||
accountId,
|
||||
deps,
|
||||
replyToId,
|
||||
threadId,
|
||||
formatting,
|
||||
forceDocument,
|
||||
silent,
|
||||
gatewayClientScopes,
|
||||
}) => {
|
||||
const outboundTo = normalizeTelegramOutboundTarget(to);
|
||||
const { send, baseOpts } = await resolveTelegramSendContext({
|
||||
cfg,
|
||||
deps,
|
||||
accountId,
|
||||
replyToId,
|
||||
threadId,
|
||||
formatting,
|
||||
silent,
|
||||
gatewayClientScopes,
|
||||
sendMedia: async (params) => {
|
||||
const { outboundTo, send, baseOpts } = await resolveTelegramOutboundSendContext({
|
||||
...params,
|
||||
resolveSend,
|
||||
});
|
||||
return await send(outboundTo, text, {
|
||||
return await send(outboundTo, params.text, {
|
||||
...baseOpts,
|
||||
mediaUrl,
|
||||
mediaLocalRoots,
|
||||
mediaReadFile,
|
||||
forceDocument: forceDocument ?? false,
|
||||
mediaUrl: params.mediaUrl,
|
||||
mediaLocalRoots: params.mediaLocalRoots,
|
||||
mediaReadFile: params.mediaReadFile,
|
||||
forceDocument: params.forceDocument ?? false,
|
||||
});
|
||||
},
|
||||
}),
|
||||
sendPayload: async ({
|
||||
cfg,
|
||||
to,
|
||||
payload,
|
||||
mediaLocalRoots,
|
||||
mediaReadFile,
|
||||
accountId,
|
||||
deps,
|
||||
replyToId,
|
||||
threadId,
|
||||
formatting,
|
||||
forceDocument,
|
||||
silent,
|
||||
gatewayClientScopes,
|
||||
}) => {
|
||||
const outboundTo = normalizeTelegramOutboundTarget(to);
|
||||
const { send, baseOpts } = await resolveTelegramSendContext({
|
||||
cfg,
|
||||
deps,
|
||||
accountId,
|
||||
replyToId,
|
||||
threadId,
|
||||
formatting,
|
||||
silent,
|
||||
gatewayClientScopes,
|
||||
sendPayload: async (params) => {
|
||||
const { outboundTo, send, baseOpts } = await resolveTelegramOutboundSendContext({
|
||||
...params,
|
||||
resolveSend,
|
||||
});
|
||||
const result = await sendTelegramPayloadMessages({
|
||||
send,
|
||||
to: outboundTo,
|
||||
payload,
|
||||
payload: params.payload,
|
||||
baseOpts: {
|
||||
...baseOpts,
|
||||
mediaLocalRoots,
|
||||
mediaReadFile,
|
||||
forceDocument: forceDocument ?? false,
|
||||
mediaLocalRoots: params.mediaLocalRoots,
|
||||
mediaReadFile: params.mediaReadFile,
|
||||
forceDocument: params.forceDocument ?? false,
|
||||
},
|
||||
});
|
||||
return attachChannelToResult("telegram", result);
|
||||
|
||||
Reference in New Issue
Block a user