Telegram bot for interacting with a Google Sheets spreadsheet
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tmp
.gitignore
LICENSE
Procfile
README.md
config-sample.toml
development.pm2.json
package.json
production.pm2.json
yarn.lock

README.md

Contributing

Clone and install dependencies

git clone https://github.com/fczuardi/gsheetsbot.git
cd gsheetsbot
yarn

Setup

Telegram bot with @BotFather

Talk with BotFather to create a Telegram bot and get a bot api token.

Google App for acessing Google Sheets

Follow step 1 of https://developers.google.com/sheets/quickstart/nodejs

Launch bot and api processes that restarts on src file changes

yarn dev

Display stream of logs

yarn logs

Stop all processes

yarn stop

Deploying to Heroku

After testing your bot locally, you can deploy it to heroku using the heroku cli and a local secret branch that don't gitignore your config.toml file.

Here is how to make this:

1. Login to heroku using the cli:

yarn stop
heroku login

2. Go to heroku.com and create a new app

3. Setup a git remote named heroku to be your production remote:

heroku git:remote -a your-heroku-app-name

4. Create a local branch that includes your secrets:

git checkout -b secret-branch
git branch --set-upstream-to heroku/master

5. On your secret local branch, remove config.toml from the .gitignore file

and push this local branch to heroku

git checkout secret-branch
$EDITOR .gitignore
git add .
git status
git commit -m "exposing my secrets to heroku"
git push

6. Launch your bot and follow the debug logs

heroku ps:scale worker=1
heroku logs --tail

7. Stop bot

heroku ps:scale worker=0

8. Change back to your local dev branch copying config.toml

from the secret heroku branch

git checkout master
git checkout secret-branch config.toml

Logging

All Telegram updates are logged in the filesystem on a log file configured in the [log] section of the config.toml file. To download this file any admin of the bot can use the /logs command.

But if your bot is deployed to an environment with non-persistent filesystem, such as Heroku, then the logfile sent to the admin with the /logs command will contain just the updates after the last reboot.

For that case, it is recommended to install a heroku logging addon, such as Papertrail to have a more complete logging management. All telegram updates JSON data are logged in the standard output (look for [DEBUG] or {"update_id") so it should be simple to catch them using this service.

Dependencies

This bot uses the Telegraf library for interacting with the Telegram Bot API.

The configuration file is writem in TOML, and we use toml-require for parsing it on node.js

To interact with Google APIs we use googleapis.

Dev Dependencies

Some tools we use in the developer environment: