Last active
August 29, 2015 14:16
-
-
Save lylepratt/76e491486df331a09a5f to your computer and use it in GitHub Desktop.
BetterVoice Calls to FollowUpBoss Events | Hook.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
module['exports'] = function echoHttp (hook) { | |
var res = {}; | |
res.params = hook.params; | |
var bv_data = hook.params; | |
//Build the Follow Up Boss Data Payload from the BV Payload. | |
var fub_data = { | |
"source": "BetterVoice.com", | |
"system": "BetterVoice", | |
"type": "Phone Call", | |
"message": ((bv_data.audio_voicemail && bv_data.audio_transcription) ? bv_data.audio_transcription+" -- "+bv_data.audio_voicemail : null), | |
"person": { | |
"tags": ((bv_data.tag_list) ? bv_data.tag_list.split(",") : null), | |
"firstName": bv_data.contact_first_name, | |
"lastName": bv_data.contact_last_name, | |
"emails": [{"value":bv_data.contact_email}], | |
"phones": [{"value":bv_data.from_number}] | |
} | |
} | |
//Post the Data to Follow Up Boss Events API. Your API key should be passed in one of the POSTed parameters. | |
//var url = "http://requestb.in/tsdudets"; | |
var url = "https://api.followupboss.com/v1/events"; | |
var key = hook.params.key; | |
request.post(url, { | |
'auth': { | |
'user': hook.params.key, | |
'pass': 'password', | |
}, | |
"form": fub_data | |
}, function (error, response, body) { | |
res.error = error; | |
res.response = response; | |
res.body = body; | |
hook.debug(res); | |
hook.res.end(JSON.stringify(res, true, 2)); | |
}); | |
}; | |
//We define our schema here. This is the data we will be using in the request. | |
module['exports'].schema = { | |
"key": { | |
"type": "any", | |
"required": true | |
} | |
}; | |
//Currently not working because mschema does not support null values on strings or any field types. | |
/* | |
"to_number": { | |
"type": "any" | |
}, | |
"from_number": { | |
"type": "any" | |
}, | |
"contact_email": { | |
"type": "any" | |
}, | |
"contact_first_name": { | |
"type": "any" | |
}, | |
"contact_last_name": { | |
"type": "any" | |
}, | |
"direction": { | |
"type": "string" | |
}, | |
"tag_list": { | |
"type": "any" | |
}, | |
"audio_transcription": { | |
"type": "any" | |
}, | |
"audio_voicemail": { | |
"type": "any" | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment