Serverless Telegram bot template code for use with Firebase Cloud Functions
https://telegram.me/serverless_tgbot_example_bot
- Automatically initializes
functions.config()
from a localconfig.json
file. Includes module that provides the local copy if running insidefirebase serve --only functions
. - Organized Express.js stack
- Convenient
postdeploy
andpredeploy
actions. - Code generation with hygen (Try:
npx hygen route new <name>
) - OpenAPI integration with swagger-jsdoc. (See: Sample)
-
Clone your repo
git clone <YOUR REPOSITORY>
-
Install dependencies (this will generate a
config.json
file)cd functions && npm install
-
Edit
.firebaserc
to represent your Firebase project information. -
Edit
config.json
to set your information. This information is automatically set as firebase environment configurations in functions/scripts/predeploy.js:{ "telegram": { "bot_token": "77777777:Alskdjaslkdjasl-kjLKjlkasddd", "webhook_secret": "mysecretendpoint" }, "gcp": { "datacenter": "us-central1", "project_id": "serverless-bot" } }
-
(Optional) Write your own bot logic code in functions/src/lib/bot/controller.js. For testing your environment and deployment, you can leave it as is and test the build-in
/start
command.// in functions/src/lib/bot/controller.js // ... const Telegraf = require('telegraf') const bot = new Telegraf(config.telegram.bot_token, { telegram: { webhookReply: true } }) bot.command('start', ctx => { return ctx.reply('Hello from Cloud Function') }) // ...
-
When ready, deploy to Firebase:
firebase deploy
-
See if your Telegram bot responds: