-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessage.js
More file actions
63 lines (61 loc) · 1.23 KB
/
message.js
File metadata and controls
63 lines (61 loc) · 1.23 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Message {
constructor(message) {
Object.assign(this, message);
}
static create(message) {
return new Message(message);
}
static reply(msgtype, data) {
return {
msgtype,
[msgtype]: data,
at: {
atMobiles: [],
isAtAll: false
}
};
}
at(isAtAll, atMobiles) {
this.at = { isAtAll, atMobiles };
return this;
}
text(content) {
this.msgtype = 'text';
this.text = { content };
return this;
}
link(title, link, options) {
this.msgtype = 'link';
if (typeof title === 'object') {
this.link = title;
} else {
this.link = Object.assign({
title,
text: title,
messageUrl: link,
}, options);
}
return this;
}
markdown(title, text) {
this.msgtype = 'markdown';
this.markdown = { title, text };
return this;
}
actionCard(actionCard) {
this.msgtype = 'actionCard';
this.actionCard = actionCard;
return this;
}
feedCard(feedCard) {
this.msgtype = 'feedCard';
this.feedCard = feedCard;
return this;
}
send() {
if (!this.dingtalk)
throw new Error('Can not access DingTalk instance');
return this.dingtalk.send(this);
}
}
module.exports = Message;