Skip to content

Instantly share code, notes, and snippets.

@fizzy33
Created June 29, 2013 23:58
Show Gist options
  • Save fizzy33/5893196 to your computer and use it in GitHub Desktop.
Save fizzy33/5893196 to your computer and use it in GitHub Desktop.
// =++=++=++= isolate.groovy =++=++=++=
void sendSignal(String sessionId, String signalName) {
def url = new URL("https://api.tropo.com/1.0/sessions/${sessionId}/signals?action=signal&value=${signalName}")
log("--log-- http get -- " + url)
def connection = url.openConnection()
def response = slurpStream(connection.getInputStream())
def statusCode = connection.getResponseCode()
log("--log-- http get response -- " + statusCode + " -- " + response)
response
}
String slurpStream(InputStream input) {
def bufferSize = 4906
def buffer = new char[bufferSize]
def out = new StringBuilder()
def reader = new InputStreamReader(input, "UTF-8")
try {
while(true) {
def readCount = reader.read(buffer, 0, buffer.length);
if (readCount < 0) break
out.append(buffer, 0, readCount)
}
out.toString()
} finally {
reader.close()
}
}
log("mySessionId=" + currentCall.sessionId)
Thread.start("childthread") {
log("--log-- child thread started")
await(5000) // wait 5 seconds
log("--log-- sending signal")
sendSignal(currentCall.sessionId, "happy")
log("--log-- signal sent")
}
say("https://vmail.medxcom.com/assets/prompts/system/followme_hold.mp3", [
onSignal: { event ->
say("stopped on hold with " + event.value)
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment