Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 484 lines (423 sloc) 14.763 kb
a4d606c @technoweenie remove redis brain (it will return in hubot-scripts)
technoweenie authored
1 Fs = require 'fs'
2 Url = require 'url'
3 Path = require 'path'
4 EventEmitter = require('events').EventEmitter
b253e94 @atmos fuck a color history
atmos authored
5
6 class Robot
3726dbe @technoweenie document the core robot methods better
technoweenie authored
7 # Robots receive messages from a chat source (Campfire, irc, etc), and
8 # dispatch them to matching listeners.
9 #
10 # path - String directory full of Hubot scripts to load.
a3a58c0 @tombell Attempt at updating tests for new adapter class
tombell authored
11 constructor: (adapterPath, adapter, name = "Hubot") ->
be6b76b @atmos enable '/' instead of hubot as a cli opt
atmos authored
12 @name = name
a4d606c @technoweenie remove redis brain (it will return in hubot-scripts)
technoweenie authored
13 @brain = new Robot.Brain
be6b76b @atmos enable '/' instead of hubot as a cli opt
atmos authored
14 @commands = []
15 @Response = Robot.Response
16 @listeners = []
17 @loadPaths = []
a39b823 @Vrtak-CZ Add --alias (--enable-slash is deprecated)
Vrtak-CZ authored
18 @alias = false
e2f7b6f @tombell Update loading path condition
tombell authored
19
a3a58c0 @tombell Attempt at updating tests for new adapter class
tombell authored
20 Adapter = require "#{adapterPath}/#{adapter}"
3a9d1b5 @tombell Add missing tomdoc comments to functions
tombell authored
21 @adapter = new Adapter @
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
22
3726dbe @technoweenie document the core robot methods better
technoweenie authored
23 # Public: Adds a Listener that attempts to match incoming messages based on
24 # a Regex.
25 #
26 # regex - A Regex that determines if the callback should be called.
27 # callback - A Function that is called with a Response object.
28 #
29 # Returns nothing.
b253e94 @atmos fuck a color history
atmos authored
30 hear: (regex, callback) ->
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
31 @listeners.push new TextListener(@, regex, callback)
b253e94 @atmos fuck a color history
atmos authored
32
bbf0c75 @tombell Update formatting
tombell authored
33 # Public: Adds a Listener that attempts to match incoming messages directed
34 # at the robot based on a Regex. All regexes treat patterns like they begin
35 # with a '^'
be5fce6 @atmos hubot listen or be addressed in chat. fixes #4
atmos authored
36 #
37 # regex - A Regex that determines if the callback should be called.
38 # callback - A Function that is called with a Response object.
39 #
40 # Returns nothing.
41 respond: (regex, callback) ->
42 re = regex.toString().split("/")
18beda1 @atmos handle slashes in regexes properly
atmos authored
43 re.shift() # remove empty first item
44 modifiers = re.pop() # pop off modifiers
45
6780d7a @tombell Update equality checks to use 'is'
tombell authored
46 if re[0] and re[0][0] is "^"
ce149d9 @atmos warn about anchors not working with respond, fixes #10
atmos authored
47 console.log "\nWARNING: Anchors don't work well with respond, perhaps you want to use 'hear'"
48 console.log "WARNING: The regex in question was #{regex.toString()}\n"
49
18beda1 @atmos handle slashes in regexes properly
atmos authored
50 pattern = re.join("/") # combine the pattern back again
a39b823 @Vrtak-CZ Add --alias (--enable-slash is deprecated)
Vrtak-CZ authored
51 if @alias
52 alias = @alias.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") # escape alias for regexp
53 newRegex = new RegExp("^(?:#{alias}|#{@name}[:,]?)\\s*(?:#{pattern})", modifiers)
be6b76b @atmos enable '/' instead of hubot as a cli opt
atmos authored
54 else
fc33244 @lautis Allow comma when addressing Hubot
lautis authored
55 newRegex = new RegExp("^#{@name}[:,]?\\s*(?:#{pattern})", modifiers)
18beda1 @atmos handle slashes in regexes properly
atmos authored
56
2b432ff @atmos make hubot easier for first timers
atmos authored
57 console.log newRegex.toString()
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
58 @listeners.push new TextListener(@, newRegex, callback)
59
60 # Public: Adds a Listener that triggers when anyone enters the room.
61 #
62 # callback - A Function that is called with a Response object.
63 #
64 # Returns nothing.
65 enter: (callback) ->
66 @listeners.push new Listener(@, ((msg) -> msg instanceof Robot.EnterMessage), callback)
67
68 # Public: Adds a Listener that triggers when anyone leaves the room.
69 #
70 # callback - A Function that is called with a Response object.
71 #
72 # Returns nothing.
73 leave: (callback) ->
74 @listeners.push new Listener(@, ((msg) -> msg instanceof Robot.LeaveMessage), callback)
be5fce6 @atmos hubot listen or be addressed in chat. fixes #4
atmos authored
75
3726dbe @technoweenie document the core robot methods better
technoweenie authored
76 # Public: Passes the given message to any interested Listeners.
77 #
78 # message - A Robot.Message instance.
79 #
80 # Returns nothing.
b253e94 @atmos fuck a color history
atmos authored
81 receive: (message) ->
56a1115 @tombell Update forEach calls to be comprehensions
tombell authored
82 for lst in @listeners
f37292a @eventualbuddha Give some indication that a script listener threw an exception.
eventualbuddha authored
83 try
84 lst.call message
85 catch ex
86 console.log "error while calling listener: #{ex}"
b253e94 @atmos fuck a color history
atmos authored
87
3726dbe @technoweenie document the core robot methods better
technoweenie authored
88 # Public: Loads every script in the given path.
89 #
90 # path - A String path on the filesystem.
91 #
92 # Returns nothing.
b253e94 @atmos fuck a color history
atmos authored
93 load: (path) ->
a5b8d5d @atmos make hubot-scripts development easier
atmos authored
94 Path.exists path, (exists) =>
95 if exists
96 @loadPaths.push path
df4912b @tombell Update to use for x in y instead of forEach
tombell authored
97 for file in Fs.readdirSync(path)
a5b8d5d @atmos make hubot-scripts development easier
atmos authored
98 @loadFile path, file
99
100 # Public: Loads a file in path
101 #
102 # path - A String path on the filesystem.
103 # file - A String filename in path on the filesystem.
104 #
105 # Returns nothing.
106 loadFile: (path, file) ->
107 ext = Path.extname file
108 full = Path.join path, Path.basename(file, ext)
6780d7a @tombell Update equality checks to use 'is'
tombell authored
109 if ext is '.coffee' or ext is '.js'
a5b8d5d @atmos make hubot-scripts development easier
atmos authored
110 require(full) @
845e37e @atmos parse help on a per-script basis
atmos authored
111 @parseHelp "#{path}/#{file}"
112
113 # Public: Help Commands for Running Scripts
114 #
115 # Returns an array of help commands for running scripts
116 #
117 helpCommands: () ->
118 @commands.sort()
119
120 # Private: load help info from a loaded script
121 #
122 # path - The path to the file on disk
123 #
124 # Returns nothing
125 parseHelp: (path) ->
126 Fs.readFile path, "utf-8", (err, body) =>
127 throw err if err
128 for i, line of body.split("\n")
1d1b69d @jasford Updated the help generator to allow for .js scripts to include help l…
jasford authored
129 break if !(line[0] == '#' or line.substr(0, 2) == '//')
845e37e @atmos parse help on a per-script basis
atmos authored
130 continue if !line.match('-')
131 @commands.push line[2..line.length]
b253e94 @atmos fuck a color history
atmos authored
132
3a9d1b5 @tombell Add missing tomdoc comments to functions
tombell authored
133 # Public: Get an Array of User objects stored in the brain.
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
134 users: ->
135 @brain.data.users
136
432e818 @tombell Update to fix the robot name not getting passed through
tombell authored
137 # Public: Get a User object given a unique identifier.
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
138 userForId: (id, options) ->
139 user = @brain.data.users[id]
140 unless user
141 user = new Robot.User id, options
142 @brain.data.users[id] = user
143 user
144
432e818 @tombell Update to fix the robot name not getting passed through
tombell authored
145 # Public: Get a User object given a name.
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
146 userForName: (name) ->
147 result = null
148 lowerName = name.toLowerCase()
149 for k of (@brain.data.users or { })
150 if @brain.data.users[k]['name'].toLowerCase() is lowerName
151 result = @brain.data.users[k]
152 result
153
52bcdd3 @russelldavis Move fuzzy matching to its own function.
russelldavis authored
154 # Public: Get all users whose names match fuzzyName. Currently, match
155 # means 'starts with', but this could be extended to match initials,
156 # nicknames, etc.
157 #
158 usersForRawFuzzyName: (fuzzyName) ->
159 lowerFuzzyName = fuzzyName.toLowerCase()
160 user for key, user of (@brain.data.users or {}) when (
161 user.name.toLowerCase().lastIndexOf(lowerFuzzyName, 0) == 0)
162
163 # Public: If fuzzyName is an exact match for a user, returns an array with
164 # just that user. Otherwise, returns an array of all users for which
165 # fuzzyName is a raw fuzzy match (see usersForRawFuzzyName).
166 #
167 usersForFuzzyName: (fuzzyName) ->
f3d86be @tombell Merge branch 'matchPartialNames' of https://github.com/russelldavis/h…
tombell authored
168 matchedUsers = @usersForRawFuzzyName(fuzzyName)
52bcdd3 @russelldavis Move fuzzy matching to its own function.
russelldavis authored
169 lowerFuzzyName = fuzzyName.toLowerCase()
170 # We can scan matchedUsers rather than all users since usersForRawFuzzyName
171 # will include exact matches
172 for user in matchedUsers
173 return [user] if user.name.toLowerCase() is lowerFuzzyName
174
175 matchedUsers
176
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
177 run: ->
178 @adapter.run()
179
180 class Robot.Adapter
3a9d1b5 @tombell Add missing tomdoc comments to functions
tombell authored
181 # An adapter is a specific interface to a chat source for robots.
182 #
183 # robot - A Robot instance.
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
184 constructor: (@robot) ->
185
3726dbe @technoweenie document the core robot methods better
technoweenie authored
186 # Public: Raw method for sending data back to the chat source. Extend this.
187 #
188 # user - A Robot.User instance.
189 # strings - One or more Strings for each message to send.
b253e94 @atmos fuck a color history
atmos authored
190 send: (user, strings...) ->
191
3726dbe @technoweenie document the core robot methods better
technoweenie authored
192 # Public: Raw method for building a reply and sending it back to the chat
193 # source. Extend this.
194 #
195 # user - A Robot.User instance.
196 # strings - One or more Strings for each reply to send.
b253e94 @atmos fuck a color history
atmos authored
197 reply: (user, strings...) ->
198
7c9e8a8 @markstory Adding topic support.
markstory authored
199 # Public: Raw method for setting a topic on the chat source. Extend this.
200 #
201 # user - A Robot.User instance
202 # strings - One more more Strings to set as the topic.
203 topic: (user, strings...) ->
204
3726dbe @technoweenie document the core robot methods better
technoweenie authored
205 # Public: Raw method for invoking the bot to run
b253e94 @atmos fuck a color history
atmos authored
206 # Extend this.
3726dbe @technoweenie document the core robot methods better
technoweenie authored
207 run: ->
b253e94 @atmos fuck a color history
atmos authored
208
f43d021 @technoweenie get the tests actually running
technoweenie authored
209 # Public: Raw method for shutting the bot down.
210 # Extend this.
211 close: ->
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
212 @robot.brain.close()
f43d021 @technoweenie get the tests actually running
technoweenie authored
213
3a9d1b5 @tombell Add missing tomdoc comments to functions
tombell authored
214 # Public: Dispatch a received message to the robot.
215 #
216 # message - A TextMessage instance of the received message.
217 #
218 # Returns nothing.
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
219 receive: (message) ->
220 @robot.receive message
221
3a9d1b5 @tombell Add missing tomdoc comments to functions
tombell authored
222 # Public: Get an Array of User objects stored in the brain.
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
223 users: ->
224 @robot.users
1875856 @atmos robot brain in redis
atmos authored
225
226 # Public: Get a User object given a unique identifier
227 userForId: (id, options) ->
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
228 @robot.userForId id, options
1875856 @atmos robot brain in redis
atmos authored
229
230 # Public: Get a User object given a name
231 userForName: (name) ->
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
232 @robot.userForName name
233
f3d86be @tombell Merge branch 'matchPartialNames' of https://github.com/russelldavis/h…
tombell authored
234 # Public: Get all users whose names match fuzzyName. Currently, match
235 # means 'starts with', but this could be extended to match initials,
236 # nicknames, etc.
237 #
238 usersForRawFuzzyName: (fuzzyName) ->
239 @robot.usersForRawFuzzyName fuzzyName
240
241 # Public: If fuzzyName is an exact match for a user, returns an array with
242 # just that user. Otherwise, returns an array of all users for which
243 # fuzzyName is a raw fuzzy match (see usersForRawFuzzyName).
244 #
245 usersForFuzzyName: (fuzzyName) ->
246 @robot.usersForFuzzyName fuzzyName
1875856 @atmos robot brain in redis
atmos authored
247
23e72da @tombell Small refactor of twilio adapter
tombell authored
248 # Public: Creates a scoped http client with chainable methods for
249 # modifying the request. This doesn't actually make a request though.
250 # Once your request is assembled, you can call `get()`/`post()`/etc to
251 # send the request.
252 #
253 # url - String URL to access.
254 #
255 # Examples:
256 #
257 # res.http("http://example.com")
258 # # set a single header
259 # .header('Authorization', 'bearer abcdef')
260 #
261 # # set multiple headers
262 # .headers(Authorization: 'bearer abcdef', Accept: 'application/json')
263 #
264 # # add URI query parameters
265 # .query(a: 1, b: 'foo & bar')
266 #
267 # # make the actual request
268 # .get() (err, res, body) ->
269 # console.log body
270 #
271 # # or, you can POST data
272 # .post(data) (err, res, body) ->
273 # console.log body
274 #
275 # Returns a ScopedClient instance.
276 http: (url) ->
277 @httpClient.create(url)
278
f3d86be @tombell Merge branch 'matchPartialNames' of https://github.com/russelldavis/h…
tombell authored
279
53d76c3 @technoweenie add real user/message objects
technoweenie authored
280 class Robot.User
3726dbe @technoweenie document the core robot methods better
technoweenie authored
281 # Represents a participating user in the chat.
282 #
283 # id - A unique ID for the user.
284 # options - An optional Hash of key, value pairs for this user.
1875856 @atmos robot brain in redis
atmos authored
285 constructor: (@id, options = { }) ->
286 for k of (options or { })
287 @[k] = options[k]
288
f43d021 @technoweenie get the tests actually running
technoweenie authored
289 # http://www.the-isb.com/images/Nextwave-Aaron01.jpg
a4d606c @technoweenie remove redis brain (it will return in hubot-scripts)
technoweenie authored
290 class Robot.Brain extends EventEmitter
1875856 @atmos robot brain in redis
atmos authored
291 # Represents somewhat persistent storage for the robot.
292 #
8354140 @technoweenie Robot.RedisBrain extends Robot.Brain
technoweenie authored
293 # Returns a new Brain with no external storage. Extend this!
294 constructor: () ->
295 @data =
296 users: { }
297
2230dfd @technoweenie allow configurable save interval for the brain
technoweenie authored
298 @resetSaveInterval 5
a4d606c @technoweenie remove redis brain (it will return in hubot-scripts)
technoweenie authored
299
3a9d1b5 @tombell Add missing tomdoc comments to functions
tombell authored
300 # Emits the 'save' event so that 'brain' scripts can handle persisting.
301 #
302 # Returns nothing.
a4d606c @technoweenie remove redis brain (it will return in hubot-scripts)
technoweenie authored
303 save: ->
304 @emit 'save', @data
305
3a9d1b5 @tombell Add missing tomdoc comments to functions
tombell authored
306 # Emits the 'close' event so that 'brain' scripts can handle closing.
307 #
308 # Returns nothing.
8354140 @technoweenie Robot.RedisBrain extends Robot.Brain
technoweenie authored
309 close: ->
a4d606c @technoweenie remove redis brain (it will return in hubot-scripts)
technoweenie authored
310 clearInterval @saveInterval
311 @save()
312 @emit 'close'
8354140 @technoweenie Robot.RedisBrain extends Robot.Brain
technoweenie authored
313
3a9d1b5 @tombell Add missing tomdoc comments to functions
tombell authored
314 # Reset the interval between save function calls.
315 #
316 # seconds - An Integer of seconds between saves.
317 #
318 # Returns nothing.
2230dfd @technoweenie allow configurable save interval for the brain
technoweenie authored
319 resetSaveInterval: (seconds) ->
320 clearInterval @saveInterval if @saveInterval
321 @saveInterval = setInterval =>
322 @save()
323 , seconds * 1000
324
8354140 @technoweenie Robot.RedisBrain extends Robot.Brain
technoweenie authored
325 # Merge keys loaded from a DB against the in memory representation
326 #
327 # Returns nothing
328 #
329 # Caveats: Deeply nested structures don't merge well
330 mergeData: (data) ->
331 for k of (data or { })
332 @data[k] = data[k]
2b99aa2 @atmos whitespace
atmos authored
333
95e85fd @codec Also emit the @data
codec authored
334 @emit 'loaded', @data
8354140 @technoweenie Robot.RedisBrain extends Robot.Brain
technoweenie authored
335
53d76c3 @technoweenie add real user/message objects
technoweenie authored
336 class Robot.Message
3726dbe @technoweenie document the core robot methods better
technoweenie authored
337 # Represents an incoming message from the chat.
338 #
339 # user - A Robot.User instance that sent the message.
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
340 constructor: (@user) ->
341
342 class Robot.TextMessage extends Robot.Message
343 # Represents an incoming message from the chat.
344 #
345 # user - A Robot.User instance that sent the message.
3726dbe @technoweenie document the core robot methods better
technoweenie authored
346 # text - The String message contents.
347 constructor: (@user, @text) ->
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
348 super @user
53d76c3 @technoweenie add real user/message objects
technoweenie authored
349
3726dbe @technoweenie document the core robot methods better
technoweenie authored
350 # Determines if the message matches the given regex.
351 #
352 # regex - The Regex to check.
353 #
354 # Returns a Match object or null.
53d76c3 @technoweenie add real user/message objects
technoweenie authored
355 match: (regex) ->
356 @text.match regex
357
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
358 # Represents an incoming user entrance notification.
359 #
360 # user - A Robot.User instance for the user who entered.
361 class Robot.EnterMessage extends Robot.Message
362
363 # Represents an incoming user exit notification.
364 #
365 # user - A Robot.User instance for the user who left.
366 class Robot.LeaveMessage extends Robot.Message
367
b253e94 @atmos fuck a color history
atmos authored
368 class Listener
bbf0c75 @tombell Update formatting
tombell authored
369 # Listeners receive every message from the chat source and decide if they
370 # want to act on it.
3726dbe @technoweenie document the core robot methods better
technoweenie authored
371 #
372 # robot - The current Robot instance.
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
373 # matcher - The Function that determines if this listener should trigger the
3726dbe @technoweenie document the core robot methods better
technoweenie authored
374 # callback.
375 # callback - The Function that is triggered if the incoming message matches.
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
376 constructor: (@robot, @matcher, @callback) ->
b253e94 @atmos fuck a color history
atmos authored
377
3726dbe @technoweenie document the core robot methods better
technoweenie authored
378 # Public: Determines if the listener likes the content of the message. If
379 # so, a Response built from the given Message is passed to the Listener
380 # callback.
381 #
382 # message - a Robot.Message instance.
383 #
384 # Returns nothing.
b253e94 @atmos fuck a color history
atmos authored
385 call: (message) ->
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
386 if match = @matcher message
1e4ae57 @technoweenie google images tests
technoweenie authored
387 @callback new @robot.Response(@robot, message, match)
b253e94 @atmos fuck a color history
atmos authored
388
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored
389 class TextListener extends Listener
390 # TextListeners receive every message from the chat source and decide if they want
391 # to act on it.
392 #
393 # robot - The current Robot instance.
394 # regex - The Regex that determines if this listener should trigger the
395 # callback.
396 # callback - The Function that is triggered if the incoming message matches.
397 constructor: (@robot, @regex, @callback) ->
398 @matcher = (message) =>
399 if message instanceof Robot.TextMessage
400 message.match @regex
401
1e4ae57 @technoweenie google images tests
technoweenie authored
402 class Robot.Response
3726dbe @technoweenie document the core robot methods better
technoweenie authored
403 # Public: Responses are sent to matching listeners. Messages know about the
404 # content and user that made the original message, and how to reply back to
405 # them.
406 #
407 # robot - The current Robot instance.
408 # message - The current Robot.Message instance.
409 # match - The Match object from the successful Regex match.
b253e94 @atmos fuck a color history
atmos authored
410 constructor: (@robot, @message, @match) ->
411
3726dbe @technoweenie document the core robot methods better
technoweenie authored
412 # Public: Posts a message back to the chat source
b253e94 @atmos fuck a color history
atmos authored
413 #
414 # strings - One or more strings to be posted. The order of these strings
415 # should be kept intact.
416 #
417 # Returns nothing.
418 send: (strings...) ->
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
419 @robot.adapter.send @message.user, strings...
b253e94 @atmos fuck a color history
atmos authored
420
7c9e8a8 @markstory Adding topic support.
markstory authored
421 # Public: Posts a topic changing message
422 #
2b99aa2 @atmos whitespace
atmos authored
423 # strings - One or more strings to set as the topic of the
7c9e8a8 @markstory Adding topic support.
markstory authored
424 # room the bot is in.
425 #
426 # Returns nothing.
427 topic: (strings...) ->
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
428 @robot.adapter.topic @message.user, strings...
7c9e8a8 @markstory Adding topic support.
markstory authored
429
3726dbe @technoweenie document the core robot methods better
technoweenie authored
430 # Public: Posts a message mentioning the current user.
b253e94 @atmos fuck a color history
atmos authored
431 #
432 # strings - One or more strings to be posted. The order of these strings
433 # should be kept intact.
434 #
435 # Returns nothing.
436 reply: (strings...) ->
792567b @tombell Update Campfire, IRC and Shell adapters
tombell authored
437 @robot.adapter.reply @message.user, strings...
b253e94 @atmos fuck a color history
atmos authored
438
3726dbe @technoweenie document the core robot methods better
technoweenie authored
439 # Public: Picks a random item from the given items.
440 #
441 # items - An Array of items (usually Strings).
442 #
443 # Returns a random item.
b253e94 @atmos fuck a color history
atmos authored
444 random: (items) ->
445 items[ Math.floor(Math.random() * items.length) ]
446
158e963 @technoweenie use scoped-http-client
technoweenie authored
447 # Public: Creates a scoped http client with chainable methods for
448 # modifying the request. This doesn't actually make a request though.
449 # Once your request is assembled, you can call `get()`/`post()`/etc to
450 # send the request.
451 #
452 # url - String URL to access.
453 #
454 # Examples:
f796552 @atmos cleanup shitty variable usage
atmos authored
455 #
158e963 @technoweenie use scoped-http-client
technoweenie authored
456 # res.http("http://example.com")
457 # # set a single header
458 # .header('Authorization', 'bearer abcdef')
459 #
460 # # set multiple headers
461 # .headers(Authorization: 'bearer abcdef', Accept: 'application/json')
462 #
463 # # add URI query parameters
464 # .query(a: 1, b: 'foo & bar')
465 #
466 # # make the actual request
467 # .get() (err, res, body) ->
468 # console.log body
469 #
470 # # or, you can POST data
471 # .post(data) (err, res, body) ->
472 # console.log body
473 #
474 # Returns a ScopedClient instance.
475 http: (url) ->
476 @httpClient.create(url)
477
23e72da @tombell Small refactor of twilio adapter
tombell authored
478 HttpClient = require 'scoped-http-client'
479
480 Robot.Response::httpClient = HttpClient
481 Robot::httpClient = HttpClient
b253e94 @atmos fuck a color history
atmos authored
482
483 module.exports = Robot
Something went wrong with that request. Please try again.