Skip to content

About

A Telegram bot that gets memes using an API to find memes on Reddit.

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

71 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Meme Bot - PoC

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

image

  • /meme - fetch a random meme from Reddit (chosen from either r/memes, r/dankmemes, or r/me_irl)

image

  • /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)

image

How does it work?

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.

image

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).

image

Can I make my own version of this bot?

Absolutely! However, there are a few things you will want to do first.

If you want to host your own Telegram bot based on this code, there are a few steps you need to take.

  1. Create a Telegram account
  2. 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)

image

  • 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.
  1. Clone this repo
  2. Create a .env file here: src/main/resources/.env
  3. Put the following values in the .env file, inputting your own bot username, API token, and ID. image
  • 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: image
  1. 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.

About

A Telegram bot that gets memes using an API to find memes on Reddit.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages