This repository contains a PHP script for creating a Telegram bot that leverages the Gemini API for enhanced functionalities. It's designed to handle user interactions in real-time, manage sessions, and provide custom responses based on user input. Get ready to launch your bot with interactive commands, session management, and seamless integration with Gemini API services!
Before diving in, ensure you have the following ready:
- A Telegram account.
- PHP environment with Composer installed.
- A server with SSL (HTTPS) support for the webhook setup.
- Access to the Gemini API via MarketSuite on Google Cloud Platform.
- Telegram Bot Token: Obtain your bot token by creating a bot through Telegram's BotFather. Replace
"BOT_TOKEN"in the script with your actual bot token. - Gemini API Key: Replace
'GOOGLE_API_FOR_GEMINI'with your actual Gemini API key obtained from the MarketSuite on Google Cloud Platform.
- Clone the Repository: Clone or download this repository to your server.
- Install Dependencies: Run
composer installto install the required PHP dependencies. - Configure Your Bot: Follow the configuration steps to set up your bot token and Gemini API key.
- Deploy: Upload the PHP script to your server. Ensure it's accessible via HTTPS.
- Set Up the Webhook: Configure the webhook to point to your script's URL using the Telegram API.
Set the webhook for your bot using the following URL, replacing <YOUR_BOT_TOKEN> and <YOUR_WEBHOOK_URL> with your information:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=<YOUR_WEBHOOK_URL>
Verify the webhook is set correctly:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getWebhookInfo
- Interactive Commands: Your bot supports various commands like
/start,/help,/end, and/devto engage users. - Session Management: Utilizes sessions to maintain context and continuity in conversations.
- Gemini API Integration: Enhances bot responses using the Gemini API for dynamic content generation.
- Custom Responses: Includes error handling and default prompts for a user-friendly experience.
Feel free to fork this repository, make changes, and submit pull requests. Contributions to enhance the bot's functionalities or documentation are always welcome!
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or suggestions, please reach out to me at:
- 📧 Email: maleeshaudan6@gmail.com
- 💼 GitHub: @MaleeshaUdan