Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

...

...

...

...

...

...


Panel
id0

This section describes how an sms provider plugin can be created.

What does this section cover?

Table of Contents

Create a custom sms provider

In order to create a custom sms provider, you need to:

  1. Define the custom sms provider in sms providers metadata file.
  2. Create a custom object class to store sms setting parameters. (optional)Create a custom process class extending com.crm.process.smsproviders.CRMProcessSMSProvidersBean
  3. 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
titleSMS providers metadata file


Code Block
languagexml
titlesmsproviders.xml
collapsetrue
<smsprovidersconfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/applications.xsd">
	<smsproviders>
		<smsprovider>
			<smsproviderprotocol>TWILIO<<smsproviderprotocol>CUSTOM</smsproviderprotocol>
			<smsprovidername>TWILIO<<smsprovidername>CUSTOM</smsprovidername>
			<smsproviderprocessejbname>ejb/TWILIOCRMProcessTwilioSMSProvider<CUSTOMCRMProcessCustomSMSProvider</smsproviderprocessejbname>
			<generalparameters>
				<generalparameter>
					<generalparameterid>username</generalparameterid>
					<generalparametername>key_username</generalparametername>
					<generalparametertype>java.lang.String</generalparametertype>
				</generalparameter>
				<generalparameter>
					<generalparameterid>password</generalparameterid>
					<generalparametername>key_password</generalparametername>
					<generalparametertype>password</generalparametertype>
				</generalparameter>
				<generalparameter>
					<generalparameterid>commFrom</generalparameterid>
					<generalparametername>key_from</generalparametername>
					<generalparametertype>java.lang.String</generalparametertype>
				</generalparameter>
			</generalparameters>
		</smsprovider>
	</smsproviders>
</smsprovidersconfig>





2

...

This class will be used to define the sms setting parameters. 

...

languagejava
titleTWILIOCRMDOSmsSettings .java
linenumberstrue
collapsetrue

...

.

...

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.

Below you can find both an example of TWILIO process CUSTOM process class.


Code Block
languagejava
titleTWILIOCRMProcessTwilioSMSProviderBeanCUSTOMCRMProcessCustomSMSProviderBean
linenumberstrue
collapsetrue
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/TWILIOCRMProcessTwilioSMSProviderCUSTOMCRMProcessCustomSMSProvider")
@LocalBean
public class TWILIOCRMProcessTwilioSMSProviderBeanCUSTOMCRMProcessCustomSMSProviderBean 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 = "TWILIOCUSTOM";

	@Override
	public SMSProviderResult sendSMS(String toPhone, String fromPhone, String message,String contactID, SendSMSParameters parameters)throws Exception {

		
		
		TWILIOCRMDOSmsSettingsCUSTOMSmsSettings smsSettings = new TWILIOCRMDOSmsSettingsCUSTOMSmsSettings(); //Optional Custom Object to hold your Sms Provider Settings
		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();//Implementation of the logic needed to communicate with SMS Provider and send the SMS
			
			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) about the Request");
			CallList.LogTextFile(getCRMSession(),request1,
					"Providers/SMS Gateways/Errors/TWILIOCUSTOM_SMS_GATEWAY", "");
			CallList.LogTextFile(getCRMSession(), "Error:" + ((ApiException)e).getMoreInfo(),
					"Providers/SMS Gateways/Errors/TWILIOCUSTOM_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)) about the Request");
			CallList.LogTextFile(getCRMSession(),request1,
					"Providers/SMS Gateways/Errors/TWILIOCUSTOM_SMS_GATEWAY", "");
			CallList.LogTextFile(getCRMSession(), "Error:" + ExceptionUtil.getStackTrace(e),
					"Providers/SMS Gateways/Errors/TWILIOCUSTOM_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;
	}

}

...

3.

...

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

4.Select SMS Settings tab

5.On edit mode, next to SMS Protocol dropdown click on New 

6.A modal with the available for creation providers will appear. Select your custom provider( ex.

...

CUSTOM)

7.The general parameters of SMS Provider will appear on screen as a form. Fill the form and Save. 

...