Skip to content

poulad/BusVbot

Repository files navigation

🚍 BusV Bot 🤖

tg badge travis badge

BusVbot logo

BusV is a Telegram chat bot 🤖 that helps you catch your bus 🚍 by providing you route information and bus predictions. Start chatting with it on Telegram to find out more: @BusVbot.

This bot works best for passengers who take frequent routes and already know what bus they should take to reach their destinations.

BusVbot demo

Supporting 70+ transit agencies in North America, the real-time bus predictions are powered by NextBus.

Here are the regions that agencies operate in:

Canada U.S.
Ontario, Quebec California-Northern, California-Southern, District of Columbia, Florida, Georgia, Indiana, Iowa, Kentucky, Maryland, Massachusetts, Mississippi, Nevada, New Jersey, New York, North Carolina, Oregon, Pennsylvania, Texas, Virginia, Washington

Getting Started

You can take a look at the Redis instance via:

docker run -it --link busvbot-redis:redis --rm redis redis-cli -h redis -p 6379

Build and Run

BusVbot is built using Telegram.Bot.Framework as an ASP.NET Core app.

Requirements

  • Visual Studio 2017 or .NET Core 1.1
  • Postgres database
  • Telegram Bot API token

Configurations

Make a copy of appsettings.json in project folder and name it appsettings.Development.json:

cp -v src/BusVbot/appsettings{,.Development}.json

Edit the appsettings.Development.json file and put your bot name, API token, and Postgres connection string values there.

There are other options to provide the app with configurations. Have a look at first few lines of Startup class.

Note that appsettings.Development.json is gitignored so it is safe to store the app secrets there.

Database

Run the Postgres database. Examples here are using docker containers.

# create and start the container
docker run -d -p 5432:5432 --name busvbot-postgres -e POSTGRES_PASSWORD=password -e POSTGRES_USER=busvbot -e POSTGRES_DB=busvbot postgres

See docker-local.sh for sample docker commands to use.

Seed Data

While running in Development environment, app makes sure database is seeded with data from NextBus before it starts the bot.

It might take a while to download all the data so in order to save time, use the sql dump file and its INSERT statements instead.

Create schema:

cd src/BusVbot
dotnet restore
dotnet ef database update

Insert data:

# inside docker container, as postgres user
psql -U busvbot < nextbus-dump.sql

Run

Run the app and start chatting with the bot on Telegram.

Bot Configurations

Commands

Set the commands for bot in a chat with @BotFather.

bus - 🚍 Bus predictions
profile - 👤 View/Modify my profile
help - ❓ Help

Tests

Systems Integration Tests

TelegramTests project contains the Systems Integration test cases. The HTTP requests to the Telegram Bot API are mocked using(Moq) and Docker Compose is used to run containers for other dependencies.

Before running the tests, MongoDB and Redis should be up and running.

cd test/TelegramTests
# run the containers in the background
docker-compose --project-name tg up -d --force-recreate --remove-orphans

# optionally, see the logs while running the tests
# docker-compose --project-name tg logs --follow

Tests cases can be run now from the IDE or the console.

dotnet test --verbosity normal

Containers can be removed after the tests are done.

docker-compose --project-name tg rm --stop -fv