Customization

Overview

In this section, learn how to customize the Kommunicate SDK according to your requirements.

Getting started with customization

Kommunicate provides easy settings to customize different elements (such as fonts, message color, background colors) and enable or disable any particular feature.

Follow these steps:

  1. Download the settings file from here (Right click -> Save as -> Save)

  2. Place the downloaded applozic-settings.json file under your app/src/main/assets/ folder.

There are a lot of customization options in the file. Below are some common options available.

Changing the message background colors

You can change the sent/received message background and text color by setting the hex color codes in the below properties in applozic-settings.json file.

"sentMessageBackgroundColor": "#5c5aa7",
"receivedMessageBackgroundColor": "#e6e5ec",
"sentMessageCreatedAtTimeColor": "#ede6e6",
"receivedMessageCreatedAtTimeColor": "#8a8686",
"sentMessageTextColor": "#FFFFFFFF",
"receivedMessageTextColor": "#646262"

Hiding/Showing media attachment and location sharing options

You can hide or show the media attachments options like camera, emoji, files and location sharing by changing the below values in applozic-settings.json file.

You can make any of the options 'false' if you want to hide them.

"attachmentOptions": {
    ":location": false, 
    ":camera": true,
    ":file": true,
    ":audio":true
  }

If location sharing functionality is enabled

If you are enabling the location sharing option in the applozic-settings.json file, make sure to include the below permissions and geo-API key in your AndroidManifest.xml file.

Add the following permissions in your AndroidManifest.xml file:

   <uses-permission android:name=".permission.MAPS_RECEIVE" />
   <permission
        android:name="..permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

Add your geo-API_KEY in AndroidManifest.xml file:

   <meta-data
       android:name="com.google.android.geo.API_KEY"
       android:value="" />

Other properties

Below are some more properties which you can customize in the SDK:

"enableFaqOption": [         
    false,                   
    false                    
  ],
"enableAwayMessage": false,   
"logoutOption": true,        
"logoutPackageName": "", 
"showStartNewConversation" : false, 
"sentMessageCornerRadii": [  
10,                          
10,                          
10,                          
10                           
],
"receivedMessageCornerRadii": [  
10,
10,
10,
10
]

Changing fonts

Fonts for some TextViews can be changed by setting the fonts in the applozic-settings.json file. Add the below property in applozic-settings.json file to change the fonts for the respective TextViews:

"fontModel": {
    "messageTextFont": "",  
    "messageDisplayNameFont": "",
    "createdAtTimeFont": "",
    "toolbarTitleFont": "", 
    "toolbarSubtitleFont": "",
    "messageEditTextFont": ""
  }

If a particular field is left blank or is not included in the above object, then default font would be used for the same. To change the font, provide either an external font file or select from the list of default android fonts. The details on how to update external or default Android fonts are given below.

Use TTF font file

To use an external font, add the TTF font file under the directory app/src/main/assets/fonts/.ttf

Then specify the font for the specific TextView. For example, to use the above font for the toolbar title, set the path to the property toolbarTitleFont:

"fontModel": {
    "messageTextFont": "",
    "messageDisplayNameFont": "",
    "createdAtTimeFont": "",
    "toolbarTitleFont": "fonts/.ttf", 
    "toolbarSubtitleFont": "",
    "messageEditTextFont": ""
  }

Use Android's default fonts

To use the font from the list of default android fonts, set the font name to the TextView property in the fontModel object in applozic-settings.json file. Use fonts from the below list. You can only use one font per TextView, no combinations are allowed.

normal, 
bold,
italic,
bold_italic,
default,
default_bold,
monospace,
sans_serif,
serif

For example, if you want to use sans_serif font for the toolbar subtitle TextView, set the font name to the toolbarSubtitleFont property:

"fontModel": {
    "messageTextFont": "",
    "messageDisplayNameFont": "",
    "createdAtTimeFont": "",
    "toolbarTitleFont": "fonts/.ttf", 
    "toolbarSubtitleFont": "sans_serif", 
    "messageEditTextFont": ""
  }

Theme customization

You may not be able to change all the colors from the applozic-settings.json file. There are some colors such as the status bar/toolbar color, message status icon colors (sent, delivered etc icons) which you need to override in your colors file.

Follow the below steps to override the default colors in Kommunicate:

  1. Add this line in your tag in the colors.xml file

xmlns:tools="http://schemas.android.com/tools"
  1. Add the below colors in your colors.xml file and use your own color values in them

    <color name="applozic_theme_color_primary_dark" tools:override="true">#FF4081color>Status bar color

NOTE: primary colors such as Tool bar color, message_status_icon_colors can be set from the Kommunicate dashboard

Sample colors.xml file:


<resources xmlns:tools="http://schemas.android.com/tools">
    <Your other custom colors go here> // Add the specific colors you want to set here
    <color name="applozic_theme_color_primary_dark" tools:override="true">#FF4081color>Status bar color
resources>

Sending additional metadata with messages

If you need to send some additional data with all the messages sent from a device, then you need to set predefined metadata when logging in the user.

For example, if you need to send deviceInformation with all the messages sent from that device then call the below function in onSuccess of login or whichever initial method you are calling from Kommunicate:

 Map<String, String> metadata = new HashMap<>();
 metadata.put("deviceId", "Current Device ID");
 metadata.put("deviceManufaturer", "Some manufacturer");
 KmSettings.updateChatContext(context, metadata);

This data will be sent with all the messages sent from the device.

Pass Custom data to bot platform

Use the below code to send the custom data to bot platform and pass the key-value string to a Map to the below method Kommunicate.updateChatContext.

  Map<String, String> metadata = new HashMap<>();
  metadata.put("key1", "value1"); 
  metadata.put("key2", "value2"); 
  
  if (Kommunicate.isLoggedIn(context)) { 
     Kommunicate.updateChatContext(context, metadata);
  }

Note: Make sure to call this method after login success or conversation builder success.

Set parent activity to the ConversationActivity dynamically

If you have a use case where the conversation is launched from multiple activities, then you can set the parent activity to the conversation activity so that the user navigates back to the parent activity when the app is launched from chat notification. Use the below code to set the parentActivity dynamically:

  KommunicateSetting.getInstance(getContext()).setParentActivity("");
  

Speech-to-Text and Text-to-Speech support

The quality of the customer journey is everything in a product. STT and TTS will help you in enhancing the user experience and people with different learning styles prefer using these features, hence we have decided to help our clients in this way and added the support for this.

You can enable the Speech-to-Text and Text-to-Speech using the below setting;

KmPrefSettings.getInstance(SplashScreenActivity.this)
                     .enableSpeechToText(true) 
                     .enableTextToSpeech(true) 
                     .setSendMessageOnSpeechEnd(true) 
                     .setSpeechToTextLanguage("zh-TW") 
                     .setTextToSpeechLanguage("zh-TW"); 
   

Text to speech: Works only when the conversation is open and a new message is received within the conversation.

Speech to text: The mic button used to record and send audio will function as STT starter. Just click the button once and the device will start listening. To cancel an ongoing listening, click on the button again. The audio button will scale animate depending on the input voice amplitude. The partial results will be set on the message edit text but the send message button will only be enabled once the complete speech is received. When isSendOnSpeechEnd = true, the message will be sent automatically once the text is received.

To Integrate your own STT or TTS service, replace the KmSpeechToText and KmTextToSpeech implementation with your service.

Last updated