Bus Eta Bot's secret identity
- The
DATABASE_URLshould be set appropriately. - For a local database:
env DATABASE_URL='postgres://localhost/bete_test?sslmode=disable' go test ./...
- Create a new bot with @BotFather on Telegram and obtain a bot token.
- Request for API access to LTA DataMall and obtain an account key.
- Build the server binary:
make - Run the server with the
DATAMALL_ACCOUNT_KEY,TELEGRAM_BOT_TOKENandDATABASE_URLenvironment variables:
env DATABASE_URL='postgres://localhost/bete_test?sslmode=disable' DATAMALL_ACCOUNT_KEY='xxx' TELEGRAM_BOT_TOKEN='xxx' bin/bete
- Start a separate ngrok process to expose the server:
ngrok http 8080 - Set the bot webhook to the public ngrok URL (use the HTTPS one). Note that
the path should be
/telegram/updates
curl https://api.telegram.org/bot$bot_token/setWebhook?url=https://xxx/telegram/updates
- Find your bot on Telegram and chat with it, you should see HTTP requests logged by ngrok and bete.
- For convenience, the Makefile contains a
starttarget to build and run the server, and awebhooktarget to automatically set the webhook. These both need the appropriate environment variables to be set.
- Install
mockgenbinary tobin/mockgen:GOBIN=$PWD/bin go get github.com/golang/mock/mockgen - Generate mocks:
go generate
- Install
migratebinary tobin/migrate:GOBIN=$PWD/bin go get -tags postgres github.com/golang-migrate/migrate/v4/cmd/migrate - The
postgrestag is needed to run migrations against Postgres. - To generate new migrations:
bin/migrate create -dir migrations -ext sql MIGRATION_NAME - To run migrations:
bin/migrate -path migrations -database 'postgres://localhost/bete_test?sslmode=disable' up