This is a simple Telegram bot that finds memes based on an API, and then sends the memes to the user that requested them as a Telegram message.
I'm, currently not hosting this bot. To try out the bot, open the following link t.me/connors_meme_bot and send him some messages (you need a Telegram account to do so).
Here is a list of current supported commands by the bot:
/start- show welcome command and usage
/meme- fetch a random meme from Reddit (chosen from either r/memes, r/dankmemes, or r/me_irl)
/source- fetch a random meme from a specific subreddit (Currently supported subreddits are r/memes, r/dankmemes, r/wholesomememes, r/nsfwmemes, r/4chan, and r/greentext. This is subject to change in the future)
The bot uses the Telegram Bot API to register the bot with Telegram's servers. Then, the bot constantly polls the servers with a request to get any updates since the last poll. In this project, I'm specifically using the TelegramBots Java library to interact with the Bot API.
Once the bot receives an update, we check the contents of the update (whether or not it was a command sent by text, or a callbackQuery sent via button click). We then take action based on the content of the update.
In our case, the action being taken is sending a GET request to the meme-api.com API, which scrapes various subreddits on Reddit for memes, and returns the JSON data of the meme.
We parse the JSON data and return it to the users in a nicely formatted message.
We can even make decisions based on the JSON data, such as whether or not to blur an image if it is marked at Not Safe for Work (NSFW).
Absolutely! However, there are a few things you will want to do first.
- Create a Telegram account and get familiar with the UI and various Telegram features.
- Download any JDK version 22 or newer (version 22 is what this project was built with).
- IMPORTANT -> If you are unfamiliar with the Telegram API and how it works, go check out this super helpful tutorial by Telegram which walks you through building out a Telegram Bot in Java.
If you want to host your own Telegram bot based on this code, there are a few steps you need to take.
- Create a Telegram account
- Create a bot using the @BotFather bot in Telegram (this is how you get the bot username and bot API token to interact with your bot)
- Note: do not expose your API token to anybody. It allows anybody to control this bot from anywhere. This token in the picture will not work if you try to use it since I have revoked it. I'll be using it for this tutorial though.
- Clone this repo
- Create a
.envfile here:src/main/resources/.env - Put the following values in the
.envfile, inputting your own bot username, API token, and ID.
- If you don't know what to put in TELEGRAM_MY_ID, this is your Telegram user ID, if you follow the Bot tutorial by Telegram they will go into more detail on this. You don't need a valid number here, this is just to alert you every time your bot starts up. This should not affect the functionality of the bot.
- Here is an example of the notification:

- Run the project. No need to set up any crazy servers, forward any ports, etc. The bot will just work. You can now message the bot and it should start sending you memes.





