Created
August 24, 2012 21:59
-
-
Save metadaddy/3456169 to your computer and use it in GitHub Desktop.
Transcribing Voice Messages to Tasks with the Tropo API
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
@RestResource(urlMapping='/messageToTask') | |
global class MessageToTask { | |
global class Result { | |
public String guid; | |
public String identifier; | |
public String transcription; | |
} | |
@HttpPost | |
global static void incomingMessage(Result result) { | |
// Format the incoming phone number as (999) 999-9999 | |
// TODO - handle international formatting | |
String phone = '(' + result.identifier.substring(0,3) + ') ' + | |
result.identifier.substring(3,6) + '-' + | |
result.identifier.substring(6,10); | |
// Try to find a matching Contact | |
Contact contact = null; | |
try { | |
contact = [SELECT Id FROM Contact WHERE (Phone = :phone OR MobilePhone = :phone) LIMIT 1]; | |
} catch (QueryException qe) { | |
System.debug('No match for phone number '+result.identifier); | |
return; | |
} | |
// Create and insert a new Task | |
Task task = new Task(ActivityDate = Date.today(), | |
CallDisposition = 'Contact left a message', | |
CallType = 'Inbound', | |
Description = result.transcription, | |
Status = 'Completed', | |
Subject = 'Phone Message from '+phone, | |
Type = 'Call', | |
WhoId = contact.Id); | |
insert task; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
International formatting can be offloaded to the methods for 228 countries already coded as the libphonenumber project.