From 72b0ae0133f8832c1738e584963a08ad2c4e9c4c Mon Sep 17 00:00:00 2001 From: kappa Date: Wed, 14 Jan 2026 13:57:21 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=85=94=EB=A0=88=EA=B7=B8=EB=9E=A8=20?= =?UTF-8?q?=EB=AF=B8=EB=8B=88=EC=95=B1=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sendMessageWithKeyboard 함수 추가 - /start 명령어에 미니앱 버튼 추가 - 메뉴 버튼으로 서비스 페이지 열기 지원 Co-Authored-By: Claude Opus 4.5 --- src/index.ts | 11 ++++++++++- src/telegram.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index d221b55..c38e626 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { Env, TelegramUpdate } from './types'; import { validateWebhookRequest, checkRateLimit } from './security'; -import { sendMessage, setWebhook, getWebhookInfo, sendChatAction } from './telegram'; +import { sendMessage, sendMessageWithKeyboard, setWebhook, getWebhookInfo, sendChatAction } from './telegram'; import { addToBuffer, processAndSummarize, @@ -76,6 +76,15 @@ async function handleMessage( const [command, ...argParts] = text.split(' '); const args = argParts.join(' '); responseText = await handleCommand(env, userId, chatIdStr, command, args); + + // /start 명령어는 미니앱 버튼과 함께 전송 + if (command === '/start') { + await sendMessageWithKeyboard(env.BOT_TOKEN, chatId, responseText, [ + [{ text: '🌐 서비스 보기', web_app: { url: 'https://anvil-hosting.pages.dev' } }], + [{ text: '💬 문의하기', url: 'https://t.me/AnvilForgeBot' }], + ]); + return; + } } else { // 타이핑 표시 await sendChatAction(env.BOT_TOKEN, chatId, 'typing'); diff --git a/src/telegram.ts b/src/telegram.ts index dda626a..55db0a5 100644 --- a/src/telegram.ts +++ b/src/telegram.ts @@ -82,6 +82,54 @@ export async function deleteWebhook( return response.json(); } +// 인라인 키보드 타입 +export interface InlineKeyboardButton { + text: string; + url?: string; + callback_data?: string; + web_app?: { url: string }; +} + +// 인라인 키보드와 함께 메시지 전송 +export async function sendMessageWithKeyboard( + token: string, + chatId: number, + text: string, + keyboard: InlineKeyboardButton[][], + options?: { + parse_mode?: 'HTML' | 'Markdown' | 'MarkdownV2'; + } +): Promise { + try { + const response = await fetch( + `https://api.telegram.org/bot${token}/sendMessage`, + { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + chat_id: chatId, + text, + parse_mode: options?.parse_mode || 'HTML', + reply_markup: { + inline_keyboard: keyboard, + }, + }), + } + ); + + if (!response.ok) { + const error = await response.text(); + console.error('Telegram API error:', error); + return false; + } + + return true; + } catch (error) { + console.error('Failed to send message with keyboard:', error); + return false; + } +} + // 타이핑 액션 전송 export async function sendChatAction( token: string,