-
Notifications
You must be signed in to change notification settings - Fork 662
/
Copy pathchat.js
103 lines (90 loc) · 4.06 KB
/
chat.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* API Facet to make calls to methods in the chat namespace.
*
* This provides functions to call:
* - delete: {@link https://api.slack.com/methods/chat.delete|chat.delete}
* - postMessage: {@link https://api.slack.com/methods/chat.postMessage|chat.postMessage}
* - update: {@link https://api.slack.com/methods/chat.update|chat.update}
*
*/
function ChatFacet(makeAPICall) {
this.name = 'chat';
this.makeAPICall = makeAPICall;
}
/**
* Deletes a message.
* @see {@link https://api.slack.com/methods/chat.delete|chat.delete}
*
* @param {?} ts - Timestamp of the message to be deleted.
* @param {?} channel - Channel containing the message to be deleted.
* @param {function=} optCb Optional callback, if not using promises.
*/
ChatFacet.prototype.delete = function delete_(ts, channel, optCb) {
var requiredArgs = {
ts: ts,
channel: channel
};
return this.makeAPICall('chat.delete', requiredArgs, null, optCb);
};
/**
* Sends a message to a channel.
* @see {@link https://api.slack.com/methods/chat.postMessage|chat.postMessage}
*
* @param {?} channel - Channel, private group, or IM channel to send message to. Can be an
* encoded ID, or a name. See [below](#channels) for more details.
* @param {?} text - Text of the message to send. See below for an explanation of
* [formatting](#formatting).
* @param {Object=} opts
* @param {?} opts.parse - Change how messages are treated. Defaults to `none`. See
* [below](#formatting).
* @param {?} opts.link_names - Find and link channel names and usernames.
* @param {?} opts.attachments - Structured message attachments.
* @param {?} opts.unfurl_links - Pass true to enable unfurling of primarily text-based content.
* @param {?} opts.unfurl_media - Pass false to disable unfurling of media content.
* @param {?} opts.username - Set your bot's user name. Must be used in conjunction with `as_user`
* set to false, otherwise ignored. See [authorship](#authorship) below.
* @param {?} opts.as_user - Pass true to post the message as the authed user, instead of as a
* bot. Defaults to false. See [authorship](#authorship) below.
* @param {?} opts.icon_url - URL to an image to use as the icon for this message. Must be used in
* conjunction with `as_user` set to false, otherwise ignored. See [authorship](#authorship)
* below.
* @param {?} opts.icon_emoji - emoji to use as the icon for this message. Overrides `icon_url`.
* Must be used in conjunction with `as_user` set to false, otherwise ignored. See
* [authorship](#authorship) below.
* @param {function=} optCb Optional callback, if not using promises.
*/
ChatFacet.prototype.postMessage = function postMessage(channel, text, opts, optCb) {
var requiredArgs = {
channel: channel,
text: text
};
return this.makeAPICall('chat.postMessage', requiredArgs, opts, optCb);
};
/**
* Updates a message.
* @see {@link https://api.slack.com/methods/chat.update|chat.update}
*
* @param {?} ts - Timestamp of the message to be updated.
* @param {?} channel - Channel containing the message to be updated.
* @param {?} text - New text for the message, using the [default formatting
* rules](/docs/formatting).
* @param {Object=} opts
* @param {?} opts.attachments - Structured message attachments.
* @param {?} opts.parse - Change how messages are treated. Defaults to `client`, unlike
* `chat.postMessage`. See [below](#formatting).
* @param {?} opts.link_names - Find and link channel names and usernames. Defaults to `none`.
* This parameter should be used in conjunction with `parse`. To set `link_names` to `1`, specify
* a `parse` mode of `full`.
* @param {?} opts.as_user - Pass true to update the message as the authed user. [Bot
* users](/bot-users) in this context are considered authed users.
* @param {function=} optCb Optional callback, if not using promises.
*/
ChatFacet.prototype.update = function update(ts, channel, text, opts, optCb) {
var requiredArgs = {
ts: ts,
channel: channel,
text: text
};
return this.makeAPICall('chat.update', requiredArgs, opts, optCb);
};
module.exports = ChatFacet;