Validate Customer's Twitter Handle Script

This script validates whether the agent's response begins with the @mention of the customer's Twitter handle.

You must add this script as a validation rule to the Message object (child of Service Request object). You must also add a validation message that's displayed to the agents when their Twitter response is greater than 280 characters.

Use the following code as an example:

//Validation logic
//For channel other than social ignore
if(ChannelTypeCd !='ORA_SVC_SOCIAL')
    return true
//For draft ignore
if(StatusCd == 'ORA_SVC_DRAFT')
    return true
//For message other than response ignore
if(MessageTypeCd != 'ORA_SVC_RESPONSE')
    return true
//Get the last social customer entry
def vo = newView('SrMessageVO')
def vc = newViewCriteria(vo)
def vcr = vc.createRow()
def vci1 = vcr.ensureCriteriaItem('MessageTypeCd')
vci1.setOperator('=')
vci1.setValue('ORA_SVC_CUSTOMER_ENTRY')
def vci2 = vcr.ensureCriteriaItem('ChannelTypeCd')
vci2.setOperator('=')
vci2.setValue('ORA_SVC_SOCIAL')
def vci3 = vcr.ensureCriteriaItem('SrId')
vci3.setOperator('=')
vci3.setValue(ServiceRequest?.SrId)
vc.insertRow(vcr)
vo.appendViewCriteria(vc)
vo.executeQuery()
def lastCustEntry=vo.first()
//Get the channel via
def channelViaList=lastCustEntry.channelCommunication
def channelVia = channelViaList.first()
// Using inbound object id as post id, find the social post
def postId = channelVia.InboundObjectId;
def key = key(postId);
def socialPostVO = newView('SocialPostVO')
def socialPosts = socialPostVO.findByKey(key, 1)
// do nothing if the social post is not found
if (socialPosts == null || socialPosts.size() == 0) { 
    return true
}
// use the first social post
def socialPost = socialPosts[0];
def networkType = socialPost.PostChannelCd
//do nothing if other than twitter 
if(networkType != 'TWITTER')    { 
    return true
}
//If message content is not having twitter handle as prefix then error out.
def twitterHandle = '@' + socialPost.PostUser + ' '
if(MessageContent!= null && !startsWith(MessageContent.toString(),twitterHandle))   {
  return false
}
return true;