ahmedgomaaeid / message
send messages library
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ahmedgomaaeid/message
Requires
- php: ^8.1
README
A powerful Laravel package for sending messages to multiple messaging platforms with an elegant fluent API.
✨ Features
- 🚀 Easy Integration - Simple Laravel package installation
- 💬 Multiple Platforms - Support for various messaging services
- 🎯 Fluent API - Elegant method chaining for message composition
- 📝 Rich Formatting - Bold text, lists, line breaks, and more
- ⚙️ Auto Configuration - Automatic chat ID detection for Telegram
- 🔒 Secure - Environment-based configuration
📋 Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
- PHP ext-zip extension (for dependencies)
📦 Supported Platforms
- Telegram ✅
- More platforms coming soon...
🚀 Installation
Install the package via Composer:
composer require ahmedgomaaeid/message
Laravel Setup
The package will automatically register its service provider. If you need to register it manually, add to config/app.php:
'providers' => [ // Other providers... AhmedGomaaEid\Message\MessageServiceProvider::class, ],
⚙️ Configuration
Telegram Configuration
- Add your bot token to your
.envfile:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
- Get your Chat ID (First time setup):
- Send any message to your Telegram bot
- Visit:
https://your-app-url.com/telegram-chat-id-taker - The chat ID will be automatically saved to your
.envfile
📖 Usage Examples
🔹 Basic Telegram Message
use AhmedGomaaEid\Message\Classes\TelegramMessage; $message = new TelegramMessage(); $message->addLine('Hello from Laravel!') ->addBoldText('This is bold text') ->send();
🔹 Rich Formatted Message
use AhmedGomaaEid\Message\Classes\TelegramMessage; $message = new TelegramMessage(); // Create a list of items $todoList = [ 'Complete project documentation', 'Review pull requests', 'Deploy to production', 'Update team on progress' ]; $message->addBoldText('📋 Daily Tasks') ->addLine('Here are today\'s important tasks:') ->addList($todoList) ->addLine('') ->addLine('Please complete by end of day. 🎯') ->send();
🔹 System Notifications
use AhmedGomaaEid\Message\Classes\TelegramMessage; // Example: Order notification $message = new TelegramMessage(); $message->addBoldText('🛒 New Order Received!') ->addLine('Order ID: #12345') ->addLine('Customer: John Doe') ->addLine('Amount: $199.99') ->addLine('Status: Processing') ->addLink('View Order', 'https://your-app-url.com/orders/12345') ->send();
🔹 Available Methods
$message = new TelegramMessage(); // Text formatting $message->addLine('Regular text line'); $message->addBoldText('Bold text'); // Lists $message->addList(['Item 1', 'Item 2', 'Item 3']); // List with key-value pairs $message->addListWithKeyValue(['Key1' => 'Value1', 'Key2' => 'Value2']); // Hyperlinks $message->addLink('Click Here', 'https://example.com'); // Send the message $message->send();
🛠️ Available Methods
| Method | Description | Example |
|---|---|---|
addLine($text) |
Add a regular text line | ->addLine('Hello World') |
addBoldText($text) |
Add bold formatted text | ->addBoldText('Important!') |
addList($array) |
Add a bulleted list | ->addList(['A', 'B', 'C']) |
addListWithKeyValue($array) |
Add a list with key-value pairs | ->addListWithKeyValue(['Key1' => 'Value1', 'Key2' => 'Value2']) |
addLink($text, $url) |
Add a hyperlink | ->addLink('Click Here', 'https://example.com') |
send() |
Send the composed message | ->send() |
🔧 Troubleshooting
Common Issues
1. "Bot token not configured" error:
- Ensure
TELEGRAM_BOT_TOKENis set in your.envfile - Verify the token is correct (get it from @BotFather)
2. "Chat ID not found" error:
- Visit
/telegram-chat-id-takerto set up chat ID - Make sure you've sent at least one message to your bot first
3. Messages not sending:
- Check your internet connection
- Verify bot token permissions
- Ensure chat ID is correct
Getting Help
- Check the Laravel Log for detailed error messages
- Verify your
.envconfiguration - Test your bot token using Telegram's API directly
🎯 Use Cases
This package is perfect for:
- System Notifications - Server alerts, error notifications
- Order Updates - E-commerce order status updates
- Daily Reports - Automated daily/weekly summaries
- User Notifications - Account updates, reminders
- Marketing Messages - Promotional campaigns
- Team Communication - Development team notifications
📝 License
This package is open-sourced software licensed under the MIT license.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
🙏 Credits
Created by Ahmed Gomaa Eid