Create an SMS Provider Plug-in

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

What does this section cover?

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 process class extending com.crm.process.smsproviders.CRMProcessSMSProvidersBean
  3. Set up the SMS Provider 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> = CUSTOM

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. 

2. 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 CUSTOM process class.

CUSTOMCRMProcessCustomSMSProviderBean
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.smsproviders.CRMDOSMSProvider;
import com.crm.dataobject.smsproviders.SendSMSParameters;
import com.crm.framework.util.CallList;
import com.crm.framework.util.ExceptionUtil;


@Stateless(mappedName = "ejb/CUSTOMCRMProcessCustomSMSProvider")
@LocalBean
public class CUSTOMCRMProcessCustomSMSProviderBean 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 = "CUSTOM";

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

		
		
		CUSTOMSmsSettings smsSettings = new CUSTOMSmsSettings(); //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);
			}
			
			//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("Information about the Request");
			CallList.LogTextFile(getCRMSession(),request1,
					"Providers/SMS Gateways/Errors/CUSTOM_SMS_GATEWAY", "");
			CallList.LogTextFile(getCRMSession(), "Error:" + ((ApiException)e).getMoreInfo(),
					"Providers/SMS Gateways/Errors/CUSTOM_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("Information about the Request");
			CallList.LogTextFile(getCRMSession(),request1,"Providers/SMS Gateways/Errors/CUSTOM_SMS_GATEWAY", "");
			CallList.LogTextFile(getCRMSession(), "Error:" + ExceptionUtil.getStackTrace(e),"Providers/SMS Gateways/Errors/CUSTOM_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 {
		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;
	}
	

}

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.