Files
openhuman/src/lib/telegram/api/pressInlineButton.ts
T
Steven Enamakel 95e06bc54a Refactor Telegram MCP integration and add new API functionalities
- Updated import paths for Telegram types and API functions to improve module organization.
- Introduced new helper functions for reading typed values from MCP tool arguments.
- Added comprehensive API functions for managing Telegram contacts, chats, and messages, including creating groups, channels, and polls.
- Implemented a tool action parser to convert tool inputs into human-readable descriptions.
- Added tests for new functionalities to ensure reliability and correctness.

This update enhances the Telegram MCP server's capabilities and improves code maintainability.
2026-01-31 00:51:52 +05:30

42 lines
1.2 KiB
TypeScript

/**
* API: Press inline button
*/
import { mtprotoService } from "../../../services/mtprotoService";
import { getChatById } from "./helpers";
import type { ApiResult } from "./types";
import type { BotCallbackAnswer } from "./apiResultTypes";
import { Api } from "telegram";
import { narrow } from "./apiCastHelpers";
export async function pressInlineButton(
chatId: string | number,
messageId: number,
buttonData: string
): Promise<ApiResult<string>> {
const chat = getChatById(chatId);
if (!chat) {
throw new Error(`Chat not found: ${chatId}`);
}
const client = mtprotoService.getClient();
const entity = chat.username ? `@${chat.username.replace("@", "")}` : chat.id;
const result = await mtprotoService.withFloodWaitHandling(async () => {
const inputPeer = await client.getInputEntity(entity);
return client.invoke(
new Api.messages.GetBotCallbackAnswer({
peer: inputPeer,
msgId: messageId,
data: Buffer.from(buttonData, "base64"),
})
);
});
const answer =
narrow<BotCallbackAnswer>(result)?.message ??
"Button pressed (no response message).";
return { data: answer, fromCache: false };
}