Created
November 5, 2017 16:00
-
-
Save bz0/de445b369720fc92a424e00ef91f53c9 to your computer and use it in GitHub Desktop.
chatworkAPIでメッセージを送信します。(ES6 / Google Apps Script)
This file contains 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
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); | |
} |
This file contains 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
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