Created
May 2, 2016 19:10
-
-
Save bnmrrs/198c1241755f7f8d6988566c55df9a8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bot Rails Template | |
# | |
# Use this script to help generate a Rails bot. | |
# | |
# rails new rails_app -m bot_template.rb | |
# | |
run "rm Gemfile" | |
run "touch Gemfile" | |
add_source 'http://rubygems.org' | |
gem 'rails', '4.2.6' | |
#gem 'bundler', '1.12.0' | |
gem 'sass-rails', '~> 5.0' | |
gem 'uglifier', '>= 1.3.0' | |
gem 'coffee-rails', '~> 4.1.0' | |
gem 'jquery-rails' | |
gem 'turbolinks' | |
gem 'jbuilder', '~> 2.0' | |
gem 'bot' | |
gem_group :development do | |
gem 'quiet_assets' | |
end | |
gem_group :development, :test do | |
gem 'sqlite3' | |
gem 'dotenv-rails' | |
gem 'pry' | |
gem 'web-console', '~> 2.0' | |
gem 'spring' | |
end | |
gem_group :production do | |
gem 'pg' | |
gem 'puma' | |
gem 'rails_12factor' | |
end | |
run "bundle install" | |
# Generate the required files for our Bot gem | |
run "rails generate bot:install" | |
# Add the Bot route so Kik can send notifications | |
route "mount_bot 'kik-notify'" | |
# Find out what our Bot details are | |
bot_name = ask "What is your bot username?" | |
bot_token = ask "What is your bot API key? (https://dev.kik.com/#/engine)" | |
host_url = ask "What is your host url? (eg: https://mybot.ngrok.io)" | |
use_mixpanel = yes?("Would you like to use Mixpanel?") | |
run "touch .ruby-version" | |
run "touch .ruby-gemset" | |
append_file ".ruby-version", "2.2.2" | |
append_file ".ruby-gemset", bot_name | |
# Persist our Bot details using dotenv | |
file '.env', <<-CODE | |
KIK_BOT_USER=#{bot_name} | |
KIK_TOKEN=#{bot_token} | |
HOST_URL=#{host_url} | |
CALLBACK_URL=#{host_url}/kik-notify | |
REDIS_URL=redis://localhost:6379/15 | |
CODE | |
if use_mixpanel | |
mixpanel_token = ask "What is your Mixpanel token?" | |
gem 'mixpanel-ruby' | |
append_file ".env", "MIXPANEL_TOKEN=#{mixpanel_token}" | |
initializer 'mixpanel.rb', <<-CODE | |
MIXPANEL = Mixpanel::Tracker.new(ENV['MIXPANEL_TOKEN']) | |
CODE | |
end | |
file 'config/puma.rb', <<-CODE | |
workers Integer(ENV['WEB_CONCURRENCY'] || 1) | |
threads_count = Integer(ENV['MAX_THREADS'] || 5) | |
threads threads_count, threads_count | |
preload_app! | |
rackup DefaultRackup | |
port ENV['PORT'] || 3000 | |
environment ENV['RACK_ENV'] || 'development' | |
CODE | |
# Remove our default bot initializer and replace it with one that uses ENV | |
# to get the bot details | |
run "rm config/initializers/bot.rb" | |
initializer 'bot.rb', <<-CODE | |
Bot.configure do |config| | |
config.adapter = Bot::Adapter::Kik.new(bot_user: ENV['KIK_BOT_USER'], bot_token: ENV['KIK_TOKEN']) | |
config.redis = Redis.new | |
end | |
CODE | |
append_file ".gitignore", <<-CODE | |
.env | |
CODE | |
# Generate a User model | |
generate :model, "User", "username:string", "introduced:boolean" | |
rake "db:migrate" | |
# Tell Kik about our bot | |
rake "bot:kik:configure" | |
run "git init" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment