https://github.com/au5ton/serverless-bot
🛰 [indev] Serverless Telegram bot template code for use with Firebase Cloud Functions
https://github.com/au5ton/serverless-bot
firebase serverless telegram-bot
Last synced: about 1 year ago
JSON representation
🛰 [indev] Serverless Telegram bot template code for use with Firebase Cloud Functions
- Host: GitHub
- URL: https://github.com/au5ton/serverless-bot
- Owner: au5ton
- Created: 2020-02-23T04:38:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T21:56:14.000Z (about 3 years ago)
- Last Synced: 2024-05-02T06:01:10.480Z (almost 2 years ago)
- Topics: firebase, serverless, telegram-bot
- Language: JavaScript
- Homepage:
- Size: 345 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
serverless-bot
==============
Serverless Telegram bot template code for use with Firebase Cloud Functions
## Demo
https://telegram.me/serverless_tgbot_example_bot
## Features
- Automatically initializes [`functions.config()`](https://firebase.google.com/docs/functions/config-env) from a local `config.json` file. Includes module that provides the local copy if running inside `firebase serve --only functions`.
- Organized Express.js stack
- Convenient `postdeploy` and `predeploy` actions.
- Code generation with [hygen](https://github.com/jondot/hygen) (Try: `npx hygen route new `)
- OpenAPI integration with [swagger-jsdoc](https://github.com/Surnet/swagger-jsdoc). (See: [Sample](functions/src/lib/languages/route.js))
## Setup
- [Setup the Firebase CLI](https://firebase.google.com/docs/cli)
- [Generate your own repository from this template](https://github.com/au5ton/serverless-bot/generate)
- Clone your repo
`git clone `
- 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](https://firebase.google.com/docs/functions/config-env) configurations in [functions/scripts/predeploy.js](functions/scripts/predeploy.js):
```json
{
"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](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._
```javascript
// 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:
