Telegram Bot Crashlytics

Telegram Bot Crashlytics is a package that works with the Dio library to send application errors directly to Telegram. With this package, you can send errors from your app to your Telegram group or channel in real-time.

Created by JaysonKhan

Features

  • Automatic error reporting to Telegram.
  • Monitors any HTTP errors via a Dio interceptor.
  • Allows sending additional messages (for example, user notifications or system status updates).
  • Retrieves detailed device information and appends it to error messages for enhanced debugging.
  • Lets you selectively ignore specific HTTP status codes with the ignoreStatusCodes parameter.

Installation

Add the following line to your pubspec.yaml file:

dependencies:
  telegram_bot_crashlytics: ^1.1.0

Or, install it via the command line:

flutter pub add telegram_bot_crashlytics

Usage

1. Creating a Bot

To create a new bot in Telegram, contact BotFather and obtain the bot token.

How to get bot token How to get chat ID

2. Obtaining the Telegram Chat ID

Identify the Chat ID of the group or channel where you want to receive messages. You can find this by sending a message to yourself or the bot and then accessing it through the API:

https://api.telegram.org/bot<your-bot-token>/getUpdates

3. Verifying the Result from Chat

After sending a test message, you should see a response similar to the following:

Result from chat

4. Setting up Telegram Bot Crashlytics

Configure the package in your app as follows:

import 'package:telegram_bot_crashlytics/telegram_bot_crashlytics.dart';

void main() {
  // Set up Telegram Bot Crashlytics
  final telegramCrashlytics = TelegramBotCrashlytics(
    botToken: 'YOUR_BOT_TOKEN',
    chatId: YOUR_CHAT_ID,
    ignoreStatusCodes: [400, 404], // Add ignored status codes here
  );

  // Set up Dio and add the interceptor
  final dio = Dio();
  dio.interceptors.add(telegramCrashlytics.interceptor);
}

5. Monitoring Errors

When making HTTP requests with Dio, errors are automatically sent to Telegram via the interceptor.

If you want to manually send a message outside of Dio errors:

await telegramCrashlytics.sendErrorToTelegram("Describe the error here.");
await telegramCrashlytics.sendInfoToTelegram("Provide additional information here.");

Additional Settings

  • Device Information:

    • Automatically adds device details (e.g., Android model, iOS version) to error messages.
    • Each device type is represented with an emoji sticker for quick identification in Telegram.
  • Selective Ignoring of HTTP Status Codes:

    • Use the ignoreStatusCodes parameter to exclude specific status codes from being sent to Telegram.

Example

// Executing HTTP request with Dio
final response = await dio.get('https://jsonplaceholder.typicode.com/posts');

// If an error occurs, it will be automatically sent to Telegram by the interceptor.

Join Our Channel

Join our Telegram channel for updates and Flutter tips: @FlutterMarkazi


Support the Project

If you like this project and want to support me, consider buying me a coffee or donating via USDT TRC20:

  • Buy Me a Coffee: KHAN347
  • USDT TRC20 Wallet: TPXnvYAYcsf1tMrqWfpmDy5swFpiJ737br

Libraries

dart_telegram_bot/dart_telegram_bot
dart_telegram_bot/src/entities/internal/bot
dart_telegram_bot/src/entities/internal/entities/chat_id
dart_telegram_bot/src/entities/internal/entities/http_file
dart_telegram_bot/src/entities/internal/exceptions/api_exceptions
dart_telegram_bot/src/entities/internal/exceptions/lib_exceptions
dart_telegram_bot/src/entities/internal/helpers/bot_command_parser
dart_telegram_bot/src/entities/internal/helpers/util
dart_telegram_bot/src/entities/internal/tgapi_client
dart_telegram_bot/src/entities/internal/tgapi_methods
dart_telegram_bot/src/entities/telegram/animation
dart_telegram_bot/src/entities/telegram/audio
dart_telegram_bot/src/entities/telegram/bot_command
dart_telegram_bot/src/entities/telegram/bot_command_scope
dart_telegram_bot/src/entities/telegram/bot_command_scope_all_chat_administrators
dart_telegram_bot/src/entities/telegram/bot_command_scope_all_group_chats
dart_telegram_bot/src/entities/telegram/bot_command_scope_all_private_chats
dart_telegram_bot/src/entities/telegram/bot_command_scope_chat
dart_telegram_bot/src/entities/telegram/bot_command_scope_chat_administrators
dart_telegram_bot/src/entities/telegram/bot_command_scope_chat_member
dart_telegram_bot/src/entities/telegram/bot_command_scope_default
dart_telegram_bot/src/entities/telegram/bot_description
dart_telegram_bot/src/entities/telegram/bot_name
dart_telegram_bot/src/entities/telegram/bot_short_description
dart_telegram_bot/src/entities/telegram/callback_game
dart_telegram_bot/src/entities/telegram/callback_query
dart_telegram_bot/src/entities/telegram/chat
dart_telegram_bot/src/entities/telegram/chat_administrator_rights
dart_telegram_bot/src/entities/telegram/chat_join_request
dart_telegram_bot/src/entities/telegram/chat_location
dart_telegram_bot/src/entities/telegram/chat_member
dart_telegram_bot/src/entities/telegram/chat_member_updated
dart_telegram_bot/src/entities/telegram/chat_permissions
dart_telegram_bot/src/entities/telegram/chat_photo
dart_telegram_bot/src/entities/telegram/chat_shared
dart_telegram_bot/src/entities/telegram/chosen_inline_result
dart_telegram_bot/src/entities/telegram/contact
dart_telegram_bot/src/entities/telegram/dice
dart_telegram_bot/src/entities/telegram/document
dart_telegram_bot/src/entities/telegram/encrypted_credentials
dart_telegram_bot/src/entities/telegram/encrypted_passport_element
dart_telegram_bot/src/entities/telegram/enums
dart_telegram_bot/src/entities/telegram/file
dart_telegram_bot/src/entities/telegram/force_reply
dart_telegram_bot/src/entities/telegram/forum_topic
dart_telegram_bot/src/entities/telegram/forum_topic_closed
dart_telegram_bot/src/entities/telegram/forum_topic_created
dart_telegram_bot/src/entities/telegram/forum_topic_edited
dart_telegram_bot/src/entities/telegram/forum_topic_reopened
dart_telegram_bot/src/entities/telegram/game
dart_telegram_bot/src/entities/telegram/game_high_score
dart_telegram_bot/src/entities/telegram/general_forum_topic_hidden
dart_telegram_bot/src/entities/telegram/general_forum_topic_unhidden
dart_telegram_bot/src/entities/telegram/inline_keyboard_button
dart_telegram_bot/src/entities/telegram/inline_keyboard_markup
dart_telegram_bot/src/entities/telegram/inline_query
dart_telegram_bot/src/entities/telegram/inline_query_result
dart_telegram_bot/src/entities/telegram/inline_query_result_article
dart_telegram_bot/src/entities/telegram/inline_query_result_audio
dart_telegram_bot/src/entities/telegram/inline_query_result_cached_audio
dart_telegram_bot/src/entities/telegram/inline_query_result_cached_document
dart_telegram_bot/src/entities/telegram/inline_query_result_cached_gif
dart_telegram_bot/src/entities/telegram/inline_query_result_cached_mpeg4_gif
dart_telegram_bot/src/entities/telegram/inline_query_result_cached_photo
dart_telegram_bot/src/entities/telegram/inline_query_result_cached_sticker
dart_telegram_bot/src/entities/telegram/inline_query_result_cached_video
dart_telegram_bot/src/entities/telegram/inline_query_result_cached_voice
dart_telegram_bot/src/entities/telegram/inline_query_result_contact
dart_telegram_bot/src/entities/telegram/inline_query_result_document
dart_telegram_bot/src/entities/telegram/inline_query_result_game
dart_telegram_bot/src/entities/telegram/inline_query_result_gif
dart_telegram_bot/src/entities/telegram/inline_query_result_location
dart_telegram_bot/src/entities/telegram/inline_query_result_mpeg4_gif
dart_telegram_bot/src/entities/telegram/inline_query_result_photo
dart_telegram_bot/src/entities/telegram/inline_query_result_venue
dart_telegram_bot/src/entities/telegram/inline_query_result_video
dart_telegram_bot/src/entities/telegram/inline_query_result_voice
dart_telegram_bot/src/entities/telegram/inline_query_results_button
dart_telegram_bot/src/entities/telegram/input_contact_message_content
dart_telegram_bot/src/entities/telegram/input_location_message_content
dart_telegram_bot/src/entities/telegram/input_media
dart_telegram_bot/src/entities/telegram/input_media_animation
dart_telegram_bot/src/entities/telegram/input_media_audio
dart_telegram_bot/src/entities/telegram/input_media_document
dart_telegram_bot/src/entities/telegram/input_media_photo
dart_telegram_bot/src/entities/telegram/input_media_video
dart_telegram_bot/src/entities/telegram/input_message_content
dart_telegram_bot/src/entities/telegram/input_sticker
dart_telegram_bot/src/entities/telegram/input_text_message_content
dart_telegram_bot/src/entities/telegram/input_venue_message_content
dart_telegram_bot/src/entities/telegram/invoice
dart_telegram_bot/src/entities/telegram/keyboard_button
dart_telegram_bot/src/entities/telegram/keyboard_button_poll_type
dart_telegram_bot/src/entities/telegram/keyboard_button_request_chat
dart_telegram_bot/src/entities/telegram/keyboard_button_request_user
dart_telegram_bot/src/entities/telegram/labeled_price
dart_telegram_bot/src/entities/telegram/location
dart_telegram_bot/src/entities/telegram/login_url
dart_telegram_bot/src/entities/telegram/mask_position
dart_telegram_bot/src/entities/telegram/message
dart_telegram_bot/src/entities/telegram/message_auto_delete_timer_changed
dart_telegram_bot/src/entities/telegram/message_entity
dart_telegram_bot/src/entities/telegram/message_id
dart_telegram_bot/src/entities/telegram/order_info
dart_telegram_bot/src/entities/telegram/passport_data
dart_telegram_bot/src/entities/telegram/passport_file
dart_telegram_bot/src/entities/telegram/photo_size
dart_telegram_bot/src/entities/telegram/poll
dart_telegram_bot/src/entities/telegram/poll_answer
dart_telegram_bot/src/entities/telegram/poll_option
dart_telegram_bot/src/entities/telegram/pre_checkout_query
dart_telegram_bot/src/entities/telegram/proximity_alert_triggered
dart_telegram_bot/src/entities/telegram/reply_keyboard_markup
dart_telegram_bot/src/entities/telegram/reply_keyboard_remove
dart_telegram_bot/src/entities/telegram/reply_markup
dart_telegram_bot/src/entities/telegram/response_parameters
dart_telegram_bot/src/entities/telegram/sent_web_app_message
dart_telegram_bot/src/entities/telegram/shipping_address
dart_telegram_bot/src/entities/telegram/shipping_option
dart_telegram_bot/src/entities/telegram/shipping_query
dart_telegram_bot/src/entities/telegram/sticker
dart_telegram_bot/src/entities/telegram/sticker_set
dart_telegram_bot/src/entities/telegram/story
dart_telegram_bot/src/entities/telegram/successful_payment
dart_telegram_bot/src/entities/telegram/switch_inline_query_chosen_chat
dart_telegram_bot/src/entities/telegram/update
dart_telegram_bot/src/entities/telegram/user
dart_telegram_bot/src/entities/telegram/user_profile_photos
dart_telegram_bot/src/entities/telegram/user_shared
dart_telegram_bot/src/entities/telegram/venue
dart_telegram_bot/src/entities/telegram/video
dart_telegram_bot/src/entities/telegram/video_chat_ended
dart_telegram_bot/src/entities/telegram/video_chat_participants_invited
dart_telegram_bot/src/entities/telegram/video_chat_scheduled
dart_telegram_bot/src/entities/telegram/video_chat_started
dart_telegram_bot/src/entities/telegram/video_note
dart_telegram_bot/src/entities/telegram/voice
dart_telegram_bot/src/entities/telegram/web_app_data
dart_telegram_bot/src/entities/telegram/web_app_info
dart_telegram_bot/src/entities/telegram/write_access_allowed
dart_telegram_bot/telegram_entities
interceptor/telegram_error_interceptor
telegram_bot_crashlytics