Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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