モチベーション
Chatworkに定期ポストして、簡素なリマインダーにしたくあります。
お金はなるべく使わない方向が嬉しいです。
要するに
Defining Node.js task for Heroku Scheduler - Rafal Spacjer blogとledsun/post-chatwork-messageを組み合わせます。
手順
配置する空プロジェクトを作ります
ディレクトリを作ります。
mkdir notyfication-sender
gitを初期化します。
cd notyfication-sender
git init
npmライブラリーを使いたいのでpackage.jsonを作ります。
npm init
コミットします。
git add .
git commit -m "init"
配置します
herokuにログインします。
heroku login
アプリケーションを作ります。
heroku create notyfication-sender
配置
git push heroku master
通知コマンドを作ります
利用するnpmパッケージを追加します。
npm install --save post-chatwork-message
binディレクトリを作ります。
mkdir bin
通知コマンドを作ります。
cd bin
touch notify
次のshebangを指定するとnode.jsのスクリプトが実行できます。
# !/usr/bin/env node
notifyコマンドの中身は次のようになります。
# !/usr/bin/env node
var postChatworkMessage = require('post-chatwork-message')
var APIKey = 'YOUR_API_TOKEN',
roomId = 'TARGET_CHATROOM_ID'
postChatworkMessage(APIKey, roomId, 'hello world')
試しに実行します。
node notify
指定したチャットルームに通知ができれば成功です。
通知コマンドを配置します
git add .
git commit -m "Code for scheduler task"
git push heroku master
試しに実行してみます。notyfication-senderディレクトリで次のコマンドを実行します。
heroku run notify
指定したチャットルームに通知ができれば成功です。
スケジューラーを設定します
herokuのアドオンを追加します。notyfication-senderディレクトリで
heroku addons:create scheduler:standard
heroku addons:open scheduler
次の画面が開きます。
Add new job
をクリックします。
コマンド名にnotify
を、FREQUENCYをEvery 10 minutes
に設定します。
Save
ボタンをクリックします。
10分毎にチャットルームに通知がくれば成功です。
動作確認ができたら、不要になったjobは削除しましょう。