Create a gist now

Instantly share code, notes, and snippets.

Embed
chatworkAPIでメッセージを送信します。(ES6 / Google Apps Script)
import rooms from './rooms'
const room_id = [room id]; //https://www.chatwork.com/#!rid[room id]
const token = "[chatwork api token]";
global.messages = function () {
let cw = new rooms(room_id, token);
let body = "test";
cw.messages(body);
}
export default class rooms{
constructor(room_id, token){
this.domain = "https://api.chatwork.com";
this.endpoint = "/rooms/{room_id}";
this.version = 2;
this.apiurl = "";
this.header = [];
let apiurl = this.domain + "/v" + this.version + this.endpoint;
this.apiurl = apiurl.replace(/{room_id}/, room_id);
this.header = {"X-ChatWorkToken" : token};
}
messages(body){
let apiurl = this.apiurl + "/messages";
let post_data = {
'body' : body
};
var options = {
"headers" : this.header,
"method" : "post",
"payload" : post_data,
"muteHttpExceptions" : true
};
let res = UrlFetchApp.fetch(apiurl, options);
let txt = res.getContentText();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment