 			'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36'
 
 	if trigger.prepareOutgoingRequestScript? and trigger.prepareOutgoingRequestScript.trim() isnt ''
+		trigger.store ?= {}
 		sandbox =
 			request: opts
-
-		script = undefined
-		vmScript = undefined
-		try
-			script = "result = (function() {\n"+trigger.prepareOutgoingRequestScript+"\n}());"
-			vmScript = vm.createScript script, 'script.js'
-			logger.outgoing.info 'will execute script prepareOutgoingRequestScript'
-			logger.outgoing.debug script
-			logger.outgoing.debug 'with context', sandbox
-		catch e
-			logger.outgoing.error "[Error evaluating Script:]"
-			logger.outgoing.error script.replace(/^/gm, '  ')
-			logger.outgoing.error "\n[Stack:]"
-			logger.outgoing.error e.stack.replace(/^/gm, '  ')
-			return
-
-		try
-			sandbox._ = _
-			sandbox.s = s
-			sandbox.console = console
-			vmScript.runInNewContext sandbox
-			opts = sandbox.result
-			logger.outgoing.debug 'result', opts
-			if opts?.message?
-				return sendMessage opts.message
-		catch e
-			logger.outgoing.error "[Error running Script:]"
-			logger.outgoing.error script.replace(/^/gm, '  ')
-			logger.outgoing.error "\n[Stack:]"
-			logger.outgoing.error e.stack.replace(/^/gm, '  ')
-			return
+			store: trigger.store
+
+		opts = executeScript trigger.prepareOutgoingRequestScript, 'prepareOutgoingRequestScript', sandbox
 
 	if not opts?
 		return
 
+	if opts.message?
+		return sendMessage opts.message
 
 	HTTP.call opts.method, opts.url, opts, (error, result) ->
 		if not result? or result.statusCode isnt 200

vm = Npm.require('vm')

triggers = {}

RocketChat.models.Integrations.find({type: 'webhook-outgoing'}).observe
	added: (record) ->

						content: result.data
						content_raw: result.content
						headers: result.headers
					store: trigger.store

				scriptResult = executeScript trigger.processOutgoingResponseScript, 'processOutgoingResponseScript', sandbox
				result =
					data: scriptResult?.content

			if result?.data?.text? or result?.data?.attachments?
				sendMessage result.data
