Skip to content

Installation

Anna Buianova edited this page Aug 1, 2019 · 4 revisions

Prerequisites

  • You have installed Ruby. Look for the required version in the file .ruby-version. You can use rbenv to pick a right version for this application.
  • You have installed bundler

Development Workflow

  1. After cloning days-of-code, run bundle install to fetch its dependencies.

  2. Create your own test bot (see instructions below).

  3. Create postgres databases for test and development environments, e.g. telegram_bot_development and telegram_bot_test

  4. Create .env.development and .env.test files in the app root. Set variables DATABASE_URL, BOT_TOKEN, CHAT_ID, DATE_START and DATE_END there. Use .env.development.sample file for reference. Remember to set a different DATABASE_URL for the test and development environments. E.g. postgresql://postgres:password@localhost:5432/telegram_bot_development and postgresql://postgres:password@localhost:5432/telegram_bot_test

You can set environment variables PROXY_SERVER and PROXY_PORT if you use a proxy to connect to Telegram servers.

  1. To prevent problems with connection to Telegram API, before bot launch you need to start some preventing online restrictions tool.

You can launch the app in one of two ways:

  1. bundle exec ruby bot_control.rb start (w/o console output)
  2. bundle exec ruby bot.rb

Creating your own test bot

Open Telegram, add bot @BotPhaser, and create a bot:

/start
/newbot

etc. Finally, you'll receive Your API-token from bot_father : XXXXXXXXX:YYYYYYY-YYYYYYYYYYYYYYYYY_YY. To get chat id you may do the following. On private chat with your bot, send a random message. You will search this message later. Then, on your browser make a request with url:

https://api.telegram.org/botXXXXXXXXX:YYYYYYY-YYYYYYYYYYYYYYYYY_YY/getUpdates

The request returns a json response, in json text search your random message and get chat id in that object.

Creating a database

psql postgres
create database telegram_bot_development;

There's also a need to run migrations:

bundle exec rake db:migrate

And optional seeds:

bundle exec ruby db/seeds.rb
Clone this wiki locally