50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
|
|
import { ApiSettings } from '../types';
|
|
|
|
/**
|
|
* Telegram Notification Client Service
|
|
* 프론트엔드에서는 백엔드에 알림 요청만 보내며,
|
|
* 실제 봇 호출 및 메시지 구성은 서버(백엔드)에서 안전하게 처리합니다.
|
|
*/
|
|
export class TelegramService {
|
|
private settings: ApiSettings;
|
|
|
|
constructor(settings: ApiSettings) {
|
|
this.settings = settings;
|
|
}
|
|
|
|
/**
|
|
* 백엔드 알림 API를 호출합니다.
|
|
* 백엔드 엔진은 사용자가 브라우저를 닫아도 독립적으로 이 로직을 수행합니다.
|
|
*/
|
|
async sendMessage(message: string): Promise<boolean> {
|
|
if (!this.settings.useTelegram) return false;
|
|
|
|
console.log(`[Frontend] 요청된 알림 메시지: ${message}`);
|
|
|
|
try {
|
|
// 실제 환경에서는 백엔드 API 호출:
|
|
// const response = await fetch('/api/notify/send', {
|
|
// method: 'POST',
|
|
// headers: { 'Content-Type': 'application/json' },
|
|
// body: JSON.stringify({ message })
|
|
// });
|
|
// return response.ok;
|
|
|
|
return true; // 데모용 성공 반환
|
|
} catch (e) {
|
|
console.error("Telegram notification request failed", e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 설정 페이지에서 알림 연결 테스트용
|
|
*/
|
|
async testConnection(token: string, chatId: string): Promise<{success: boolean, msg: string}> {
|
|
console.log("Telegram: Testing connection through backend...");
|
|
// 백엔드 /api/notify/test 호출 로직
|
|
return { success: true, msg: "테스트 메시지가 발송되었습니다." };
|
|
}
|
|
}
|