Slackでボットを作りたい
Slackでボットを5秒以内に作れるツールを作ったを見ると簡単っぽいけど、本当なのか試してみることにした。
書かれていないことを考えると「BOTを動かすマシンはサーバが望ましい」
適当なサーバがないのでAWS無料枠で出来るのか試してみる。
AWSアカウント登録
普通の個人情報とクレジットカード番号と電話番号が必要
サインインしたら最初に東京
右上「オレゴン」をクリックして、「東京」に変更
お金の確認
右上の「自分の名前」から「請求とコスト管理」で確認、常に確認するべし。
EC2でインスタンス作成
SSH認証
System Requiredをみる
- ruby -v(入っている
- gem -v(入っている
- bundler -v(入っていない
- gem install bundler
- gem list bundler(確認
GitHubから持ってくる
- su ec2-user
- git clone https://github.com/alfa-jpn/BotHeaven.git
環境変数を設定
SlackのアプリケーションIDとキーをhttps://api.slack.com/applicationsから取得
- Name:てきとー
- URL:null
- RedirectURI(s):http://(EC2のパブリックIP):3000/auth/slack/callback
- Description:てきとー
- Team:稼働させるところ
トークンを取得するhttps://api.slack.com/web#authentication
- Teamの「Create token」で発行する
APIのテストhttps://api.slack.com/methods/auth.test/testで「Test Method」でズラズラでてきたらOK
ボットインテグレーションを作成するhttps://slack.com/services/new/bot
Menu > Manage Your Teamに作成される
cd botHeaven
cp .env.example .env
vi .env
SLACK_TEAM_ID=SlackのチームID(auth.testのteam_id
SLACK_APP_ID=SlackのアプリケーションID(Application DetailsのClient ID
SLACK_APP_SECRET=Slackのアプリケーションキー(Application DetailsのClient Secret
SLACK_BOT_NAME=Slackのボット名(BotsのCustomize Name
SLACK_BOT_TOKEN=Slackのボットトークン(BotsのAPI Token
SECRET_KEY_BASE=(http://www.convertstring.com/ja/Hash/SHA256で作成する
Gemをインストール
]# bundle install --path vendor /bundle /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- io/console (LoadError
ダメだって。
EC2でBundle Installすると、io/consoleエラーになるを参考に
$ sudo yum install -y ruby-devel
$ sudo yum install -y ruby20-devel gcc-c++
$ gem install io-console
$ bundle install --path vendor/bundle
(nokogiriでエラー)
$ gem install nokogiri -v '1.6.6.2'
(オプションが悪いっぽい)
$ gem install nokogiri -- --use-system-libraries
$ bundle config build.nokogiri --use-system-libraries
$ bundle install
(pgでエラー)
$ sudo yum -y install postgresql-devel
$ bundle install
(pumaでエラー)
疲れてきた
$ gem install puma -v '2.11.2'
Fetching: rack-1.6.4.gem (100%)
Successfully installed rack-1.6.4
Fetching: puma-2.11.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing puma:
ERROR: Failed to build gem native extension./usr/bin/ruby2.0 extconf.rb
checking for BIO_read() in -lcrypto... no
checking for BIO_read() in -llibeay32... noextconf.rb failed ***
これかな?I want to make sure my Amazon EC2 Linux instance has the latest version of OpenSSL
$ sudo yum update openssl
$ which openssl
/usr/bin/openssl
$ sudo yum install openssl-devel
$ gem install puma -v '2.11.2' -- with-opt-dir=/usr/bin/openssl
Building native extensions with: 'with-opt-dir=/usr/bin/openssl'
This could take a while...
ERROR: Error installing puma:
ERROR: Failed to build gem native extension./usr/bin/ruby2.0 extconf.rb with-opt-dir=/usr/bin/openssl
checking for BIO_read() in -lcrypto... *** extconf.rb failed ***
ちがった。
$ gem install puma -v '2.11.2'
Building native extensions. This could take a while...
Successfully installed puma-2.11.2
Parsing documentation for puma-2.11.2
Installing ri documentation for puma-2.11.2
Done installing documentation for puma after 4 seconds
1 gem installed
なんだ、オプションがいらなかったのか
「puma」をまとめると
$ gem install puma -v '2.11.2'
Fetching: rack-1.6.4.gem (100%)
Successfully installed rack-1.6.4
Fetching: puma-2.11.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing puma:
ERROR: Failed to build gem native extension.
$ sudo yum update openssl
$ sudo yum install openssl-devel
$ gem install puma -v '2.11.2'
次!
$ bundle install --path vendor/bundle
An error occurred while installing sqlite3 (1.3.10), and Bundler cannot
continue.
Make sure that `gem install sqlite3 -v '1.3.10'` succeeds before bundling.
$ gem install sqlite3 -v '1.3.10'
Fetching: sqlite3-1.3.10.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension./usr/bin/ruby2.0 extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
$ sudo yum install sqlite-devel
$ bundle install --path vendor/bundle
・・・おわった
インストール系がやっと終わったとおもうので、実行してみる。
$ bundle exec rails s -e production
=> Booting Puma
=> Rails 4.2.0 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.2 starting...
1436401711* Min threads: 0, max threads: 16
1436401712* Environment: production
1436401713* Listening on tcp://localhost:3000
terminate called after throwing an instance of 'std::runtime_error'
what(): Encryption not available on this event-machine
Aborted
なんとなく
しまった!!!!最初に確認するべきところだぁあああ
まだまだ続く・・・