Giter VIP home page Giter VIP logo

serverless-bot's Introduction

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() 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 (Try: npx hygen route new <name>)
  • OpenAPI integration with swagger-jsdoc. (See: Sample)

Setup

  • Setup the Firebase CLI

  • Generate your own repository from this template

  • 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:

    demo

serverless-bot's People

Contributors

au5ton avatar dependabot[bot] avatar imgbotapp avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

serverless-bot's Issues

"webhook_secret" Meaning

Hello,
I'm stuck with config.json

I don't understand "webhook_secret" meaning? What should I use here?

{
    "telegram": {
        "bot_token": "1111111111:AAGBZpfsgsfhsXXXXXXXXX1D41DgUxI",
        "webhook_secret": "????????????"  // <<<<<<<<
    },
    "gcp": {
        "datacenter": "europe-west1",
        "project_id": "project-id-here"
    }
}

Regards!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.