Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@naosim
Created May 11, 2021 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naosim/b3d2337f97ae918108ec491cb60686e3 to your computer and use it in GitHub Desktop.
Save naosim/b3d2337f97ae918108ec491cb60686e3 to your computer and use it in GitHub Desktop.
GAS用チャットワーククライアント
/**
* 内部でUrlFetchAppを使っています
*/
class ChatWorkClient {
constructor(token) {
this.token = token;
this.baseUrl = 'https://api.chatwork.com/v2';
this.header = { 'X-ChatWorkToken' : token };
}
postMessage(roomId, message) {
const url = `${this.baseUrl}/rooms/${roomId}/messages`;
const options = {
method: 'post',
headers: this.header,
payload: { body: message }
};
UrlFetchApp.fetch(url, options);
}
addTask(roomId, message, toId) {
const url = `${this.baseUrl}/rooms/${roomId}/tasks`;
const options = {
method: 'post',
headers: this.header,
payload: {
body: message,
to_ids: toId
}
};
UrlFetchApp.fetch(url, options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment