Skip to content

Latest commit

 

History

History
 
 

sample-firebase-bot

sample-firebase-bot

This Nx Firebase application was generated by @simondotm/nx-firebase.

Introduction

This demo project is a proof-of-concept Firebase Function bot implementation. It utilizes webhooks linked to Firebase functions to implement process the postbacks.

  • Currently, only local development is tested (using ngrok for webhooks)
  • Two functions implemented:
    • /webhook: The webhook postback
    • /command: A command interface that can be control Firebase via a NestJS controller. Not sure if this is needed, but it's available as an out-of-band communication tool with your project

Setup

  • Setup your Firebase project as normal and configure your ./firebaserc file with the project_id
    • firebase login - Authenticate the Firebase CLI
    • firebase use --add - Add your Firebase Project as a target to .firebaserc
  • Create a free ngrok account and set NGROK_TOKEN in your environment
  • Configure ~/.ngrok2/ngrok.yml as per the example below
  • Copy packages/sample-firebase-bot/src/.env.example to packages/sample-firebase-bot/src/.env and configure with your values

ℹ️ Required Environment Variables Ensure these environment variables are set

  • NGROK_TOKEN
  • BOT_TOKEN

⚠️ Firebase Emulation Only You may need to link @grammyjs/nestjs to this project. For example:

nx run grammy-nestjs:build
pushd dist/packages/grammy-nestjs/
yarn link
popd
yarn link @grammyjs/nestjs

Commands

To start/stop your webhook:

./packages/sample-firebase-bot/ngrok.sh start
#or
./packages/sample-firebase-bot/ngrok.sh stop
#or
./packages/sample-firebase-bot/ngrok.sh status

To start the emulator, running your bot locally:

yarn nx run sample-firebase-bot:emulate

The packages/sample-firebase-bot/ngrok.sh script is called prior to starting. This command:

  • Retrieves the currently active ngrok tunnel and posts it to Telegram for your bot

~/.ngrok2/ngrok.yml

authtoken: xxxxxx
tunnels:
    grammy:
        proto: http
        addr: 5001

.firebaserc

{ 'projects': { 'default': 'abcd....' } }