An interface for Telegram bots to send AI-generated memes from imgflip.
You can check out @AiMemesBot on Telegram.
Please note that I didn't get permission from imgflip for this. I am using an undocumented API that is being called when you generate a meme on their website. I have no idea how to implement an AI like this - I am just a web developer who knows how to communicate with REST interfaces and wanted to create something funny and wasted two days on it.
See https://core.telegram.org/bots#6-botfather.
/setinline
/setinlinefeedback Enabled
/setcommands /empty
/setjoingroups Disable
Copy functions/src/config.json.template
to functions/src/config.json
and set the properties to the following:
telegramBotToken
is your bot's token which was provided by the BotFather when you set up the bot.imgflipUsername
username of any imgflip account (set one up here)imgflipPassword
the account's password - in unencoded textmaintainer
your telegram handle/username without the leading @selfUrl
the url the functions will be available at
Message the bot you created in a private message a /start
.
After that it will remember this chat as the maintainer chat and report errors in this chat.
You need to set/maintain two properties via this chat.
-
The imgFlip token - this is where it gets dodgy.
Open https://imgflip.com/ai-meme in your browser (preferably a private tab), open the DevTools and go the the Network tab.
Now click on one of the memes. You'll see a POST to
ajax_ai_meme
. In the Form Data there'll be a __tok. Copy the value and set it as yourimgflipToken
The token might be getting invalidated every so often, so if you get an error via the maintainer chat, try getting a fresh token and setting it.
-
The imgflip Cookie
from the same request, the cookie
iflipsess
i.e. in the Headers there will be a cookie string like
__cfduid=abcdef; iflipsess=XXX; rootkey=abcdef
- copy theXXX
To set these simply send in two separate messages:
-
token <token>
, e.g.token aBcDeFgHijKlMnOpQrStUvbWjabBq2NK292NfUsZHEc=
-
cookie <cookie>
, e.g.cookie abcdef9ghni1klmioi12msdbaj
bot-utils.js in the project root is a small commandline-tool for one-time setup with Telegram and health-checking after deployment.
Execute with node bot-utils.js
and see usage with node bot-utils.js --help
POST https://imgflip.com/ajax_ai_meme
accept: application/json, text/javascript, */*; q=0.01
content-type: application/x-www-form-urlencoded; charset=UTF-8
cookie: iflipsess=hqs89rnb8bgdnovpe6frmu6baj
-
More memes than shown on https://imgflip.com/ai-meme do work
e.g.
28251713
("Oprah Giveaway") returns{ "texts": [ "you get an email! you get an email!", "everyone gets an email!!!" ], "final_text": "you get an email! you get an email!|everyone gets an email!!!|" }
-
Some memes from this list don't work
e.g.
29617627
("Look at Me") returns{ "error": "Whoops, that meme failed to generate, try again in a minute" }