-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGASlack.gs
40 lines (35 loc) · 852 Bytes
/
GASlack.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var GASlack_ = function(webhookUrl) {
this.webhookUrl = webhookUrl;
this._json = {
text: 'test',
username: 'test user',
icon_emoji: ':full_moon_with_face:'
};
this._options = {};
}
GASlack_.prototype.profile = function(username, icon) {
this._json.username = username || '';
this._json.icon_emoji = icon || '';
return this;
}
GASlack_.prototype.message = function(msg) {
this._json.text = msg || this._json.text;
return this;
}
GASlack_.prototype.send = function() {
var options = {
'method' : 'post',
'contentType' : 'application/json',
'payload' : JSON.stringify(this._json)
};
UrlFetchApp.fetch(this.webhookUrl, options);
}
/*
* initialize Slack
*
* @param {String} webhook Url from Slack
* @return {object} initialized Slack
*/
function init(webhookUrl) {
return new GASlack_(webhookUrl);
}