Free serverless Telegram bot, powered by a Cloudflare Worker, is designed to automate tasks in group chat. Originally was created to daily poll 4 members of the party if they ready to go in the adventure.
Ask chatGpt directly from telegram
Dog on demand as service 🐕
Random gif 😻
Access to telegram API
- OpenAI API: Ask ChatGPT 3.5 / 4. This requires openAI token
- EpicGames API: Get updates on free games from the Epic Games Store.
- Giphy API: get random gif or specific tag
- DogCEO API: get random Dog Photo
- Chuck Norris API: joke about Chuck Norris
- Telegram API: Poll Creation from message or code
- Telegram API: Dice roll for random integer
You can schedule these actions using Cloudflare's cron timer. The bot also uses Cloudflare's D1 serverless SQL database for data storage.
Follow Telegram Bot Tutorial to:
- Create a bot using
@BotFather
and save its token to secretTELEGRAM_BOT_TOKEN
.
- Using
@BotFather
disable group privacy to let the bot see all messages. - Using
@BotFather
register keywords as commands for rendering in Telegram after "/".
- Create a worker.
- Set worker link as Telegram webhook.
https://api.telegram.org/bot{my_bot_token}/setWebhook?url={url_to_send_updates_to}
- Create new D1 database and
epicgames
table withid
(primary key int),chatid
(string), andgames
(string). - Create a new AI gateway for openAi.
- Create new token and save it to GitHub secrets if you want to deploy using GitHub actions.
- In
src/res/config.js
, setaiGateway
andepicTableName
that you get from cloudflare dashboard. - In
wrangler.toml
, set workername
, D1database_name
anddatabase_id
.
- To schedule actions: create desired cron timers in cloudflare dashboard, put them in
src/res/crons.js
, and link them to the routine insrc/action/scheduledMap.js
. - To use different keywords or language: change keywords in
src/res/keywords.js
. - To add new APIs/Actions:: Put new actions in
src/action/actions
and register them insrc/action/actionMap.js
orsrc/action/scheduledMap.js
for cron routines.
Store secrets in the GitHub repo for deployment through GitHub Actions. They'll be pushed to the Cloudflare dashboard. Alternatively, add secrets directly in the dashboard:
TELEGRAM_BOT_TOKEN
: To send data back in the Telegram chat.
CLOUDFLARE_API_TOKEN
: For bot deployment from GitHub actionsGIPHY_API_KEY
: To search for GIFs.OPENAI_API_KEY
: To chat with ChatGPT.
Feel free to use, change, and share this code as you like. No license attached. Pull requests are welcomed.
This project isn't officially associated with Cloudflare, Telegram, Epic Games, OpenAI, or Giphy. It's a standalone project, created for learning and fun, and comes as it is.