 
   # init for actions
   httpclients.actions
-  .get(errorHandler robot) (err, res, body) ->
+  .get(errorHandler) (err, res, body) ->
     actions = JSON.parse body
     robot.brain.set 'actions', _.zipObject _.map(actions, 'name'), actions
 
   httpclients.actiontypes
-    .get(errorHandler robot) (err, res, body) ->
+    .get(errorHandler) (err, res, body) ->
       actiontypes = JSON.parse body
       robot.brain.set 'actiontypes', _.zipObject _.map(actiontypes, 'name'), actiontypes
 

_ = require 'lodash'

CONN_ERRORS =
  'ECONNREFUSED': (err) -> "Connection has been refused. Check if other components are running as well."
  'default': (err) -> "Something gone terribly wrong. #{err}"

errorHandler = (robot) ->
  (err, res) ->
    if err
      robot.logger.error (CONN_ERRORS[err.code] || CONN_ERRORS['default']) err

parseArgs = (scheme=[], argstr="") ->
  # split string by space while preserving quoted literals
  args = argstr.match(/('.*?'|".*?"|\S+)/g) or []

  # trim quotes
  (args[i] = arg[1...-1]) for arg, i in args when arg[0] in ['\'', '\"']

  # build an object
  _.zipObject scheme, args


    httpclients.actionexecutions
      .header('Content-Type', 'application/json')
      .post(JSON.stringify(payload), errorHandler) (err, res, body) ->
        staction_execution = JSON.parse(body)

        unless res.statusCode is 201
          msg.send "Action has failed to run"

        unless staction_execution.status is 'complete'
          msg.send "Action has failed to execute"
