LoginSignup
0
0

More than 1 year has passed since last update.

GASでChat Work通知

Posted at

やること

スプレットシートの情報をGASでChat Work通知する

コード

function myFunction() {

//Chat Work API
const token = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
const base_url = 'https://api.chatwork.com/v2';
const room_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
const url = base_url + '/rooms/' + room_id + '/messages';

//スプレットシート
const sheet_id = 'xxxxxxxxxxxxxxxxxxxxx';
const ss = SpreadsheetApp.openById(sheet_id);
const sheet = ss.getSheetByName("シート 1");
const cell = sheet.getDataRange().getValues();
const value = cell.toString();

//確認のため
console.log(value);

const options = {
'method': 'post',
'headers': {'X-ChatWorkToken' : token},
'payload': {'body' : value}
};

const result = UrlFetchApp.fetch(url, options);
const json = JSON.parse(result.getContentText());
    
//確認のため
console.log(json);

}

room_idはCWのURLに入っているrid以降
sheet_idはスプレットシートのURLに入っているspreadsheets/d/以降

気をつけること

setValue:1 つのデータだけをセットする
setValues:複数のデータをセットする

sがついているかついていないかで大きく変わる!!

最後に

今回は全てのセルを取得してますが自動でスプレットシートにデータが入ってきたら、範囲を指定してCWで通知するとか使えそうですね。

参考文献

0
0
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
0
0