Download the PHP package rmscms/telegram without Composer
On this page you can find all versions of the php package rmscms/telegram. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rmscms/telegram
More information about rmscms/telegram
Files in rmscms/telegram
Package telegram
Short Description A Telegram package for Laravel applications
License MIT
Informations about the package telegram
RMS Telegram Package for Laravel
A robust and fluent Telegram integration package for Laravel applications, built on top of irazasyed/telegram-bot-sdk. This package provides a chainable interface to interact with Telegram's API, enabling seamless sending of messages, photos, documents, media groups, and managing messages in Telegram channels.
Features
- Fluent Interface: Chainable methods for sending messages, photos, documents, and media groups.
- Custom Keyboards: Support for inline and reply keyboards with flexible button configurations.
- Parse Modes: Supports
HTML,MarkdownV2, and legacyMarkdownfor message formatting. - File Handling: Integrates with Laravel's
Storagefor seamless file uploads. - Comprehensive Testing: Built-in Artisan command to test all package features.
- Extensible: Easy to extend for additional Telegram API functionalities.
Installation
-
Install the Package
Add the package to your Laravel project via Composer:
-
Publish Configuration
Publish the configuration file to your project:
This creates a
config/telegram.phpfile in your Laravel project. -
Configure Environment
Add the following to your
.envfile:Ensure your bot is an admin in the specified channel.
Configuration
The config/telegram.php file contains:
Usage
The package uses a fluent, chainable interface for interacting with Telegram. Below are examples for each feature.
1. Sending a Text Message
2. Sending a Photo
Photos are loaded from Laravel's Storage disk (e.g., public). Ensure the file exists in storage/app/public.
3. Sending a Document
Documents are loaded from storage/app/public.
4. Sending a Media Group
Send multiple photos or videos in one message using MediaGroup.
5. Updating a Message or Caption
Update a text message or media caption using message_id.
6. Deleting a Message
Delete a message using message_id.
7. Pinning a Message
Pin a message in a channel using message_id.
8. Using Parse Modes
Supports HTML, MarkdownV2, and Markdown (legacy) parse modes. Default is HTML.
9. Creating Custom Keyboards
Use Keyboard and Button classes to create inline or reply keyboards.
Storage Configuration
The package uses Laravel's Storage for file handling. Ensure your config/filesystems.php has a public disk:
Place files in storage/app/public (e.g., images/photo.jpg, documents/file.pdf, videos/video.mp4).
Testing
The package includes a powerful Artisan command to validate all features:
Test Command Details
The telegram:test command executes a comprehensive suite of tests to verify the package's functionality:
- Send Text: Sends a text message with HTML formatting.
- Send Photo: Sends a photo with a caption and inline keyboard.
- Send Document: Sends a document with a caption and inline keyboard.
- Send Media Group: Sends a group of media (photo and video) with captions and an inline keyboard.
- Update Message: Updates the text of a previously sent message.
- Update Caption: Updates the caption of a previously sent photo.
- Pin Message: Pins a message in the channel.
- Delete Message: Deletes a message from the channel.
- Send Markdown: Sends a message with MarkdownV2 formatting.
- Send Inline Keyboard: Sends a message with an inline keyboard.
- Send Inline Keyboard (Reply): Sends a message with another inline keyboard (emulating reply keyboard behavior in channels).
The command automatically:
- Creates test files (
test.jpg,test.pdf,test.mp4) instorage/app/publicif they don't exist. - Runs all tests and displays results in a table.
- Cleans up test files after execution (with
--cleanoption).
Note: For the Send Media Group test, ensure a valid MP4 file is placed in storage/app/public/videos/test.mp4 (e.g., download from https://sample-videos.com). The command preserves existing files to avoid overwriting.
To run unit tests:
Contributing
Contributions are welcome! Please submit issues or pull requests to the GitHub repository.
License
This package is open-sourced under the MIT License.