├── .gitattributes ├── .gitignore ├── .pryrc ├── .rspec ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── assets │ ├── config │ │ └── manifest.js │ ├── images │ │ └── .keep │ └── stylesheets │ │ └── application.css ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ └── telegram_webhooks_controller.rb ├── helpers │ └── application_helper.rb ├── javascript │ ├── application.js │ └── controllers │ │ ├── application.js │ │ ├── hello_controller.js │ │ └── index.js ├── jobs │ └── application_job.rb ├── mailers │ └── application_mailer.rb ├── models │ ├── application_record.rb │ └── concerns │ │ └── .keep └── views │ └── layouts │ ├── application.html.erb │ ├── mailer.html.erb │ └── mailer.text.erb ├── bin ├── bundle ├── importmap ├── rails ├── rake ├── rspec ├── setup └── spring ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── importmap.rb ├── initializers │ ├── assets.rb │ ├── content_security_policy.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ └── permissions_policy.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb ├── secrets.yml.sample └── storage.yml ├── db └── seeds.rb ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── log └── .keep ├── public ├── 404.html ├── 422.html ├── 500.html ├── apple-touch-icon-precomposed.png ├── apple-touch-icon.png ├── favicon.ico └── robots.txt ├── spec ├── rails_helper.rb ├── requests │ └── telegram_webhooks_spec.rb └── spec_helper.rb ├── storage └── .keep ├── tmp ├── .keep ├── pids │ └── .keep └── storage │ └── .keep └── vendor ├── .keep └── javascript └── .keep /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files. 2 | 3 | # Mark the database schema as having been generated. 4 | db/schema.rb linguist-generated 5 | 6 | # Mark any vendored files as having been vendored. 7 | vendor/* linguist-vendored 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-* 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | /tmp/* 17 | !/log/.keep 18 | !/tmp/.keep 19 | 20 | # Ignore pidfiles, but keep the directory. 21 | /tmp/pids/* 22 | !/tmp/pids/ 23 | !/tmp/pids/.keep 24 | 25 | # Ignore uploaded files in development. 26 | /storage/* 27 | !/storage/.keep 28 | /tmp/storage/* 29 | !/tmp/storage/ 30 | !/tmp/storage/.keep 31 | 32 | /public/assets 33 | 34 | # Ignore master key for decrypting credentials and more. 35 | /config/master.key 36 | 37 | spec/examples.txt 38 | config/secrets.yml 39 | -------------------------------------------------------------------------------- /.pryrc: -------------------------------------------------------------------------------- 1 | # Aliases for debugger. 2 | if defined?(PryByebug) || defined?(PryDebugger) 3 | Pry.commands.alias_command 'c', 'continue' 4 | Pry.commands.alias_command 's', 'step' 5 | Pry.commands.alias_command 'n', 'next' 6 | Pry.commands.alias_command 'f', 'finish' 7 | end 8 | 9 | # Inspect hashes with 1.9 syntax and aligned to the left. 10 | require 'ap' 11 | Pry.config.print = proc do |_output, value| 12 | ap = AwesomePrint::Inspector.new(indent: -2, ruby19_syntax: true) 13 | pager = Pry.new.pager 14 | pretty = ap.awesome(value) 15 | pager.page "=> #{pretty}" 16 | end 17 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require rails_helper 3 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.0.0 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | ruby "3.0.0" 5 | 6 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 7 | gem "rails", "~> 7.0.2", ">= 7.0.2.3" 8 | 9 | # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] 10 | gem "sprockets-rails" 11 | 12 | # Use sqlite3 as the database for Active Record 13 | gem "sqlite3", "~> 1.4" 14 | 15 | # Use the Puma web server [https://github.com/puma/puma] 16 | gem "puma", "~> 5.6" 17 | 18 | # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 19 | gem "importmap-rails" 20 | 21 | # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 22 | gem "turbo-rails" 23 | 24 | # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 25 | gem "stimulus-rails" 26 | 27 | # Build JSON APIs with ease [https://github.com/rails/jbuilder] 28 | # gem "jbuilder" 29 | 30 | # Use Redis adapter to run Action Cable in production 31 | # gem "redis", "~> 4.0" 32 | 33 | # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 34 | # gem "kredis" 35 | 36 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 37 | # gem "bcrypt", "~> 3.1.7" 38 | 39 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 40 | gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] 41 | 42 | # Reduces boot times through caching; required in config/boot.rb 43 | # gem "bootsnap", require: false 44 | 45 | # Use Sass to process CSS 46 | # gem "sassc-rails" 47 | 48 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 49 | # gem "image_processing", "~> 1.2" 50 | 51 | gem "telegram-bot", "~> 0.15.5" 52 | 53 | group :pry do 54 | gem "awesome_print" 55 | gem "pry" 56 | gem "pry-byebug" 57 | gem "pry-doc" 58 | gem "pry-rails" 59 | end 60 | 61 | group :development, :test do 62 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 63 | gem "debug", platforms: %i[ mri mingw x64_mingw ] 64 | end 65 | 66 | group :development do 67 | # Use console on exceptions pages [https://github.com/rails/web-console] 68 | gem "web-console" 69 | 70 | # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] 71 | # gem "rack-mini-profiler" 72 | 73 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 74 | gem "spring" 75 | gem "spring-commands-rspec" 76 | end 77 | 78 | group :test do 79 | # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] 80 | # gem "capybara" 81 | # gem "selenium-webdriver" 82 | # gem "webdrivers" 83 | 84 | gem "rspec-rails" 85 | gem "rspec-its" 86 | end 87 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (7.0.3) 5 | actionpack (= 7.0.3) 6 | activesupport (= 7.0.3) 7 | nio4r (~> 2.0) 8 | websocket-driver (>= 0.6.1) 9 | actionmailbox (7.0.3) 10 | actionpack (= 7.0.3) 11 | activejob (= 7.0.3) 12 | activerecord (= 7.0.3) 13 | activestorage (= 7.0.3) 14 | activesupport (= 7.0.3) 15 | mail (>= 2.7.1) 16 | net-imap 17 | net-pop 18 | net-smtp 19 | actionmailer (7.0.3) 20 | actionpack (= 7.0.3) 21 | actionview (= 7.0.3) 22 | activejob (= 7.0.3) 23 | activesupport (= 7.0.3) 24 | mail (~> 2.5, >= 2.5.4) 25 | net-imap 26 | net-pop 27 | net-smtp 28 | rails-dom-testing (~> 2.0) 29 | actionpack (7.0.3) 30 | actionview (= 7.0.3) 31 | activesupport (= 7.0.3) 32 | rack (~> 2.0, >= 2.2.0) 33 | rack-test (>= 0.6.3) 34 | rails-dom-testing (~> 2.0) 35 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 36 | actiontext (7.0.3) 37 | actionpack (= 7.0.3) 38 | activerecord (= 7.0.3) 39 | activestorage (= 7.0.3) 40 | activesupport (= 7.0.3) 41 | globalid (>= 0.6.0) 42 | nokogiri (>= 1.8.5) 43 | actionview (7.0.3) 44 | activesupport (= 7.0.3) 45 | builder (~> 3.1) 46 | erubi (~> 1.4) 47 | rails-dom-testing (~> 2.0) 48 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 49 | activejob (7.0.3) 50 | activesupport (= 7.0.3) 51 | globalid (>= 0.3.6) 52 | activemodel (7.0.3) 53 | activesupport (= 7.0.3) 54 | activerecord (7.0.3) 55 | activemodel (= 7.0.3) 56 | activesupport (= 7.0.3) 57 | activestorage (7.0.3) 58 | actionpack (= 7.0.3) 59 | activejob (= 7.0.3) 60 | activerecord (= 7.0.3) 61 | activesupport (= 7.0.3) 62 | marcel (~> 1.0) 63 | mini_mime (>= 1.1.0) 64 | activesupport (7.0.3) 65 | concurrent-ruby (~> 1.0, >= 1.0.2) 66 | i18n (>= 1.6, < 2) 67 | minitest (>= 5.1) 68 | tzinfo (~> 2.0) 69 | awesome_print (1.9.2) 70 | bindex (0.8.1) 71 | builder (3.2.4) 72 | byebug (11.1.3) 73 | coderay (1.1.3) 74 | concurrent-ruby (1.1.10) 75 | crass (1.0.6) 76 | debug (1.5.0) 77 | irb (>= 1.3.6) 78 | reline (>= 0.2.7) 79 | diff-lcs (1.5.0) 80 | digest (3.1.0) 81 | erubi (1.10.0) 82 | globalid (1.0.0) 83 | activesupport (>= 5.0) 84 | httpclient (2.8.3) 85 | i18n (1.10.0) 86 | concurrent-ruby (~> 1.0) 87 | importmap-rails (1.1.0) 88 | actionpack (>= 6.0.0) 89 | railties (>= 6.0.0) 90 | io-console (0.5.11) 91 | irb (1.4.1) 92 | reline (>= 0.3.0) 93 | loofah (2.18.0) 94 | crass (~> 1.0.2) 95 | nokogiri (>= 1.5.9) 96 | mail (2.7.1) 97 | mini_mime (>= 0.1.1) 98 | marcel (1.0.2) 99 | method_source (1.0.0) 100 | mini_mime (1.1.2) 101 | minitest (5.15.0) 102 | net-imap (0.2.3) 103 | digest 104 | net-protocol 105 | strscan 106 | net-pop (0.1.1) 107 | digest 108 | net-protocol 109 | timeout 110 | net-protocol (0.1.3) 111 | timeout 112 | net-smtp (0.3.1) 113 | digest 114 | net-protocol 115 | timeout 116 | nio4r (2.5.8) 117 | nokogiri (1.13.6-x86_64-darwin) 118 | racc (~> 1.4) 119 | nokogiri (1.13.6-x86_64-linux) 120 | racc (~> 1.4) 121 | pry (0.14.1) 122 | coderay (~> 1.1) 123 | method_source (~> 1.0) 124 | pry-byebug (3.8.0) 125 | byebug (~> 11.0) 126 | pry (~> 0.10) 127 | pry-doc (1.3.0) 128 | pry (~> 0.11) 129 | yard (~> 0.9.11) 130 | pry-rails (0.3.9) 131 | pry (>= 0.10.4) 132 | puma (5.6.4) 133 | nio4r (~> 2.0) 134 | racc (1.6.0) 135 | rack (2.2.3.1) 136 | rack-test (1.1.0) 137 | rack (>= 1.0, < 3) 138 | rails (7.0.3) 139 | actioncable (= 7.0.3) 140 | actionmailbox (= 7.0.3) 141 | actionmailer (= 7.0.3) 142 | actionpack (= 7.0.3) 143 | actiontext (= 7.0.3) 144 | actionview (= 7.0.3) 145 | activejob (= 7.0.3) 146 | activemodel (= 7.0.3) 147 | activerecord (= 7.0.3) 148 | activestorage (= 7.0.3) 149 | activesupport (= 7.0.3) 150 | bundler (>= 1.15.0) 151 | railties (= 7.0.3) 152 | rails-dom-testing (2.0.3) 153 | activesupport (>= 4.2.0) 154 | nokogiri (>= 1.6) 155 | rails-html-sanitizer (1.4.2) 156 | loofah (~> 2.3) 157 | railties (7.0.3) 158 | actionpack (= 7.0.3) 159 | activesupport (= 7.0.3) 160 | method_source 161 | rake (>= 12.2) 162 | thor (~> 1.0) 163 | zeitwerk (~> 2.5) 164 | rake (13.0.6) 165 | reline (0.3.1) 166 | io-console (~> 0.5) 167 | rspec-core (3.11.0) 168 | rspec-support (~> 3.11.0) 169 | rspec-expectations (3.11.0) 170 | diff-lcs (>= 1.2.0, < 2.0) 171 | rspec-support (~> 3.11.0) 172 | rspec-its (1.3.0) 173 | rspec-core (>= 3.0.0) 174 | rspec-expectations (>= 3.0.0) 175 | rspec-mocks (3.11.1) 176 | diff-lcs (>= 1.2.0, < 2.0) 177 | rspec-support (~> 3.11.0) 178 | rspec-rails (5.1.2) 179 | actionpack (>= 5.2) 180 | activesupport (>= 5.2) 181 | railties (>= 5.2) 182 | rspec-core (~> 3.10) 183 | rspec-expectations (~> 3.10) 184 | rspec-mocks (~> 3.10) 185 | rspec-support (~> 3.10) 186 | rspec-support (3.11.0) 187 | spring (4.0.0) 188 | spring-commands-rspec (1.0.4) 189 | spring (>= 0.9.1) 190 | sprockets (4.0.3) 191 | concurrent-ruby (~> 1.0) 192 | rack (> 1, < 3) 193 | sprockets-rails (3.4.2) 194 | actionpack (>= 5.2) 195 | activesupport (>= 5.2) 196 | sprockets (>= 3.0.0) 197 | sqlite3 (1.4.2) 198 | stimulus-rails (1.0.4) 199 | railties (>= 6.0.0) 200 | strscan (3.0.3) 201 | telegram-bot (0.15.6) 202 | actionpack (>= 4.0, < 7.1) 203 | activesupport (>= 4.0, < 7.1) 204 | httpclient (~> 2.7) 205 | thor (1.2.1) 206 | timeout (0.3.0) 207 | turbo-rails (1.1.1) 208 | actionpack (>= 6.0.0) 209 | activejob (>= 6.0.0) 210 | railties (>= 6.0.0) 211 | tzinfo (2.0.4) 212 | concurrent-ruby (~> 1.0) 213 | web-console (4.2.0) 214 | actionview (>= 6.0.0) 215 | activemodel (>= 6.0.0) 216 | bindex (>= 0.4.0) 217 | railties (>= 6.0.0) 218 | webrick (1.7.0) 219 | websocket-driver (0.7.5) 220 | websocket-extensions (>= 0.1.0) 221 | websocket-extensions (0.1.5) 222 | yard (0.9.28) 223 | webrick (~> 1.7.0) 224 | zeitwerk (2.5.4) 225 | 226 | PLATFORMS 227 | x86_64-darwin-18 228 | x86_64-linux 229 | 230 | DEPENDENCIES 231 | awesome_print 232 | debug 233 | importmap-rails 234 | pry 235 | pry-byebug 236 | pry-doc 237 | pry-rails 238 | puma (~> 5.6) 239 | rails (~> 7.0.2, >= 7.0.2.3) 240 | rspec-its 241 | rspec-rails 242 | spring 243 | spring-commands-rspec 244 | sprockets-rails 245 | sqlite3 (~> 1.4) 246 | stimulus-rails 247 | telegram-bot (~> 0.15.5) 248 | turbo-rails 249 | tzinfo-data 250 | web-console 251 | 252 | RUBY VERSION 253 | ruby 3.0.0p0 254 | 255 | BUNDLED WITH 256 | 2.2.3 257 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Example telegram bot app 2 | 3 | This app uses [telegram-bot](https://github.com/telegram-bot-rb/telegram-bot) gem. 4 | Want to see the [bot code](https://github.com/telegram-bot-rb/telegram_bot_app/blob/master/app/controllers/telegram_webhooks_controller.rb) 5 | first? 6 | 7 | Explore separate commits to check evolution of code. 8 | 9 | Want a clean setup instead? 10 | Here is [app teamplate](https://github.com/telegram-bot-rb/rails_template) to help you. 11 | 12 | ## Commands 13 | 14 | - `/start` - Greeting. 15 | - `/help` 16 | - `/memo %text%` - Saves text to session. 17 | - `/remind_me` - Replies with text from session. 18 | - `/keyboard` - Simple keyboard. 19 | - `/inline_keyboard` - Inline keyboard example. 20 | - Inline queries. Enable it in [@BotFather](https://telegram.me/BotFather), 21 | and your're ready to try 'em. 22 | - `/last_chosen_inline_result` - Your last chosen inline result 23 | (Enable feedback with sending `/setinlinefeedback` 24 | to [@BotFather](https://telegram.me/BotFather)). 25 | 26 | ## Setup 27 | 28 | - Create bot with [@BotFather](https://telegram.me/BotFather) `unless has_test_bot?` 29 | - Clone repo. 30 | - run `./bin/setup`. 31 | - Update `config/secrets.yml` with your bot's token. 32 | 33 | ## Run 34 | 35 | ### Development 36 | 37 | ``` 38 | bin/rake telegram:bot:poller 39 | ``` 40 | 41 | ### Production 42 | 43 | One way is just to run poller. You don't need anything else, just check 44 | your production secrets & configs. But there is better way: use webhooks. 45 | 46 | __You may want to use different token: after you setup the webhook, 47 | you need to unset it to run development poller again.__ 48 | 49 | First you need to setup the webhook. There is rake task for it, 50 | but you're free to set it manually with API call. 51 | To use rake task you need to set host in `routes.default_url_options` 52 | for production environment (`config.routes` for Rails < 5). 53 | There is already such line in the repo in `production.rb`. 54 | Uncomment it, change the values, and you're ready for: 55 | 56 | ``` 57 | bin/rake telegram:bot:set_webhook RAILS_ENV=production 58 | ``` 59 | 60 | Now deploy your app in any way you like. You don't need run anything special for bot, 61 | but `rails server` as usual. Your rails app will receive webhooks and bypass them 62 | to bot's controller. 63 | 64 | By default session is configured to use FileStore at `Rails.root.join('tmp', 'session_store')`. 65 | To use it in production make sure to share this folder between releases 66 | (ex., add to list shared of shared folders in capistrano). 67 | Read more about different session stores in 68 | [original readme](https://github.com/telegram-bot-rb/telegram-bot#session). 69 | 70 | ### Testing 71 | 72 | ``` 73 | bin/rspec 74 | ``` 75 | 76 | ## Advanced 77 | 78 | ### Async mode 79 | 80 | - Uncomment `async: true` in `secrets.yml`. 81 | - Run and check the logs out. 82 | - More info about [async mode](https://github.com/telegram-bot-rb/telegram-bot#async-mode). 83 | 84 | ## Contributing 85 | 86 | Bug reports and pull requests are welcome on GitHub at https://github.com/telegram-bot-rb/telegram_bot_app. 87 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../stylesheets .css 3 | //= link_tree ../../javascript .js 4 | //= link_tree ../../../vendor/javascript .js 5 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's 6 | * vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/telegram_webhooks_controller.rb: -------------------------------------------------------------------------------- 1 | class TelegramWebhooksController < Telegram::Bot::UpdatesController 2 | include Telegram::Bot::UpdatesController::MessageContext 3 | 4 | def start!(*) 5 | respond_with :message, text: t('.content') 6 | end 7 | 8 | def help!(*) 9 | respond_with :message, text: t('.content') 10 | end 11 | 12 | def memo!(*args) 13 | if args.any? 14 | session[:memo] = args.join(' ') 15 | respond_with :message, text: t('.notice') 16 | else 17 | respond_with :message, text: t('.prompt') 18 | save_context :memo! 19 | end 20 | end 21 | 22 | def remind_me!(*) 23 | to_remind = session.delete(:memo) 24 | reply = to_remind || t('.nothing') 25 | respond_with :message, text: reply 26 | end 27 | 28 | def keyboard!(value = nil, *) 29 | if value 30 | respond_with :message, text: t('.selected', value: value) 31 | else 32 | save_context :keyboard! 33 | respond_with :message, text: t('.prompt'), reply_markup: { 34 | keyboard: [t('.buttons')], 35 | resize_keyboard: true, 36 | one_time_keyboard: true, 37 | selective: true, 38 | } 39 | end 40 | end 41 | 42 | def inline_keyboard!(*) 43 | respond_with :message, text: t('.prompt'), reply_markup: { 44 | inline_keyboard: [ 45 | [ 46 | {text: t('.alert'), callback_data: 'alert'}, 47 | {text: t('.no_alert'), callback_data: 'no_alert'}, 48 | ], 49 | [{text: t('.repo'), url: 'https://github.com/telegram-bot-rb/telegram-bot'}], 50 | ], 51 | } 52 | end 53 | 54 | def callback_query(data) 55 | if data == 'alert' 56 | answer_callback_query t('.alert'), show_alert: true 57 | else 58 | answer_callback_query t('.no_alert') 59 | end 60 | end 61 | 62 | def inline_query(query, _offset) 63 | query = query.first(10) # it's just an example, don't use large queries. 64 | t_description = t('.description') 65 | t_content = t('.content') 66 | results = Array.new(5) do |i| 67 | { 68 | type: :article, 69 | title: "#{query}-#{i}", 70 | id: "#{query}-#{i}", 71 | description: "#{t_description} #{i}", 72 | input_message_content: { 73 | message_text: "#{t_content} #{i}", 74 | }, 75 | } 76 | end 77 | answer_inline_query results 78 | end 79 | 80 | # As there is no chat id in such requests, we can not respond instantly. 81 | # So we just save the result_id, and it's available then with `/last_chosen_inline_result`. 82 | def chosen_inline_result(result_id, _query) 83 | session[:last_chosen_inline_result] = result_id 84 | end 85 | 86 | def last_chosen_inline_result!(*) 87 | result_id = session[:last_chosen_inline_result] 88 | if result_id 89 | respond_with :message, text: t('.selected', result_id: result_id) 90 | else 91 | respond_with :message, text: t('.prompt') 92 | end 93 | end 94 | 95 | def message(message) 96 | respond_with :message, text: t('.content', text: message['text']) 97 | end 98 | 99 | def action_missing(action, *_args) 100 | if action_type == :command 101 | respond_with :message, 102 | text: t('telegram_webhooks.action_missing.command', command: action_options[:command]) 103 | end 104 | end 105 | end 106 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/javascript/application.js: -------------------------------------------------------------------------------- 1 | // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails 2 | import "@hotwired/turbo-rails" 3 | import "controllers" 4 | -------------------------------------------------------------------------------- /app/javascript/controllers/application.js: -------------------------------------------------------------------------------- 1 | import { Application } from "@hotwired/stimulus" 2 | 3 | const application = Application.start() 4 | 5 | // Configure Stimulus development experience 6 | application.debug = false 7 | window.Stimulus = application 8 | 9 | export { application } 10 | -------------------------------------------------------------------------------- /app/javascript/controllers/hello_controller.js: -------------------------------------------------------------------------------- 1 | import { Controller } from "@hotwired/stimulus" 2 | 3 | export default class extends Controller { 4 | connect() { 5 | this.element.textContent = "Hello World!" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /app/javascript/controllers/index.js: -------------------------------------------------------------------------------- 1 | // Import and register all your controllers from the importmap under controllers/* 2 | 3 | import { application } from "controllers/application" 4 | 5 | // Eager load all controllers defined in the import map under controllers/**/*_controller 6 | import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" 7 | eagerLoadControllersFrom("controllers", application) 8 | 9 | // Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) 10 | // import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" 11 | // lazyLoadControllersFrom("controllers", application) 12 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TelegramBotApp 5 | 6 | <%= csrf_meta_tags %> 7 | <%= csp_meta_tag %> 8 | 9 | <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> 10 | <%= javascript_importmap_tags %> 11 | 12 | 13 | 14 | <%= yield %> 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../../Gemfile", __FILE__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_version 64 | @bundler_version ||= 65 | env_var_version || cli_arg_version || 66 | lockfile_version 67 | end 68 | 69 | def bundler_requirement 70 | return "#{Gem::Requirement.default}.a" unless bundler_version 71 | 72 | bundler_gem_version = Gem::Version.new(bundler_version) 73 | 74 | requirement = bundler_gem_version.approximate_recommendation 75 | 76 | return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") 77 | 78 | requirement += ".a" if bundler_gem_version.prerelease? 79 | 80 | requirement 81 | end 82 | 83 | def load_bundler! 84 | ENV["BUNDLE_GEMFILE"] ||= gemfile 85 | 86 | activate_bundler 87 | end 88 | 89 | def activate_bundler 90 | gem_error = activation_error_handling do 91 | gem "bundler", bundler_requirement 92 | end 93 | return if gem_error.nil? 94 | require_error = activation_error_handling do 95 | require "bundler/version" 96 | end 97 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 98 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 99 | exit 42 100 | end 101 | 102 | def activation_error_handling 103 | yield 104 | nil 105 | rescue StandardError, LoadError => e 106 | e 107 | end 108 | end 109 | 110 | m.load_bundler! 111 | 112 | if m.invoked_as_script? 113 | load Gem.bin_path("bundler", "bundle") 114 | end 115 | -------------------------------------------------------------------------------- /bin/importmap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative "../config/application" 4 | require "importmap/commands" 5 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/rspec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | load File.expand_path("spring", __dir__) 3 | require 'bundler/setup' 4 | load Gem.bin_path('rspec-core', 'rspec') 5 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | unless File.exist?("config/secrets.yml") 25 | FileUtils.cp "config/secrets.yml.sample", "config/secrets.yml" 26 | end 27 | 28 | puts "\n== Preparing database ==" 29 | system! "bin/rails db:prepare" 30 | 31 | puts "\n== Removing old logs and tempfiles ==" 32 | system! "bin/rails log:clear tmp:clear" 33 | 34 | puts "\n== Restarting application server ==" 35 | system! "bin/rails restart" 36 | end 37 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads Spring without using loading other gems in the Gemfile, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"]) 7 | require "bundler" 8 | 9 | Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring| 10 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 11 | gem "spring", spring.version 12 | require "spring/binstub" 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups( 8 | assets: %i[development test], 9 | pry: %i[development test], 10 | )) 11 | # load pry for production console 12 | Bundler.require(:pry) if defined?(Rails::Console) 13 | 14 | module TelegramBotApp 15 | class Application < Rails::Application 16 | # Initialize configuration defaults for originally generated Rails version. 17 | config.load_defaults 7.0 18 | 19 | # Configuration for the application, engines, and railties goes here. 20 | # 21 | # These settings can be overridden in specific environments using the files 22 | # in config/environments, which are processed later. 23 | # 24 | # config.time_zone = "Central Time (US & Canada)" 25 | # config.eager_load_paths << Rails.root.join("extras") 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | # require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: redis 3 | url: redis://localhost:6379/1 4 | 5 | test: 6 | adapter: test 7 | 8 | production: 9 | adapter: redis 10 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 11 | channel_prefix: telegram_bot_app_production 12 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem "sqlite3" 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.cache_classes = false 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.action_controller.perform_caching = true 24 | config.action_controller.enable_fragment_cache_logging = true 25 | 26 | config.cache_store = :memory_store 27 | config.public_file_server.headers = { 28 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 29 | } 30 | else 31 | config.action_controller.perform_caching = false 32 | 33 | config.cache_store = :null_store 34 | end 35 | 36 | # Store uploaded files on the local file system (see config/storage.yml for options). 37 | config.active_storage.service = :local 38 | 39 | # Don't care if the mailer can't send. 40 | config.action_mailer.raise_delivery_errors = false 41 | 42 | config.action_mailer.perform_caching = false 43 | 44 | # Print deprecation notices to the Rails logger. 45 | config.active_support.deprecation = :log 46 | 47 | # Raise exceptions for disallowed deprecations. 48 | config.active_support.disallowed_deprecation = :raise 49 | 50 | # Tell Active Support which deprecation messages to disallow. 51 | config.active_support.disallowed_deprecation_warnings = [] 52 | 53 | # Raise an error on page load if there are pending migrations. 54 | config.active_record.migration_error = :page_load 55 | 56 | # Highlight code that triggered database queries in logs. 57 | config.active_record.verbose_query_logs = true 58 | 59 | # Suppress logger output for asset requests. 60 | config.assets.quiet = true 61 | 62 | # Raises error for missing translations. 63 | # config.i18n.raise_on_missing_translations = true 64 | 65 | # Annotate rendered view with file names. 66 | # config.action_view.annotate_rendered_view_with_filenames = true 67 | 68 | # Uncomment if you wish to allow Action Cable access from any origin. 69 | # config.action_cable.disable_request_forgery_protection = true 70 | 71 | # Use memory store for bot sessions. 72 | config.telegram_updates_controller.session_store = :memory_store 73 | end 74 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.cache_classes = true 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | config.action_controller.perform_caching = true 18 | 19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 21 | # config.require_master_key = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? 26 | 27 | # Compress CSS using a preprocessor. 28 | # config.assets.css_compressor = :sass 29 | 30 | # Do not fallback to assets pipeline if a precompiled asset is missed. 31 | config.assets.compile = false 32 | 33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 34 | # config.asset_host = "http://assets.example.com" 35 | 36 | # Specifies the header that your server uses for sending files. 37 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 38 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 39 | 40 | # Store uploaded files on the local file system (see config/storage.yml for options). 41 | config.active_storage.service = :local 42 | 43 | # Mount Action Cable outside main process or domain. 44 | # config.action_cable.mount_path = nil 45 | # config.action_cable.url = "wss://example.com/cable" 46 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 47 | 48 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 49 | # config.force_ssl = true 50 | 51 | # Include generic and useful information about system operation, but avoid logging too much 52 | # information to avoid inadvertent exposure of personally identifiable information (PII). 53 | config.log_level = :info 54 | 55 | # Prepend all log lines with the following tags. 56 | config.log_tags = [ :request_id ] 57 | 58 | # Use a different cache store in production. 59 | # config.cache_store = :mem_cache_store 60 | 61 | # Use a real queuing backend for Active Job (and separate queues per environment). 62 | # config.active_job.queue_adapter = :resque 63 | # config.active_job.queue_name_prefix = "telegram_bot_app_production" 64 | 65 | config.action_mailer.perform_caching = false 66 | 67 | # Ignore bad email addresses and do not raise email delivery errors. 68 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 69 | # config.action_mailer.raise_delivery_errors = false 70 | 71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 72 | # the I18n.default_locale when a translation cannot be found). 73 | config.i18n.fallbacks = true 74 | 75 | # Don't log any deprecations. 76 | config.active_support.report_deprecations = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | 81 | # Use a different logger for distributed setups. 82 | # require "syslog/logger" 83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 84 | 85 | if ENV["RAILS_LOG_TO_STDOUT"].present? 86 | logger = ActiveSupport::Logger.new(STDOUT) 87 | logger.formatter = config.log_formatter 88 | config.logger = ActiveSupport::TaggedLogging.new(logger) 89 | end 90 | 91 | # Do not dump schema after migrations. 92 | config.active_record.dump_schema_after_migration = false 93 | 94 | # Set application domain, to be able to run `rake telegram:bot:set_webhook` 95 | # routes.default_url_options = {host: 'yourdomain.com', protocol: 'https'} 96 | 97 | # Configure session store for telegram bot. 98 | config.telegram_updates_controller.session_store = :file_store, 99 | Rails.root.join('tmp', 'session_store') 100 | end 101 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # Turn false under Spring and add config.action_view.cache_template_loading = true. 12 | config.cache_classes = false 13 | 14 | # Eager loading loads your whole application. When running a single test locally, 15 | # this probably isn't necessary. It's a good idea to do in a continuous integration 16 | # system, or in some way before deploying your code. 17 | config.eager_load = ENV["CI"].present? 18 | 19 | # Configure public file server for tests with Cache-Control for performance. 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 23 | } 24 | 25 | # Show full error reports and disable caching. 26 | config.consider_all_requests_local = true 27 | config.action_controller.perform_caching = false 28 | config.cache_store = :null_store 29 | 30 | # Raise exceptions instead of rendering exception templates. 31 | config.action_dispatch.show_exceptions = false 32 | 33 | # Disable request forgery protection in test environment. 34 | config.action_controller.allow_forgery_protection = false 35 | 36 | # Store uploaded files on the local file system in a temporary directory. 37 | config.active_storage.service = :test 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Tell Action Mailer not to deliver emails to the real world. 42 | # The :test delivery method accumulates sent emails in the 43 | # ActionMailer::Base.deliveries array. 44 | config.action_mailer.delivery_method = :test 45 | 46 | # Print deprecation notices to the stderr. 47 | config.active_support.deprecation = :stderr 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raises error for missing translations. 56 | # config.i18n.raise_on_missing_translations = true 57 | 58 | # Annotate rendered view with file names. 59 | # config.action_view.annotate_rendered_view_with_filenames = true 60 | 61 | # Use memory store for bot sessions. 62 | config.telegram_updates_controller.session_store = :memory_store 63 | 64 | # Stub clients before processing routes.rb. 65 | Telegram::Bot::ClientStub.stub_all! 66 | end 67 | -------------------------------------------------------------------------------- /config/importmap.rb: -------------------------------------------------------------------------------- 1 | # Pin npm packages by running ./bin/importmap 2 | 3 | pin "application", preload: true 4 | pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true 5 | pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true 6 | pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true 7 | pin_all_from "app/javascript/controllers", under: "controllers" 8 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in the app/assets 11 | # folder are already added. 12 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 13 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy 4 | # For further information see the following documentation 5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap and inline scripts 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src) 22 | # 23 | # # Report CSP violations to a specified URI. See: 24 | # # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only 25 | # # config.content_security_policy_report_only = true 26 | # end 27 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # "true": "foo" 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | telegram_webhooks: 34 | action_missing: 35 | command: Can not perform %{command} 36 | callback_query: 37 | alert: This is ALERT-T-T!!! 38 | no_alert: Simple answer 39 | help: 40 | content: | 41 | Available cmds: 42 | /start - Greeting. 43 | /memo %text% - Saves text to session. 44 | /remind_me - Replies with text from session. 45 | /keyboard - Simple keyboard. 46 | /inline_keyboard - Inline keyboard example. 47 | Bot supports inline queries. Enable it in @BotFather. 48 | /last_chosen_inline_result - Your last chosen inline result \ 49 | (Enable feedback with /setinlinefeedback). 50 | inline_keyboard: 51 | alert: Answer with alert 52 | no_alert: Without alert 53 | prompt: 'Check my inline keyboard:' 54 | repo: Open gem repo 55 | inline_query: 56 | content: Content 57 | description: Description 58 | keyboard: 59 | buttons: 60 | - Lorem 61 | - Ipsum 62 | - /cancel 63 | prompt: 'Select something with keyboard:' 64 | selected: "You've selected: %{value}" 65 | last_chosen_inline_result: 66 | prompt: Mention me to initiate inline query 67 | selected: "You've chosen result #%{result_id}" 68 | memo: 69 | notice: Remembered! 70 | prompt: What should I remember? 71 | message: 72 | content: 'You wrote: %{text}' 73 | remind_me: 74 | nothing: Nothing to remind 75 | start: 76 | content: Hi there! 77 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT") { 3000 } 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `bin/rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html 3 | 4 | # Defines the root path route ("/") 5 | # root "articles#index" 6 | 7 | telegram_webhook TelegramWebhooksController 8 | end 9 | -------------------------------------------------------------------------------- /config/secrets.yml.sample: -------------------------------------------------------------------------------- 1 | development: &dev 2 | secret_key_base: 93b7f55dd41146764804e122fc94b1e9b9fd86718659a219e8f0828135156dd0245165b215e29d740da4626d92ef2f04648627f8de96b75e59ef8d1a06f35788 3 | telegram: 4 | bot: 5 | token: BOT_TOKEN 6 | username: BOT_NAME 7 | # async: true 8 | 9 | test: 10 | secret_key_base: 7fb559360ff2d7297bf5fbe7eeb7480e3692373708e08283498acfcbfb4207c142812bb52f36606e13cbf9b22a309bf4a64882e0424527f42423106f77e9faba 11 | telegram: 12 | bot: 13 | token: test_bot_token 14 | username: BOT_NAME 15 | # async: true 16 | 17 | # Do not keep production secrets in the repository, 18 | # instead read values from the environment. 19 | production: 20 | <<: *dev 21 | -------------------------------------------------------------------------------- /config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) 7 | # Character.create(name: "Luke", movie: movies.first) 8 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/lib/assets/.keep -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/lib/tasks/.keep -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/log/.keep -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require 'spec_helper' 3 | ENV['RAILS_ENV'] ||= 'test' 4 | require File.expand_path('../config/environment', __dir__) 5 | # Prevent database truncation if the environment is production 6 | abort("The Rails environment is running in production mode!") if Rails.env.production? 7 | require 'rspec/rails' 8 | require 'telegram/bot/rspec/integration/rails' 9 | # Add additional requires below this line. Rails is not loaded until this point! 10 | 11 | # Requires supporting ruby files with custom matchers and macros, etc, in 12 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 13 | # run as spec files by default. This means that files in spec/support that end 14 | # in _spec.rb will both be required and run as specs, causing the specs to be 15 | # run twice. It is recommended that you do not name files matching this glob to 16 | # end with _spec.rb. You can configure this pattern with the --pattern 17 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 18 | # 19 | # The following line is provided for convenience purposes. It has the downside 20 | # of increasing the boot-up time by auto-requiring all files in the support 21 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 22 | # require only the support files necessary. 23 | # 24 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } 25 | 26 | # Checks for pending migrations and applies them before tests are run. 27 | # If you are not using ActiveRecord, you can remove these lines. 28 | # begin 29 | # ActiveRecord::Migration.maintain_test_schema! 30 | # rescue ActiveRecord::PendingMigrationError => e 31 | # puts e.to_s.strip 32 | # exit 1 33 | # end 34 | RSpec.configure do |config| 35 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 36 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 37 | 38 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 39 | # examples within a transaction, remove the following line or assign false 40 | # instead of true. 41 | config.use_transactional_fixtures = true 42 | 43 | # You can uncomment this line to turn off ActiveRecord support entirely. 44 | # config.use_active_record = false 45 | 46 | # RSpec Rails can automatically mix in different behaviours to your tests 47 | # based on their file location, for example enabling you to call `get` and 48 | # `post` in specs under `spec/controllers`. 49 | # 50 | # You can disable this behaviour by removing the line below, and instead 51 | # explicitly tag your specs with their type, e.g.: 52 | # 53 | # RSpec.describe UsersController, type: :controller do 54 | # # ... 55 | # end 56 | # 57 | # The different available types are documented in the features, such as in 58 | # https://relishapp.com/rspec/rspec-rails/docs 59 | config.infer_spec_type_from_file_location! 60 | 61 | # Filter lines from Rails gems in backtraces. 62 | config.filter_rails_from_backtrace! 63 | # arbitrary gems may also be filtered via: 64 | # config.filter_gems_from_backtrace("gem name") 65 | 66 | config.after { Telegram.bot.reset } 67 | end 68 | -------------------------------------------------------------------------------- /spec/requests/telegram_webhooks_spec.rb: -------------------------------------------------------------------------------- 1 | RSpec.describe TelegramWebhooksController, telegram_bot: :rails do 2 | describe '#start!' do 3 | subject { -> { dispatch_command :start } } 4 | it { should respond_with_message 'Hi there!' } 5 | end 6 | 7 | describe '#help!' do 8 | subject { -> { dispatch_command :help } } 9 | it { should respond_with_message(/Available cmds/) } 10 | end 11 | 12 | describe 'memoizing with /memo' do 13 | let(:memo) { ->(text) { dispatch_command :memo, text } } 14 | let(:remind_me) { -> { dispatch_command :remind_me } } 15 | let(:text) { 'asd qwe' } 16 | 17 | it 'memoizes from the single message' do 18 | expect(&remind_me).to respond_with_message 'Nothing to remind' 19 | expect { memo[text] }.to respond_with_message 'Remembered!' 20 | expect(&remind_me).to respond_with_message text 21 | expect(&remind_me).to respond_with_message 'Nothing to remind' 22 | end 23 | 24 | it 'memoizes text from subsequest message' do 25 | expect { memo[''] }.to respond_with_message 'What should I remember?' 26 | expect { dispatch_message text }.to respond_with_message 'Remembered!' 27 | expect(&remind_me).to respond_with_message text 28 | end 29 | end 30 | 31 | describe '#keyboard!' do 32 | subject { -> { dispatch_command :keyboard } } 33 | it 'shows keyboard' do 34 | should respond_with_message 'Select something with keyboard:' 35 | expect(bot.requests[:sendMessage].last[:reply_markup]).to be_present 36 | end 37 | 38 | context 'when keyboard button selected' do 39 | subject { -> { dispatch_message 'Smth' } } 40 | before { dispatch_command :keyboard } 41 | it { should respond_with_message "You've selected: Smth" } 42 | end 43 | end 44 | 45 | describe '#inline_keyboard!' do 46 | subject { -> { dispatch_command :inline_keyboard } } 47 | 48 | it 'shows inline keyboard' do 49 | should respond_with_message 'Check my inline keyboard:' 50 | expect(bot.requests[:sendMessage].last.dig(:reply_markup, :inline_keyboard)).to be_present 51 | end 52 | end 53 | 54 | describe '#callback_query', :callback_query do 55 | let(:data) { 'no_alert' } 56 | it { should answer_callback_query('Simple answer') } 57 | 58 | context 'with alert' do 59 | let(:data) { 'alert' } 60 | it { should answer_callback_query(/ALERT/) } 61 | end 62 | end 63 | 64 | describe '#chosen_inline_result' do 65 | subject { -> { dispatch(chosen_inline_result: payload) } } 66 | let(:fetch) { -> { dispatch_command :last_chosen_inline_result } } 67 | let(:payload) { {from: {id: 123}, result_id: 456} } 68 | 69 | it 'memoizes chosen_inline_result' do 70 | expect(&fetch).to respond_with_message 'Mention me to initiate inline query' 71 | subject.call 72 | expect(&fetch).to respond_with_message "You've chosen result ##{payload[:result_id]}" 73 | end 74 | end 75 | 76 | describe '#message' do 77 | subject { -> { dispatch_message text } } 78 | let(:text) { 'some plain text' } 79 | it { should respond_with_message "You wrote: #{text}" } 80 | end 81 | 82 | context 'for unsupported command' do 83 | subject { -> { dispatch_command :makeMeGreatBot } } 84 | it { should respond_with_message 'Can not perform makeMeGreatBot' } 85 | end 86 | 87 | context 'for unsupported feature' do 88 | subject { -> { dispatch time_travel: {back_to: :the_future} } } 89 | it 'does nothing' do 90 | subject.call 91 | expect(response).to be_ok 92 | end 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 16 | RSpec.configure do |config| 17 | # rspec-expectations config goes here. You can use an alternate 18 | # assertion/expectation library such as wrong or the stdlib/minitest 19 | # assertions if you prefer. 20 | config.expect_with :rspec do |expectations| 21 | # This option will default to `true` in RSpec 4. It makes the `description` 22 | # and `failure_message` of custom matchers include text for helper methods 23 | # defined using `chain`, e.g.: 24 | # be_bigger_than(2).and_smaller_than(4).description 25 | # # => "be bigger than 2 and smaller than 4" 26 | # ...rather than: 27 | # # => "be bigger than 2" 28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 29 | end 30 | 31 | # rspec-mocks config goes here. You can use an alternate test double 32 | # library (such as bogus or mocha) by changing the `mock_with` option here. 33 | config.mock_with :rspec do |mocks| 34 | # Prevents you from mocking or stubbing a method that does not exist on 35 | # a real object. This is generally recommended, and will default to 36 | # `true` in RSpec 4. 37 | mocks.verify_partial_doubles = true 38 | end 39 | 40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 41 | # have no way to turn it off -- the option exists only for backwards 42 | # compatibility in RSpec 3). It causes shared context metadata to be 43 | # inherited by the metadata hash of host groups and examples, rather than 44 | # triggering implicit auto-inclusion in groups with matching metadata. 45 | config.shared_context_metadata_behavior = :apply_to_host_groups 46 | 47 | # This allows you to limit a spec run to individual examples or groups 48 | # you care about by tagging them with `:focus` metadata. When nothing 49 | # is tagged with `:focus`, all examples get run. RSpec also provides 50 | # aliases for `it`, `describe`, and `context` that include `:focus` 51 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 52 | config.filter_run_when_matching :focus 53 | 54 | # Allows RSpec to persist some state between runs in order to support 55 | # the `--only-failures` and `--next-failure` CLI options. We recommend 56 | # you configure your source control system to ignore this file. 57 | config.example_status_persistence_file_path = "spec/examples.txt" 58 | 59 | # Limits the available syntax to the non-monkey patched syntax that is 60 | # recommended. For more details, see: 61 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 62 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 63 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 64 | config.disable_monkey_patching! 65 | 66 | # Many RSpec users commonly either run the entire suite or an individual 67 | # file, and it's useful to allow more verbose output when running an 68 | # individual spec file. 69 | if config.files_to_run.one? 70 | # Use the documentation formatter for detailed output, 71 | # unless a formatter has already been configured 72 | # (e.g. via a command-line flag). 73 | config.default_formatter = "doc" 74 | end 75 | 76 | # Print the 10 slowest examples and example groups at the 77 | # end of the spec run, to help surface which specs are running 78 | # particularly slow. 79 | # config.profile_examples = 10 80 | 81 | # Run specs in random order to surface order dependencies. If you find an 82 | # order dependency and want to debug it, you can fix the order by providing 83 | # the seed, which is printed after each run. 84 | # --seed 1234 85 | config.order = :random 86 | 87 | # Seed global randomization in this process using the `--seed` CLI option. 88 | # Setting this allows you to use `--seed` to deterministically reproduce 89 | # test failures related to randomization by passing the same `--seed` value 90 | # as the one that triggered the failure. 91 | Kernel.srand config.seed 92 | end 93 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/storage/.keep -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/tmp/.keep -------------------------------------------------------------------------------- /tmp/pids/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/tmp/pids/.keep -------------------------------------------------------------------------------- /tmp/storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/tmp/storage/.keep -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/vendor/.keep -------------------------------------------------------------------------------- /vendor/javascript/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/telegram-bot-rb/telegram_bot_app/62105ad4e117da5f418d8dca32e3b5daa3f0f685/vendor/javascript/.keep --------------------------------------------------------------------------------