Skip to main content

@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​

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​

TypeDescription
messageDirect messages with entities (hashtags, mentions, URLs)
channel_postPosts from channels
edited_messageMessages that have been edited
forwardedMessages forwarded from other chats/users

Options​

OptionTypeDefaultDescription
limitnumber100Maximum number of messages to fetch
startDateDate-Only fetch messages after this date
endDateDate-Only fetch messages before this date
channelIdsstring[]-Specific channel IDs/usernames to fetch from
includeChannelPostsbooleanfalseInclude channel posts in results
includeEditedMessagesbooleanfalseInclude edited messages in results
includeForwardedbooleantrueInclude forwarded messages in results

Error Handling​

The adapter includes specific error types:

  • TelegramAdapterError - Base error class
  • TelegramAuthError - Authentication failures
  • TelegramRateLimitError - Rate limit exceeded
  • TelegramFetchError - 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