This repository is dedicated to a Telegram bot developed in the Go programming language, utilizing powerful libraries and API interactions to create a responsive and functional bot. This project is ideal for beginners looking to gain fundamental programming skills in Go and experience working with external APIs.
The purpose of this project is to develop a Telegram bot capable of processing and responding to user messages. By completing this project, developers will gain hands-on experience with Go, understand how to work with the Telegram Bot API, and learn how to design and implement bot functionality to interact with users.
- Language: Golang
- Frameworks/Libraries:
github.com/spf13/cobra
andgopkg.in/telebot.v3
- Functionality:
- Message handler functions that reply to user messages in Telegram.
- Integration of message handler functions into
telebot.Bot
methods. - Processing messages based on their type and content.
- Golang installed on your system.
- Basic understanding of Git and GitHub.
- A Telegram account to create and manage your bot.
-
Environment Setup: If you're using Codespaces, it comes pre-configured with the necessary settings. Otherwise, ensure Golang is correctly installed and set up on your system.
-
Project Initialization:
- Create a new project on GitHub and clone it to your local machine.
- Navigate to your project directory.
-
Dependencies:
- Add
github.com/spf13/cobra
to your project by importing it in your Go files. - Install
gopkg.in/telebot.v3
by runninggo get gopkg.in/telebot.v3
.
- Add
-
Telegram Bot Creation:
- Use BotFather in Telegram to create a new bot and obtain a bot token.
- Save the bot token in an environment variable
TELE_TOKEN
.
-
Development:
- Import the necessary libraries in your Go files.
- Create a
telebot.Bot
object with the bot token. - Implement message handler functions and attach them to the bot.
- Compile and run your bot to test its functionality.
- Compile your bot using
go build -ldflags "-X="github.com/illia-ilin/kbot/cmd.appVersion=v1.0.2
. - Run the compiled executable.
- Interact with your bot in Telegram to test its responses.
After setting up your bot and running it, you can interact with it on Telegram. Here's a simple command you can start with:
\start hello
Your bot should respond with a greeting message or a similar response based on your implementation.
Contributions are welcome! Please feel free to submit pull requests or create issues for bugs and feature requests.
Distributed under the MIT License. See LICENSE
for more information.
- This project was inspired by the desire to learn Golang and explore the capabilities of the Telegram Bot API.
- Thanks to the developers of
cobra
andtelebot.v3
for their excellent libraries that make bot development more accessible.