非公式ではありますがCLIでmBaaSの操作ができるncmbが、プッシュ通知の作成に対応しました。コマンドラインから細かく絞り込んだプッシュ通知が作成できます。
インストール方法
node.jsが必須になります。その上で、
npm install ncmb -g
にてインストールできます。
プッシュ通知の作成
プッシュ通知で指定できるすべてのオプションに対応しています。
$ ncmb push create --help Usage: ncmb-push-create [options] Options: -h, --help output usage information -V, --version output the version number -a, --application_key [application_key] Your application Key -c, --client_key [client_key] Your client key -i, --immediateDeliveryFlag [immediate] If true, send a push notification immediately -d, --deliveryTime [datetime] Set a delivery time. -t, --target [target] set to ios, android or "ios,android" -m, --message [message] Push notification message -r, --richUrl [URL] Set a URL for rich push notification -s, --search [search_condition] Filter target to send push notifications -b, --badgeIncrementFlag [true or false] If true, budge numbers increment --title [title] Push notification title --userSettingValue [json] Set a json to payload --deliveryExpirationDate [date] Delivery limited date --deliveryExpirationTime [time] Delivery limited time --action [action] Custom receiver action for Android --dialog [true or false] Dialog setting. true or false --badgeSetting [number] Setting badge numbers --sound [sound] Set sound file name --contentAvailable [true or false] If true, push notification send to News stand --category [category] Set a filter of category
例えば以下のようになります。
$ ncmb push create -m "Hello" -d "2016/06/01 19:00" \ -t ios,android -s "badge >= 1" --userSettingValue '{"a": "c"}' \ --title "Test" --richUrl "http://www.moongift.jp/" \ --deliveryExpirationTime "3 hour" --action "test" \ --dialog true --sound test.mp3 \ --contentAvailable true --category 'test'
なお、deliveryExpirationTimeとimmediateDeliveryFlagなど、同時に指定できないオプションを使った場合はエラーになります。
絞り込みが容易
searchConditionを使って配信対象を絞り込めますが、このコマンドの場合はSQL風に書けるようになっています。使い方はデータストアの場合と同じなので、
- = または ==
- <> または !=
- <= または =<
- >= または =>
- <
- >
- in
- not in
であったり、ANDやORも使えるようになっています。手作業でsearchConditionを作るのは面倒ですが、こちらはごく簡単にできます。Cronで実行したり、外部のプログラムから呼び出すことでプッシュ通知作成を自動化することもできます。ぜひお試しください!
機能要望がありましたらmoongift/ncmb-cli: CLI tool for Nifty cloud mobile backendまでお寄せください。