Telegram Bot Crashlytics
Telegram Bot Crashlytics is a package that works with the Dio
library to send application errors directly to Telegram and Slack. With this package, you can send errors from your app to your Telegram group, channel, or Slack workspace in real-time.
Features
- Automatic error reporting to Telegram and Slack.
- 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. - New: Supports sending formatted error messages to Slack using a Webhook URL.
- New: Include request headers in error messages using the
includeHeaders
parameter. - New: Errors are categorized with hashtags for HTTP method types and status codes.
Installation
Add the following line to your pubspec.yaml
file:
dependencies:
telegram_bot_crashlytics: ^1.3.3
Or, install it via the command line:
flutter pub add telegram_bot_crashlytics
Note: If you encounter any issues with the latest version, consider using version
1.2.4
for stability.
Usage
1. Creating a Bot
To create a new bot in Telegram, contact BotFather
and obtain the bot token.
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. Setting up Telegram Bot Crashlytics
Configure the package in your app as follows:
import 'package:telegram_bot_crashlytics/telegram_bot_crashlytics.dart';
void main() {
final telegramCrashlytics = TelegramBotCrashlytics(
botToken: 'YOUR_BOT_TOKEN',
chatId: YOUR_CHAT_ID,
ignoreStatusCodes: [400, 404], // Specify status codes to ignore
includeHeaders: true, // Include request headers in error messages
slackWebhookUrl: 'YOUR_SLACK_WEBHOOK_URL', // Optional: Slack integration
);
final dio = Dio();
dio.interceptors.add(telegramCrashlytics.interceptor);
}
4. Sending Errors Manually
When making HTTP requests with Dio
, errors are automatically sent to Telegram and Slack via the interceptor.
If you want to manually send a message outside of Dio errors:
// Send error messages manually to Telegram
await telegramCrashlytics.sendErrorToTelegram("Describe the error here.");
// Send informational messages manually to Telegram
await telegramCrashlytics.sendInfoToTelegram("Provide additional information here.");
5. Slack Integration
How to Get a Slack Webhook URL:
- Open Slack and navigate to your workspace.
- Go to Settings & Administration > Manage Apps.
- Search for "Incoming Webhooks" and add it to your workspace.
- Create a new Webhook and copy the generated URL.
- Pass the Webhook URL when initializing
TelegramBotCrashlytics
.
Slack Integration Example:
final telegramCrashlytics = TelegramBotCrashlytics(
botToken: 'YOUR_TELEGRAM_BOT_TOKEN',
chatId: YOUR_CHAT_ID,
ignoreStatusCodes: [],
includeHeaders: true,
slackWebhookUrl: 'YOUR_SLACK_WEBHOOK_URL', // Required for Slack
);
With Slack integration, all error messages are sent to your specified Slack channel.
6. 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.
-
Selective Ignoring of HTTP Status Codes:
- Use the
ignoreStatusCodes
parameter to exclude specific status codes from being sent to Telegram or Slack.
- Use the
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 and Slack 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
Check Out My Other Package!
Looking for efficient network caching for your HTTP requests? Check out my other Dart/Flutter package:
👉 Network Cache Interceptor
What’s New in 1.3.3?
- Added Slack Integration for sending errors to your Slack workspace via Webhook.
- Enhanced error formatting for both Telegram and Slack.
- Improved device-specific details for better debugging.
- Optimized request and response data logging.
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_invite_link
- 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/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/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/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/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/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