Telegram Integration

This skill should be used when implementing Telegram bot functionality using teloxide.

first-fluke 39680bb 1.2 KB Updated

File contents

Telegram Integration

teloxide를 사용한 Telegram Bot 연동.

기본 설정

use teloxide::prelude::*;

#[tokio::main]
async fn main() {
    let bot = Bot::from_env();

    teloxide::repl(bot, |bot: Bot, msg: Message| async move {
        bot.send_message(msg.chat.id, "Hello!").await?;
        Ok(())
    })
    .await;
}

환경 변수

TELOXIDE_TOKEN=your_bot_token

메시지 정규화

fn normalize_telegram_message(msg: &Message) -> NormalizedMessage {
    NormalizedMessage {
        id: Uuid::new_v4(),
        channel: Channel::Telegram { chat_id: msg.chat.id.0 },
        user_id: msg.from().map(|u| u.id.0.to_string()).unwrap_or_default(),
        text: msg.text().unwrap_or_default().to_string(),
        timestamp: Utc::now(),
    }
}

레이트리밋

use governor::{Quota, RateLimiter};
use std::num::NonZeroU32;

// Telegram: 30 msg/sec (global), 1 msg/sec (per chat)
let limiter = RateLimiter::direct(
    Quota::per_second(NonZeroU32::new(30).unwrap())
);

참조

  • .cratos/skills/channel-agent/resources/telegram-guide.md

first-fluke/cratos/tree/main/.cratos/skills/telegram-integration commit 39680bbda3

Frequently asked questions

npx skillmds@latest add first-fluke/telegram-integration