Skip to content

Instantly share code, notes, and snippets.

@metadaddy
Created August 24, 2012 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save metadaddy/3456169 to your computer and use it in GitHub Desktop.
Save metadaddy/3456169 to your computer and use it in GitHub Desktop.
Transcribing Voice Messages to Tasks with the Tropo API
@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;
}
}
@g1smd
Copy link

g1smd commented Sep 2, 2012

International formatting can be offloaded to the methods for 228 countries already coded as the libphonenumber project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment