@idiomark/adapter-telegram
Telegram adapter for Idiomark extraction.
Features
- Messages: Text messages from private and group chats
- Edits: Track edited messages and their edit history
- Forwarded Content: Identify and track forwarded messages
- Channels: Fetch channel posts and metadata
- Rate Limiting: Built-in handling for Telegram's 30 messages/second limit
Authentication
Uses Bot token authentication via the Telegram Bot API.
Get your bot token from @BotFather on Telegram.
Rate Limits
- Requests: 30 per second for bots
- Tier Support: Bot and userbot tiers
- Documentation: https://core.telegram.org/bots/api
Usage
import { TelegramAdapter, createTelegramAdapter } from '@idiomark/adapter-telegram'
// Using the class directly
const adapter = new TelegramAdapter({
botToken: 'your_bot_token'
})
// Or using the convenience function
const adapter = createTelegramAdapter('your_bot_token', {
tier: 'bot' // or 'userbot'
})
// Authenticate
await adapter.authenticate()
// Fetch messages
const messages = await adapter.fetchMessages({
limit: 100,
includeForwarded: true
})
// Fetch channel posts
const channelPosts = await adapter.fetchChannelPosts({
limit: 50,
channelIds: ['@mychannel']
})
// Fetch edited messages
const editedMessages = await adapter.fetchEditedMessages({
limit: 50
})
// Get structured output for Idiomark analysis
const output = await adapter.getStructuredOutput({
limit: 100,
includeChannelPosts: true,
includeEditedMessages: true,
includeForwarded: true
})
Data Types
| Type | Description |
|---|---|
message | Direct messages with entities (hashtags, mentions, URLs) |
channel_post | Posts from channels |
edited_message | Messages that have been edited |
forwarded | Messages forwarded from other chats/users |
Options
| Option | Type | Default | Description |
|---|---|---|---|
limit | number | 100 | Maximum number of messages to fetch |
startDate | Date | - | Only fetch messages after this date |
endDate | Date | - | Only fetch messages before this date |
channelIds | string[] | - | Specific channel IDs/usernames to fetch from |
includeChannelPosts | boolean | false | Include channel posts in results |
includeEditedMessages | boolean | false | Include edited messages in results |
includeForwarded | boolean | true | Include forwarded messages in results |
Error Handling
The adapter includes specific error types:
TelegramAdapterError- Base error classTelegramAuthError- Authentication failuresTelegramRateLimitError- Rate limit exceededTelegramFetchError- Data fetching errors
Personality Signals
The adapter extracts the following personality signals:
- Voice: Hashtags, emoji usage, common phrases
- Communication: Message counts, reply patterns, edit frequency
- Interests: Topics from hashtags and mentions
- Sharing: Forwarded message analysis
License
MIT