...
...
...
...
...
...
...
...
...
...
Create a custom sms provider
In order to create a custom sms provider, you need to:
- Define the custom sms provider in sms providers metadata file.Create a custom object class to store sms setting parameters. (optional)
- Create a custom process class extending com.crm.process.smsproviders.CRMProcessSMSProvidersBean
- Create Set up the SMS Provider via in CRM.COM
Note that all data object, business object, user interface and process class names should start with the custom project directory name:
For this example we assume that <custom_project> = TWILIOCUSTOM
1. SMS Providers Metadata File
The new custom sms provider must be defined in smsproviders.xml file which is located under <custom_project>/src/main/resources/metadata/ directory.
Ui expand | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
|
2. SMS Providers Parameters Class( Optional )
This class will be used to define the sms setting parameters.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
package com.crm.dataobject.communications; import com.crm.dataobject.NotPersistenceObject; public class TWILIOCRMDOSmsSettings extends NotPersistenceObject { /** * */ private static final long serialVersionUID = 1L; public TWILIOCRMDOSmsSettings() { // TODO Auto-generated constructor stub } String username; String password; String commFrom; public String getUsername() { return username; } public void setUsername(String username) { setChange("username", this.username, username); this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { setChange("password", this.password, password); this.password = password; } public static long getSerialversionuid() { return serialVersionUID; } public String getCommFrom() { return commFrom; } public void setCommFrom(String commFrom) { setChange("commFrom", this.commFrom, commFrom); this.commFrom = commFrom; } } |
3. SMS Provider Process Class
The sms provider process class should extend com.crm.process.smsproviders.CRMProcessSMSProvidersBean and implement its abstract methods for sending an SMS via this custom provider, loading the sms provider and sms provider protocol.
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
package com.crm.process.smsproviders; import java.util.HashMap; import javax.ejb.EJB; import javax.ejb.LocalBean; import javax.ejb.Stateless; import com.crm.businessobject.smsproviders.CRMBOSMSProviderBean; import com.crm.dataobject.communications.TWILIOCRMDOSmsSettings; import com.crm.dataobject.smsproviders.CRMDOSMSProvider; import com.crm.dataobject.smsproviders.SendSMSParameters; import com.crm.framework.util.CallList; import com.crm.framework.util.ExceptionUtil; import com.twilio.Twilio; import com.twilio.exception.ApiException; import com.twilio.rest.api.v2010.account.Message; import com.twilio.type.PhoneNumber; @Stateless(mappedName = "ejb/TWILIOCRMProcessTwilioSMSProvider") @LocalBean public class TWILIOCRMProcessTwilioSMSProviderBean extends CRMProcessSMSProvidersBean{ /** * */ private static final long serialVersionUID = 1L; @EJB private CRMBOSMSProviderBean smsProviderBean; private final String ALIAS_PASSWORD = "password"; private final String ALIAS_USERNAME = "username"; private final String ALIAS_FROM = "commFrom"; public static String PROVIDER_PROTOCOL = "TWILIO"; @Override public SMSProviderResult sendSMS(String toPhone, String fromPhone, String message,String contactID, SendSMSParameters parameters)throws Exception { TWILIOCRMDOSmsSettings smsSettings = new TWILIOCRMDOSmsSettings(); SMSProviderResult result = new SMSProviderResult(); try { HashMap<String, Object> generalParameters = parameters.getGeneralParameters(); smsSettings.setUsername((String) generalParameters.get(ALIAS_USERNAME)); smsSettings.setPassword((String) generalParameters.get(ALIAS_PASSWORD)); smsSettings.setCommFrom((String) generalParameters.get(ALIAS_FROM)); if(fromPhone==null){ if(smsSettings.getCommFrom()!=null){ fromPhone=smsSettings.getCommFrom(); }else{ fromPhone="CRM.COM"; } } if(smsSettings.getCommFrom()==null){ smsSettings.setCommFrom(fromPhone); } Twilio.init(smsSettings.getUsername(), smsSettings.getPassword()); Message messageToSend = Message .creator(new PhoneNumber(toPhone), new PhoneNumber(smsSettings.getCommFrom()), message) .create(); result.setStatus(SMSProviderResultStatus.COMPLETED); }catch(ApiException e){ String request1 = new String("Request: Communication for Contact Information: "+contactID+". Sending from ****"+ getLastFourDigits(fromPhone) + " to phone number ****" + getLastFourDigits(toPhone)); CallList.LogTextFile(getCRMSession(),request1, "Providers/SMS Gateways/Errors/TWILIO_SMS_GATEWAY", ""); CallList.LogTextFile(getCRMSession(), "Error:" + ((ApiException)e).getMoreInfo(), "Providers/SMS Gateways/Errors/TWILIO_SMS_GATEWAY", ""); result.setStatus(SMSProviderResultStatus.REJECTED); if(e.getCode()!=null) result.setErrorCode(e.getCode()+""); result.setErrorDescription(e.getMoreInfo()); }catch(Exception e){ String request1 = new String("Request: Communication for Contact Information: "+contactID+". Sending from ****"+ getLastFourDigits(fromPhone) + " to phone number ****" + getLastFourDigits(toPhone)); CallList.LogTextFile(getCRMSession(),request1, "Providers/SMS Gateways/Errors/TWILIO_SMS_GATEWAY", ""); CallList.LogTextFile(getCRMSession(), "Error:" + ExceptionUtil.getStackTrace(e), "Providers/SMS Gateways/Errors/TWILIO_SMS_GATEWAY", ""); result.setStatus(SMSProviderResultStatus.REJECTED); result.setErrorCode("500"); result.setErrorDescription(e.getMessage()); } return result; } @Override public String getProtocol() throws Exception { return PROVIDER_PROTOCOL; } @Override public CRMDOSMSProvider setObjectsFromXML(CRMDOSMSProvider smsProvider) throws Exception { // TODO Auto-generated method stub return smsProvider; } /** * Loads an effective sms provider * * @return an effective sms provider * @throws Exception */ public CRMDOSMSProvider loadProvider() throws Exception { CRMDOSMSProvider smsProvider = loadEffectiveProvider(getProtocol()); return smsProvider; } /** * Loads an effective sms provider based on provider protocol * * @param protocol, sms provider protocol * @return * @throws Exception */ public CRMDOSMSProvider loadEffectiveProvider(String protocol) throws Exception { return loadEffectiveProvider(protocol, true); } /** * Loads a effective provider based on provider protocol * * @param protocol sms provider protocol * @param applicationServerFiltering - filter the provider based on application servers filtering configuration * @return * @throws Exception */ public CRMDOSMSProvider loadEffectiveProvider(String protocol , Boolean applicationServerFiltering) throws Exception { CRMDOSMSProvider smsProvider = smsProviderBean.loadEffective(protocol,applicationServerFiltering); if(smsProvider!=null) { smsProvider = setObjectsFromXML(smsProvider); } return smsProvider; } /** * Loads a provider based on provider protocol * * @throws Exception */ public CRMDOSMSProvider loadProvider(String protocol) throws Exception { CRMDOSMSProvider smsProvider = smsProviderBean.loadByProtocol(protocol); smsProvider = smsProviderBean.setObjectsFromXML(smsProvider); return smsProvider; } public String getLastFourDigits(String input){ String lastFourDigits = ""; //substring containing last 4 characters if (input.length() > 4) { lastFourDigits = input.substring(input.length() - 4); } else { lastFourDigits = input; } return lastFourDigits; } } |
4.
...
Set up the SMS Provider
...
in CRM.COM
To create the SMS Provider in CRM.COM you have to follow the below steps:
1.Log in to CRM.COM
2.Go to / Settings & Admin / CRM Application / CRM Settings
3.On "Set up Communications" list click on (1)General Settings
...
7.The general parameters of SMS Provider will appear on screen as a form. Fill the form and Save. Gallery