"use strict";

var _regeneratorRuntime = require('babel-runtime/regenerator')['default'];

var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];

Object.defineProperty(exports, '__esModule', {
	value: true
});
exports.voiceCallHandler = voiceCallHandler;
exports.smsCallHandler = smsCallHandler;

var _requestPromise = require('request-promise');

var _requestPromise2 = _interopRequireDefault(_requestPromise);

var voice_server_url = 'http://localhost:8000';
var sms_server_url = 'http://localhost:8001';

function voiceCallHandler(req, reply, next) {
	var body;
	return _regeneratorRuntime.async(function voiceCallHandler$(context$1$0) {
		while (1) switch (context$1$0.prev = context$1$0.next) {
			case 0:
				context$1$0.prev = 0;
				body = undefined;

				if (!(req != undefined)) {
					context$1$0.next = 8;
					break;
				}

				context$1$0.next = 5;
				return _regeneratorRuntime.awrap((0, _requestPromise2['default'])({
					url: '' + voice_server_url + req.url,
					method: 'POST',
					json: true,
					body: req.params
				}));

			case 5:
				body = context$1$0.sent;
				context$1$0.next = 9;
				break;

			case 8:
				throw new Error('Missing request parameters');

			case 9:
				if (body === undefined) reply.send(200);else reply.send(200, body, { 'content-type': 'application/xml' });
				reply.end();
				return context$1$0.abrupt('return', next());

			case 14:
				context$1$0.prev = 14;
				context$1$0.t0 = context$1$0['catch'](0);

				console.log('voiceCallHandler Error ', context$1$0.t0);
				reply.send(402, 'An error occured', { 'content-type': 'application/xml' });
				reply.end();
				return context$1$0.abrupt('return');

			case 20:
			case 'end':
				return context$1$0.stop();
		}
	}, null, this, [[0, 14]]);
}

function smsCallHandler(req, reply, next) {
	var body;
	return _regeneratorRuntime.async(function smsCallHandler$(context$1$0) {
		while (1) switch (context$1$0.prev = context$1$0.next) {
			case 0:
				context$1$0.prev = 0;
				body = undefined;

				if (!(req != undefined)) {
					context$1$0.next = 8;
					break;
				}

				context$1$0.next = 5;
				return _regeneratorRuntime.awrap((0, _requestPromise2['default'])({
					url: '' + sms_server_url + req.url,
					method: 'POST',
					json: true,
					body: req.params
				}));

			case 5:
				body = context$1$0.sent;
				context$1$0.next = 9;
				break;

			case 8:
				throw new Error('Missing request parameters');

			case 9:
				if (body === undefined) reply.send(200);else reply.send(200, body, { 'content-type': 'application/xml' });
				reply.end();
				return context$1$0.abrupt('return', next());

			case 14:
				context$1$0.prev = 14;
				context$1$0.t0 = context$1$0['catch'](0);

				console.log('smsCallHandler Error ', context$1$0.t0);
				reply.send(402, 'An error occured', { 'content-type': 'application/xml' });
				reply.end();
				return context$1$0.abrupt('return');

			case 20:
			case 'end':
				return context$1$0.stop();
		}
	}, null, this, [[0, 14]]);
}
@@ -1,8 +1,47 @@
+/* connectedvoice FE route handler */%0A%0A
 %22use str
@@ -1275,32 +1275,34 @@
 %09case 9:%0A%09%09%09%09if 
+(!
 (body === undefi
@@ -1305,38 +1305,199 @@
 defined)
- reply.send(200);else 
+) %7B%0A%09%09%09%09%09context$1$0.next = 13;%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%0A%09%09%09%09reply.send(200);%0A%09%09%09%09context$1$0.next = 17;%0A%09%09%09%09break;%0A%0A%09%09%09case 13:%0A%09%09%09%09body = new Buffer(body, 'base64').toString('utf8');%0A%09%09%09%09
 reply.se
@@ -1618,33 +1618,84 @@
 t());%0A%0A%09%09%09case 1
-4
+7:%0A%09%09%09%09context$1$0.next = 25;%0A%09%09%09%09break;%0A%0A%09%09%09case 19
 :%0A%09%09%09%09context$1$
@@ -1696,33 +1696,33 @@
 ext$1$0.prev = 1
-4
+9
 ;%0A%09%09%09%09context$1$
@@ -1803,32 +1803,40 @@
 , context$1$0.t0
+.message
 );%0A%09%09%09%09reply.sen
@@ -1962,33 +1962,33 @@
 rn');%0A%0A%09%09%09case 2
-0
+5
 :%0A%09%09%09case 'end':
@@ -2041,25 +2041,25 @@
 this, %5B%5B0, 1
-4
+9
 %5D%5D);%0A%7D%0A%0Afunc

build of route handler