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

...

  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

...

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.

...

Code Block
languagejava
titleCUSTOMCRMProcessCustomSMSProviderBean
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.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
and get the response
			
			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/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("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.