LoginSignup
3
4

More than 5 years have passed since last update.

line-notify を使った rails アプリ

Last updated at Posted at 2016-10-24

参考資料

github

Dockerfile

FROM ubuntu:16.04
WORKDIR /root
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y git build-essential libssl-dev libreadline-dev
RUN git clone https://github.com/rbenv/rbenv.git /root/.rbenv
RUN cd /root/.rbenv && src/configure && make -C src
RUN echo 'export PATH="/root/.rbenv/bin:$PATH"' >> /root/.bashrc
RUN echo 'eval "$(rbenv init -)"' >> /root/.bashrc
SHELL ["/bin/bash", "--rcfile", "~/.bashrc", "-ci"]
ENV RUBY_VERSION 2.5.0
RUN mkdir -p "$(rbenv root)"/plugins \
&& git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build \
&& apt-get install -y curl \
&& curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash \
&& CONFIGURE_OPTS="--disable-install-rdoc" rbenv install -v $RUBY_VERSION \
&& rbenv rehash \
&& rbenv global $RUBY_VERSION \
&& ruby -v
RUN gem update --system
RUN gem install bundler --no-document --force
RUN gem install oauth2
RUN gem install rails
RUN apt-get install -y sqlite3 libsqlite3-dev tzdata
RUN git clone https://github.com/bamchoh/line-notify
WORKDIR /root/line-notify
RUN bundle install
ADD settings.yml /root/line-notify/config/
EXPOSE 8080
CMD ["/bin/bash", "--rcfile", "~/.bashrc", "-ci", "rails s -b 0.0.0.0 -p 8080"]

docker build

docker build -t line-notify .

settings.yml

settings.yaml
development:
  client_id: "xxxxx"
  client_secret: "yyyyy"
  callback: "http://192.168.0.100"

test:
  client_id: "xxxxx"
  client_secret: "yyyyy"
  callback: "http://192.168.0.100"

production:
  client_id: "xxxxx"
  client_secret: "yyyyy"
  callback: "http://192.168.0.100"

client_id, client_secretはline-notifyにサービスと登録したときに出てくる文字列を指定。callbackにはoauth認証をした後に帰ってきてほしいURLを指定。サービスを登録したときのcallbackとちゃんと合わさないとエラーになるので注意。

docker run

docker run -p 80:8080 -t line-notify

ブラウザからアクセス

{docker runしたコンテナのIP}/oauth/indexにアクセスするとこんな感じの画面が出てきます。

image

認証押すとline-notifyのログイン画面に遷移するので、ログインして、適当に部屋決めて認証すると、以下のような画面に戻ってきます。

image

テキストボックスに何か文字を入力して送信ボタンを押すとLINEにメッセージが送信されます。簡単ですね。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4