1.0.4 • Published 4 years ago

cordova-plugin-salesforce-snapins v1.0.4

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

cordova-plugin-salesforce-snapins

Cordova plugin to integrate Salesforce Snap-ins SDK for iOS and Android on a Cordova project.

For more information about Salesforce SDK look at:

Installation

cordova plugin add cordova-plugin-salesforce-snapins

Supported platforms

  • Android
  • iOS

Usage

var SalesforceSnapIns = window.cordova.plugins.SalesforceSnapIns;

SalesforceSnapIns.initialize({
	colors: { // iOS only
		brandPrimary: "#007F7F"
	},
	liveAgent: {
		liveAgentPod: '...',
		orgId: '...',
		deploymentId: '...',
		buttonId: '...'
	}
});

// Optional, if you don't need to change pre-chat fields you can omit this line
SalesforceSnapIns.clearPrechatFields();

SalesforceSnapIns.addPrechatField({
	type: 'hidden', // could be: text, hidden, picker
	label: 'Subject',
	value: 'Live Agent Chat support',
	transcriptField: 'subject__c',
	required: true
});

SalesforceSnapIns.addPrechatField({
	type: 'text',
	label: 'Name',
	required: true
});

SalesforceSnapIns.addPrechatField({
	type: 'text',
	label: 'Email',
	required: true,
	keyboardType: SalesforceSnapIns.KEYBOARD_TYPE_EMAIL_ADDRESS,
	autocorrectionType: SalesforceSnapIns.AUTOCORRECTION_TYPE_NO
});

SalesforceSnapIns.addPrechatField({
	type: 'picker',
	label: 'Argomento',
	required: true,
	values: [
		{ label: 'Reso',   value: 'reso' },
		{ label: 'Ordine', value: 'ordine' }
	]
});

// Optional, if you don't need to change pre-chat entities you can omit this line
SalesforceSnapIns.clearPrechatEntities();

var accountEntity = {
	name: "Account",
	linkToEntityName: "Account",
	linkToEntityField: "AccountId",
	saveToTranscript: "AccountId",
	showOnCreate: true,
	fieldMap: [
		{
			fieldName: "Name__c",
			label: "Name",
			isExactMatch: true,
			doCreate: true,
			doFind: false
		},
		{
			fieldName: "Email__c",
			label: "Email",
			isExactMatch: true,
			doCreate: true,
			doFind: true
		}
	]
};
SalesforceSnapIns.addPrechatEntity(accountEntity);

var caseEntity = {
	name: "Case",
	linkToEntityName: "Account",
	linkToEntityField: "AccountId",
	saveToTranscript: "AccountId",
	showOnCreate: true,
	fieldMap: [
		{
			fieldName: "Subject",
			label: "Subject",
			doCreate: true
		}
	]
};
SalesforceSnapIns.addPrechatEntity(caseEntity);

SalesforceSnapIns.determineAvailability(function (available) {
	if (available) {
		SalesforceSnapIns.openLiveAgentChat(function() {
			console.log('Chat opened');
		}, function () {
			console.error('Unable to open chat');
		});
	}
}, function (err) {
	console.error(err);
});

initialize(options, success, error)

cordova.plugins.SalesforceSnapIns.initialize({
	liveAgent: {
		liveAgentPod: '...',
		orgId: '...',
		deploymentId: '...',
		buttonId: '...'
	}
});
ParameterRequiredDescription
optionsYesConfiguration object
options.liveAgentChatNo
options.liveAgentChat.liveAgentPodYes
options.liveAgentChat.orgIdYes
options.liveAgentChat.deploymentIdYes
options.liveAgentChat.buttonIdYes
options.colorsNoSee customization section for more details
successNoNo prameters
errorNoerr: error object

determineAvailability(success, error)

cordova.plugins.SalesforceSnapIns.determineAvailability(function (available) {
	if (available) {
		// Open chat with cordova.plugins.SalesforceSnapIns.openLiveAgentChat
	} else {
		// No agents available
	}
}, function (err) {
	// An error occurred
});
ParameterRequiredDescription
successNoavailable: if true there is at least one agent available for the chat
errorNoerr: error object

openLiveAgentChat(success, error)

It's suggested to call determineAvailability() before openLiveAgentChat().

cordova.plugins.SalesforceSnapIns.openLiveAgentChat(function () {
	// Chat opened
}, function (err) {
	// An error occurred
});
ParameterRequiredDescription
successNoNo prameters
errorNoerr: error object

addPrechatField(field, success, error)

cordova.plugins.SalesforceSnapIns.addPrechatField({
	type: 'hidden', // could be: text, hidden, picker
	label: 'Subject',
	value: 'Live Agent Chat support',
	transcriptField: 'subject__c',
	required: true
});

cordova.plugins.SalesforceSnapIns.addPrechatField({
	type: 'text',
	label: 'Name',
	required: true
});

cordova.plugins.SalesforceSnapIns.addPrechatField({
	type: 'text',
	label: 'Email',
	required: true,
	keyboardType: cordova.plugins.SalesforceSnapIns.KEYBOARD_TYPE_EMAIL_ADDRESS,
	autocorrectionType: cordova.plugins.SalesforceSnapIns.AUTOCORRECTION_TYPE_NO
});

cordova.plugins.SalesforceSnapIns.addPrechatField({
	type: 'picker',
	label: 'Argomento',
	required: true,
	values: [
		{ label: 'Reso',   value: 'reso' },
		{ label: 'Ordine', value: 'ordine' }
	]
});
ParameterRequiredDescription
fieldYesField details
field.typeYesCan be: text, hidden, picker
field.labelYesDisplayed field name to the user
field.valueYes (only for hidden)Displayed field name to the user
field.transcriptFieldNoTranscript field
field.requiredNoDefault false
field.keyboardTypeNo (only for text)Default KEYBOARD_TYPE_DEFAULT. Possible values:KEYBOARD_TYPE_DEFAULTKEYBOARD_TYPE_ASCII_CAPABLEKEYBOARD_TYPE_NUMBERS_AND_PUNCTATIONKEYBOARD_TYPE_URLKEYBOARD_TYPE_NUMBER_PADKEYBOARD_TYPE_PHONE_PADKEYBOARD_TYPE_NAME_PHONE_PADKEYBOARD_TYPE_EMAIL_ADDRESSKEYBOARD_TYPE_DECIMAL_PADKEYBOARD_TYPE_TWITTERKEYBOARD_TYPE_WEB_SEARCHKEYBOARD_TYPE_ASCII_CAPABLE_NUMBER_PAD
field.autocorrectionTypeNo (only for text)Default AUTOCORRECTION_TYPE_DEFAULT. Used on iOS only.Possible values:AUTOCORRECTION_TYPE_DEFAULTAUTOCORRECTION_TYPE_NOAUTOCORRECTION_TYPE_YES
field.values[]Yes (only for picker)Array of options
field.values[].labelYes (only for picker)Label showed to the user
field.values[].valueYes (only for picker)Value of the option
successNoNo prameters
errorNoerr: error object

clearPrechatFields(success, error)

// Optional, if you don't need to change pre-chat fields you can omit this line
cordova.plugins.SalesforceSnapIns.clearPrechatFields();
ParameterRequiredDescription
successNoNo prameters
errorNoerr: error object

addPrechatEntity(entities, success, error)

var accountEntity = {
	name: "Account",
	linkToEntityName: "Account",
	linkToEntityField: "AccountId",
	saveToTranscript: "AccountId",
	showOnCreate: true,
	fieldMap: [
		{
			fieldName: "Name__c",
			label: "Name",
			isExactMatch: true,
			doCreate: true,
			doFind: false
		},
		{
			fieldName: "Email__c",
			label: "Email",
			isExactMatch: true,
			doCreate: true,
			doFind: true
		}
	]
};
SalesforceSnapIns.addPrechatEntity(accountEntity);
ParameterRequiredDescription
entitiesYesSalesforce entity options
entities.nameYesEntity name
entities.linkToEntityNameNoName of another entity linked to this
entities.linkToEntityFieldNoField of another entity linked to this
entities.showOnCreateNoDefault false. If true the entity will be shown to the agent when a new chat start
entities.fieldMap[]YesDescribe how Salesforce should map pre-chat fields
entities.fieldMap[].fieldNameYesField name
entities.fieldMap[].labelYesLabel of the filed. Should match the pre-chat field label or data could not be sended correctly
entities.fieldMap[].isExactMatchNoDefault false
entities.fieldMap[].doCreateNoDefault false
entities.fieldMap[].doFindNoDefault false
successNoNo prameters
errorNoerr: error object

clearPrechatEntities(success, error)

// Optional, if you don't need to change pre-chat entities you can omit this line
cordova.plugins.SalesforceSnapIns.clearPrechatEntities();
ParameterRequiredDescription
successNoNo prameters
errorNoerr: error object

Color customization

See official customization page for iOS and Android to learn more about color customization.

Constants available are:

iOS constantAndroid constantDescription
navbarBackgroundsalesforce_toolbarBackground color for the navigation bar.
navbarInvertedsalesforce_toolbar_invertedNavigation bar text and icon color.
brandPrimarysalesforce_brand_primaryFirst data category, the Show More button, the footer stripe, the selected article.
brandSecondarysalesforce_brand_secondaryUsed throughout the UI for button colors.
brandPrimaryInvertedsalesforce_title_colorText on data category headers and the chevron on the Knowledge home page.
brandSecondaryInvertedsalesforce_brand_contrastText on areas where a brand color is used for the background.
contrastPrimarysalesforce_contrast_primaryPrimary body text color.
contrastSecondarysalesforce_contrast_secondarySubcategory headers.
contrastTertiarysalesforce_contrast_tertiarySearch background color.
contrastQuaternarysalesforce_contrast_quaternaryIcon image background color.
contrastInvertedsalesforce_contrast_invertedPage background, navigation bar, table cell background.
feedbackPrimarysalesforce_feedback_primaryText color for error messages.
feedbackSecondarysalesforce_feedback_secondaryConnection quality indicators. Background color for the Resume button when the two-way camera is active.
feedbackTertiarysalesforce_feedback_tertiaryConnection quality indicators.
overlaysalesforce_overlayBackground for the Knowledge home screen.

iOS

window.plugins.SalesforceSnapIns.initialize({
	// ...
	colors: {
		navbarBackground: "#FAFAFA",
		navbarInverted: "#010101",
		brandPrimary: "#007F7F",
		brandSecondary: "#2872CC",
		brandPrimaryInverted: "#FBFBFB",
		brandSecondaryInverted: "#FCFCFC",
		contrastPrimary: "#000000",
		contrastSecondary: "#767676",
		contrastTertiary: "#BABABA",
		contrastQuaternary: "#F1F1F1",
		contrastInverted: "#FFFFFF",
		feedbackPrimary: "#E74C3C",
		feedbackSecondary: "#2ECC71",
		feedbackTertiary: "#F5A623",
		overlay: "#000000"
	},
	// ...
});

Android

<!-- config.xml -->
<platform name="android">
	<config-file parent="/resources" target="app/src/main/res/values/colors.xml">
		<color name="salesforce_toolbar">#FAFAFA</color>
		<color name="salesforce_toolbar_inverted">#010101</color>
		<color name="salesforce_brand_primary">#007F7F</color>
		<color name="salesforce_brand_secondary">#2872CC</color>
		<color name="salesforce_brand_contrast">#FCFCFC</color>
		<color name="salesforce_contrast_primary">#000000</color>
		<color name="salesforce_contrast_secondary">#767676</color>
		<color name="salesforce_contrast_tertiary">#BABABA</color>
		<color name="salesforce_contrast_quaternary">#F1F1F1</color>
		<color name="salesforce_contrast_inverted">#FFFFFF</color>
		<color name="salesforce_feedback_primary">#E74C3C</color>
		<color name="salesforce_feedback_secondary">#2ECC71</color>
		<color name="salesforce_feedback_tertiary">#F5A623</color>
		<color name="salesforce_title_color">#FBFBFB</color>
		<color name="salesforce_overlay">#000000</color>
	</config-file>
</platform>

Attention! after cordova prepare android the color configuration will be cached into android/android.json file. If you want to remove, add or change any color after the first prepare be sure to clean android.json. Alternatively you can type your color directly into app/src/main/res/values/colors.xml with the drawback that you will lose them renewing the platform.

Prepare for submission (iOS)

As documented on Salesforce documentation on XCode project:

  • select Build Phases
  • create Run script
  • paste this line of code $PODS_ROOT/ServiceSDK/Frameworks/ServiceCore.framework/prepare-framework

TODO

  • Add Case management support
  • Add SOS support
  • Enhance color customization for Android

LICENSE

MIT