Skip to content

Instantly share code, notes, and snippets.

@bz0
Created November 5, 2017 16:00
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 bz0/de445b369720fc92a424e00ef91f53c9 to your computer and use it in GitHub Desktop.
Save bz0/de445b369720fc92a424e00ef91f53c9 to your computer and use it in GitHub Desktop.
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