mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 14:11:26 +00:00
refactor(telegram): share chat lookup types
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
resolveTelegramForumFlag,
|
||||
resolveTelegramThreadSpec,
|
||||
} from "./bot/helpers.js";
|
||||
import type { TelegramGetChat } from "./bot/types.js";
|
||||
import {
|
||||
resolveTelegramConversationBaseSessionKey,
|
||||
resolveTelegramConversationRoute,
|
||||
@@ -74,17 +75,16 @@ export const buildTelegramMessageContext = async ({
|
||||
messageId: number,
|
||||
reactions: Array<{ type: "emoji"; emoji: string }>,
|
||||
) => Promise<void>;
|
||||
getChat?: (chatId: number | string) => Promise<unknown>;
|
||||
};
|
||||
const reactionApi =
|
||||
typeof api.setMessageReaction === "function" ? api.setMessageReaction.bind(api) : null;
|
||||
const getChatApi = typeof api.getChat === "function" ? api.getChat.bind(api) : null;
|
||||
const getChatApi: TelegramGetChat = bot.api.getChat.bind(bot.api);
|
||||
const isForum = await resolveTelegramForumFlag({
|
||||
chatId,
|
||||
chatType: msg.chat.type,
|
||||
isGroup,
|
||||
isForum: (msg.chat as { is_forum?: boolean }).is_forum,
|
||||
getChat: getChatApi ?? undefined,
|
||||
getChat: getChatApi,
|
||||
});
|
||||
const threadSpec = resolveTelegramThreadSpec({
|
||||
isGroup,
|
||||
|
||||
@@ -9,7 +9,7 @@ import type {
|
||||
import { readChannelAllowFromStore } from "openclaw/plugin-sdk/conversation-runtime";
|
||||
import { normalizeAccountId } from "openclaw/plugin-sdk/routing";
|
||||
import { firstDefined, normalizeAllowFrom, type NormalizedAllowFrom } from "../bot-access.js";
|
||||
import type { TelegramStreamMode } from "./types.js";
|
||||
import type { TelegramGetChat, TelegramStreamMode } from "./types.js";
|
||||
|
||||
const TELEGRAM_GENERAL_TOPIC_ID = 1;
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function resolveTelegramForumFlag(params: {
|
||||
chatType?: Chat["type"];
|
||||
isGroup: boolean;
|
||||
isForum?: boolean;
|
||||
getChat?: (chatId: string | number) => Promise<unknown>;
|
||||
getChat?: TelegramGetChat;
|
||||
}): Promise<boolean> {
|
||||
if (typeof params.isForum === "boolean") {
|
||||
return params.isForum;
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import type { Message, UserFromGetMe } from "@grammyjs/types";
|
||||
import type { ChatFullInfo, Message, UserFromGetMe } from "@grammyjs/types";
|
||||
|
||||
/** App-specific stream mode for Telegram stream previews. */
|
||||
export type TelegramStreamMode = "off" | "partial" | "block";
|
||||
|
||||
export type TelegramGetFile = () => Promise<{ file_path?: string }>;
|
||||
export type TelegramChatDetails = {
|
||||
available_reactions?: ChatFullInfo["available_reactions"];
|
||||
is_forum?: boolean;
|
||||
};
|
||||
export type TelegramGetChat = (chatId: number | string) => Promise<TelegramChatDetails>;
|
||||
|
||||
/**
|
||||
* Minimal context projection from Grammy's Context class.
|
||||
* Decouples the message processing pipeline from Grammy's full Context,
|
||||
@@ -11,7 +18,11 @@ export type TelegramStreamMode = "off" | "partial" | "block";
|
||||
export type TelegramContext = {
|
||||
message: Message;
|
||||
me?: UserFromGetMe;
|
||||
getFile: () => Promise<{ file_path?: string }>;
|
||||
getFile: TelegramGetFile;
|
||||
};
|
||||
|
||||
export type TelegramSyntheticContextSource = Pick<TelegramContext, "me"> & {
|
||||
getFile?: TelegramGetFile;
|
||||
};
|
||||
|
||||
/** Telegram sticker metadata for context enrichment and caching. */
|
||||
|
||||
Reference in New Issue
Block a user