8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Heroku Schedulerを使ってChatworkに定期ポストする

Last updated at Posted at 2015-07-01

モチベーション

Chatworkに定期ポストして、簡素なリマインダーにしたくあります。
お金はなるべく使わない方向が嬉しいです。

要するに

Defining Node.js task for Heroku Scheduler - Rafal Spacjer blogledsun/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

次の画面が開きます。

スクリーンショット 2015-07-01 11.25.25.png

Add new jobをクリックします。

コマンド名にnotifyを、FREQUENCYをEvery 10 minutesに設定します。

スクリーンショット 2015-07-01 11.27.28.png

Saveボタンをクリックします。

10分毎にチャットルームに通知がくれば成功です。
動作確認ができたら、不要になったjobは削除しましょう。

8
5
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
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?