Created
May 11, 2021 20:17
-
-
Save naosim/b3d2337f97ae918108ec491cb60686e3 to your computer and use it in GitHub Desktop.
GAS用チャットワーククライアント
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 内部で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