LoginSignup
7

More than 5 years have passed since last update.

GAS→chatworkへメッセージを飛ばす

Last updated at Posted at 2015-08-12

概要

GASでチャットワークへ発言する関数を作成したので手順をまとめました。

これを利用すると以下のようなスクリプトを作成することが出来ます。

例:売上シートの内容をbotアカウントが毎朝つぶやく

参考

GAS - Class UrlFetchApp
ChatWork API - /rooms

事前準備

事前にAPIトークンの生成をしてください。
http://developer.chatwork.com/ja/authenticate.html

チャットワークに発言

[YourAccountAPIToken]には発言させるアカウントのAPIトークンを入力してください。

function sendHttpPost (message, room_id) {

  var payload = {
    "body" : message
  };

  var headers = {
    "X-ChatWorkToken" : [YourAccountAPIToken]
  };

  var options = {
    "method" : "post",
    "payload" : payload,
    "headers" : headers
  };

  UrlFetchApp.fetch("https://api.chatwork.com/v1/rooms/" + room_id + "/messages", options);
}

使用例

function main () {
  sendHttpPost("ピザは野菜もとれるしバランスいい", 99999999);
}

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
7