/**
* Chatwork のユーザーIDを取得する
*
* 参考URL(公式APIドキュメント):
* https://developer.chatwork.com/docs
*
*/
function getAllChatworkIds() {
// チャットルームのIDを定義
const room_ids = {
'チャットグループ1': '000000000',
'チャットグループ2': '111111111',
};
// 各ルームIDに対してメンバーIDを取得
for (let key in room_ids) {
console.log("===== " + key + " =====");
getChatworkId(room_ids[key]);
}
}
function getChatworkId(room_id) {
api_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
end_point = 'https://api.chatwork.com/v2/rooms/' + room_id + '/members';
const options = {
method: 'GET',
headers: {
accept: 'application/json',
'x-chatworktoken': api_token
}
};
let response = UrlFetchApp.fetch('https://api.chatwork.com/v2/rooms/' + room_id + '/members', options).getContentText();
response = unicodeUnescape(response);
response = response.replace(/,/g, ",\n\t");
response = response.replace(/{/g, "\n{");
Logger.log(response);
}
/**
* Unicode(¥uxxx形式)を文字列へアンエスケープ
* @param {string} str エスケープされた文字を含む文字列
* @return 文字列へアンエスケープされた文字列を返す
*/
function unicodeUnescape(str) {
let ret = str;
let matches = str.match(/\\u.{4}/gi);
for (let ii = 0; ii < matches.length; ii++) {
let new_str = String.fromCharCode(matches[ii].replace("\\u", "0x"));
let old_str = matches[ii];
ret = ret.replace(old_str, new_str);
}
return ret;
};