-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.lua
More file actions
243 lines (167 loc) · 5.39 KB
/
main.lua
File metadata and controls
243 lines (167 loc) · 5.39 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
-- -- -- -- --
-- Requires --
-- -- -- -- --
require('slack')
-- -- -- -- -- --
-- Slack Examples --
-- -- -- -- -- --
-- You get an instance of Slack for a specific API key like this
-- The ALLOW_ANY_TOKEN variable will define whether or not SlackIncoming is
-- allowed even if it's token isn't installed for the API key
-- If the instance doesn't already exist, it will be created using the
-- ALLOW_ANY_TOKEN param
local slack = Slack.GetInstance('APIKEY', ALLOW_ANY_TOKEN)
-- Getting the correct Slack instance for a specified token
-- If this returns null then there is no instance allowed for this token
local slack = Slack.GetTokenInstance('TOKEN')
-- To check if a :Send() response has an error, you do this
local hasError = Slack.HasError(response)
-- To prepare a SlackPayload object, simply do
-- The commands available are:
--[[
users.list
channels.history, channels.mark, channels.list
files.list
im.history, im.list
groups.history, groups.list
search.all, search.files, search.messages
chat.postMessage
auth.test
--]]
local payload = slack:Prepare('COMMAND')
-- To set the variables on a payload object, simply do
payload:Set('KEY', 'VARIABLE')
-- You can also do
payload:Set{ key1 = value1, key2 = value2 }
-- To manually unset keys, do
payload:UnSet('KEY')
-- You can also do
payload:Unset{ 'KEY1', 'KEY2', 'KEY3' }
-- :Send() returns the response of the object as a Lua table
-- When sending a payload object, you have two options
slack:Send(payload)
-- Or
payload:Send()
-- You can send messages easily by using a helper function, like so
-- Note that from, to, icon_emoji and icon_url aren't required and can also
-- be passed as nil if you wish to set a variable past it
-- Passing an array to the message or to param will make it act differently
-- A message array sends the message as an attachment (multiple lines, see api.slack.com)
-- A to array makes it notify multiple users, E.G: '@connorvg, @yourmom: '
slack:Message('MESSAGE', 'CHANNEL', 'FROM', 'TO', 'ICON_EMOJI', 'ICON_URL')
-- Or
slack:Message({ 'Line One', 'Line Two' }, 'CHANNEL', 'FROM', { 'TO1', 'TO2', 'TO3' }, nil, 'ICON_URL')
-- -- -- -- -- -- --
-- Payload Examples --
-- -- -- -- -- -- --
-- The payload has some helper functions, just like Slack's :Message()
-- To set a message on the payload whilst being ambiguous as to it being
-- an array (Slack attachment) or string (Slack text)
payload:Message('TEXT')
-- Or
payload:Message{ 'Line One', 'Line Two', 'Line Three' }
-- This sets the channel to interact with
payload:Channel('CHANNEL')
-- This sets the chat.postMessage's from username
payload:Username('USERNAME')
-- Or
payload:From('USERNAME')
-- This is a helper function for mentioning people in a chat.postMessage
payload:To('USER')
-- Or
payload:To{ 'USER1', 'USER2', 'USER3' }
-- The output of this, in Slack it's self, would be as so
--[[
USER1, USER2, USER3: REAL_TEXT
--]]
-- Or
--[[
USER1, USER2, USER3:
REAL_LINE_ONE
REAL_LINE_TWO
REAL_LINE_THREE
--]]
-- To set the Emoji icon of a chat.postMessage
payload:Emoji(':EMOJI:')
-- Or to set the URL icon of a chat.postMessage
payload:Icon('www.example.com/icon.png')
-- -- -- -- -- -- --
-- Utility Examples --
-- -- -- -- -- -- --
-- To get the SlackUtilities instance, you simply do
local utilities = slack:Utilities()
-- There are a lot of *simple* API calls that are implemented
-- These responses are cached in the instance until you manually do it
-- The supported keys are:
--[[
users.list
channels.list
files.list
im.list
groups.list
auth.test
--]]
-- This will clear the full cache
utilities:Clear()
-- This will clear a single key's cache
utilities:Clear('KEY')
-- This will clear many key's caches
utilities:Clear{ 'KEY1', 'KEY2', 'KEY3' }
-- The keys will only be cached after they have been requested
-- Requests are done simply as
utilities:Users()
-- Or
utilities:User('NAME', 'ID')
-- Each one is accessable in a sensible way
utilities:Users()
utilities:Channels()
utilities:Files()
utilities:IMs()
utilities:Groups()
-- ETC
-- The filters, such as :User(NAME, KEY) are supported on a per call basis
-- Both values don't need to be passed, you may pass just one. The supported
-- parameters on a per function basis are:
--[[
User(NAME, ID)
Channel(NAME, ID)
File(NAME, ID)
IM(USER_NAME, ID)
Group(NAME, ID)
--]]
-- There are a few auth.test specific functions that allow for both testing auth
-- and for accessing certain data exposed by auth.test
-- All of the commands are:
-- The full auth.test response
utilities:Auth()
-- The team specific URL
utilities:AuthURL()
-- The team's name
utilities:AuthTeam()
-- The team's ID
utilities:AuthTeamID()
-- The API key owner's user name
utilities:AuthUser()
-- The API key owner's user ID
utilities:AuthUserID()
-- -- -- -- -- -- --
-- Incoming Examples --
-- -- -- -- -- -- --
-- Instantiating the instance
-- This matches the 'Outgoing Webhook' layout
local incoming = SlackIncoming.New {
['token'] = 'TOKEN',
['team_id'] = 'T1',
['channel_id'] = 'C1',
['channel_name'] = 'luaslack',
['timestamp'] = 1,
['user_id'] = 'U1',
['user_name'] = 'connorvg',
['text'] = '!test :D',
['trigger_word'] = '!'
}
-- Returns true if there is an error in the object
local hasError = incoming:HasError()
-- Get's the incoming's instance of Slack
-- If this returns null then there is no intance of Slack allowed for this token
local slack = incoming:Slack()