Class Dimelo

java.lang.Object
com.dimelo.dimelosdk.main.Dimelo

public class Dimelo extends Object
 `Dimelo` is a central object to access Dimelo API.

 You instantiate Dimelo with an API key, configure the listener, information
 about the current user and use it to display a chat view controller.

 There are two modes in which API instance can be configured: a secure and less secure one.
 ### Recommended mode: with server-signed authentication token.

 
// Instantiate dimelo with public api key and a hostname. Dimelo dimelo = Dimelo.setup(context).initWithApiKey("public api key", "api.example.com", this); // Assign optional properties to include in authenticated JWT token. dimelo.setUserIdentifier("optional user account ID"); dimelo.setAuthenticationInfo({ <extra fields to add to JWT token> }) // Retrieve a dictionary to be signed by your server within a JWT token: JSONObject dict = dimelo.getJwtDictionary(); // Send dict to your server and receive a signed JWT token in response. // Token must be signed with a secret key corresponding to public API key that you use in your app. // Assign a token to dimelo.jwt so it can be used in all communications. dimelo.setJwt(jwtFromServer);
Now Dimelo will be able to make requests to Dimelo servers, send and receive chat messages etc. ### Unsafe mode which does not require signing a JWT token by your server:
// Instantiate dimelo with *secret* api key and a hostname. Dimelo dimelo = Dimelo.setup(context).initWithApiSecret("secret api key", "api.example.com", this); // Assign optional properties to include in authenticated JWT token. dimelo.setUserIdentifier("optional user account ID"); dimelo.setAuthenticationInfo({ <extra fields to add to JWT token> }) // Dimelo will compute and sign a valid JWT token automatically each time you change one of the properties above. // All communications will include the signed JWT token as if they were signed by your server.
**WARNING:** Note that anyone who extracts your secret API key will be able to impersonate any user if they know their userIdentifier. User's data is relatively safe if userIdentifier is not well-known or cannot be easily guessed.
  • Field Details

    • interactiveNotification

      public static boolean interactiveNotification
    • isCacheEnabled

      public static final boolean isCacheEnabled
      See Also:
    • DIMELO_DEFAULT_HOSTNAME

      protected static final String DIMELO_DEFAULT_HOSTNAME
      See Also:
    • RC_DEFAULT_PROTOCOL

      protected static String RC_DEFAULT_PROTOCOL
  • Method Details

    • setup

      public static Dimelo setup(android.content.Context context)
       Create an instance of Dimelo.
       It needs to be called once and then Dimelo.getInstance() can be called
       
      Parameters:
      context - : Context of the application
    • getInstance

      public static Dimelo getInstance()
       Get the Dimelo instance
       Be careful to call Dimelo.setup(Context context) first
       
    • isInstantiated

      public static boolean isInstantiated()
    • getThreadUuid

      public String getThreadUuid()
    • fillDimeloWithParameters

      public void fillDimeloWithParameters(String dimelo_device_token, String dimelo_api_key, boolean dimelo_debug, String dimelo_api_secret, String dimelo_domain_name, String dimelo_host_name, String dimelo_messageContext_info, String dimelo_authentication_info, String dimelo_user_identifier, String dimelo_user_name, String dimelo_jwt, String threadUuid, boolean threadsEnabled)
    • isThreadsEnabled

      public Boolean isThreadsEnabled()
    • setThreadsEnabled

      public void setThreadsEnabled(Boolean threadsEnabled)
    • getPushNotificationService

      public String getPushNotificationService()
       return the push notification service
       
    • setPushNotificationService

      public void setPushNotificationService(String pushNotificationService)
       set the push notification service
       
      Parameters:
      pushNotificationService - can be "hms" or "fcm". Default value is "fcm".
    • isInternalInteractiveNotification

      public boolean isInternalInteractiveNotification()
    • setInternalInteractiveNotification

      public void setInternalInteractiveNotification(boolean internalInteractiveNotification)
    • getInstallationIdentifier

      public String getInstallationIdentifier()
      Per-installation identifier generated when the component is instantiated for the first time within the app.
    • initWithApiKey

      public Dimelo initWithApiKey(String apiKey, String domainName, @Nullable Dimelo.DimeloListener dimeloListener)
       Initializes API client with a public API key, domainName and a listener.
       For correct operation you will have to provide a valid signed JWT token via `jwt` property.
       To do so, fill in `userIdentifier`, `authenticationInfo` and send the resulting `jwtDictionary` to your server.
      
       This is a recommended way to access Dimelo API.
       
      Parameters:
      apiKey - public hex-encoded API key, typically specific to your app.
      domainName - is your Dimelo Digital domain name (e.g. if your Dimelo Digital url is "DIMELO_DOMAIN_NAME.engagement.dimelo.com", then your domainName will be "DIMELO_DOMAIN_NAME")
      dimeloListener - an instance of `DimeloListener` interface.
    • initializeWithApiKeyAndHostName

      public Dimelo initializeWithApiKeyAndHostName(String apiKey, String hostName, @Nullable Dimelo.DimeloListener dimeloListener)
       Initializes API client with a public API key, domainName and a listener.
       For correct operation you will have to provide a valid signed JWT token via `jwt` property.
       To do so, fill in `userIdentifier`, `authenticationInfo` and send the resulting `jwtDictionary` to your server.
      
       This is a recommended way to access Dimelo API.
       
      Parameters:
      apiKey - public hex-encoded API key, typically specific to your app.
      hostName - is your hostname (e.g. if your Dimelo Digital url is "DIMELO_DOMAIN_NAME.engagement.dimelo.com", then your hostName will be "DIMELO_DOMAIN_NAME.messaging.dimelo.com")
      dimeloListener - an instance of `DimeloListener` interface.
    • initWithApiSecret

      public Dimelo initWithApiSecret(String apiSecret, String domainName, @Nullable Dimelo.DimeloListener dimeloListener)
       Initializes API client with a secret API key, domainName and a listener.
       This mode is less secure than `initWithApiKey(apiKey, domainName, dimeloListener)` because shared secret is stored inside the app.
       
      Parameters:
      apiSecret - a hex-encoded API secret key, typically specific to your app.
      domainName - is your Dimelo Digital domain name (e.g. if your Dimelo Digital url is "DIMELO_DOMAIN_NAME.engagement.dimelo.com", then your domainName will be "DIMELO_DOMAIN_NAME")
      dimeloListener - an instance of `DimeloListener` interface.
    • initializeWithApiSecretAndHostName

      public Dimelo initializeWithApiSecretAndHostName(String apiSecret, String hostName, @Nullable Dimelo.DimeloListener dimeloListener)
       Initializes API client with a secret API key, domainName and a listener.
       This mode is less secure than `initWithApiKey(apiKey, domainName, dimeloListener)` because shared secret is stored inside the app.
       
      Parameters:
      apiSecret - a hex-encoded API secret key, typically specific to your app.
      hostName - is your hostname (e.g. if your Dimelo Digital url is "DIMELO_DOMAIN_NAME.engagement.dimelo.com", then your hostName will be "DIMELO_DOMAIN_NAME.messaging.dimelo.com")
      dimeloListener - an instance of `DimeloListener` interface.
    • disableLibraryAttachment

      public static void disableLibraryAttachment()
           Disable the ability to pick an attachment from the Photos library
           Must be set at Dimelo initialization phase.
       
    • disableCameraAttachment

      public static void disableCameraAttachment()
           Disable the ability to pick an attachment from the Camera
           Must be set at Dimelo initialization phase.
       
    • disableVideoAttachment

      public static void disableVideoAttachment()
           Disable the ability to pick a video from the gallery
           Must be set at Dimelo initialization phase.
       
    • disableDocumentAttachment

      public static void disableDocumentAttachment()
           Disable the ability to pick a document in the file explorer
           Must be set at Dimelo initialization phase.
       
    • disableLocationAttachment

      public static void disableLocationAttachment()
           Disable the ability to pick an attachment from the google maps services
           Must be set at Dimelo initialization phase.
       
    • disableAttachments

      public static void disableAttachments()
           Disable the ability to pick an attachment from the Photos library
           Must be set at Dimelo initialization phase.
       
    • isLibraryAttachmentEnabled

      public static Boolean isLibraryAttachmentEnabled()
           Returns whether the ability to pick an attachment from the Photos library is enabled
       
    • isCameraAttachmentEnabled

      public static Boolean isCameraAttachmentEnabled(android.content.Context context)
           Returns whether the ability to pick an attachment from the Camera is enabled
       
    • isLocationAttachmentEnabled

      public static Boolean isLocationAttachmentEnabled(android.content.Context context)
           Returns whether the ability to pick a location is enabled
       
    • isAttachmentsEnabled

      public static Boolean isAttachmentsEnabled(android.content.Context context)
           Returns whether the ability to pick an attachment is enabled
       
    • setDimeloListener

      public void setDimeloListener(@Nullable Dimelo.DimeloListener listener)
       Set a DimeloListener allowing to be notify from couple of events.
       
    • getDomainName

      public String getDomainName()
    • getHostName

      public String getHostName()
    • setInternalApiSecret

      public void setInternalApiSecret(String apiSecret)
       Per-application API secret key, typically specific to your app.
       API secret is always represented in hex format, e.g. `"ab12d1a2a9349797b807589e7e1635cb760d69de3a8241070b1682a1bdbd6d70"`.
       
    • setApiSecret

      @Deprecated public void setApiSecret(String apiSecret)
      Deprecated.
    • getApiSecret

      public String getApiSecret()
    • setDeviceToken

      public void setDeviceToken(String deviceToken)
       Device token for remote notifications. Optional.
       Usually given by GoogleCloudMessaging.register()
       
    • getDeviceToken

      public String getDeviceToken()
       Device token for remote notifications. Optional.
       Usually given by GoogleCloudMessaging.register()
       
    • setUserName

      public void setUserName(String userName)
       Optional name of the person to be sent to Dimelo.
       
    • getUserName

      public String getUserName()
       Optional name of the person to be sent to Dimelo.
       
    • getUnreadCount

      public int getUnreadCount()
       Number of unread messages.
      
       Default value is 0.
       
    • fetchUnreadCount

      public void fetchUnreadCount(Dimelo.UnreadCountCallback unreadCountCallback)
       Fetch and refresh the number of unread messages.
      
       On success, the number of unread messages is sent as parameter through `UnreadCountCallBack.onSuccess`
      
       In case of error, `UnreadCountCallback.onError` will be called with DimeloError object.
       Completion is called on main thread.
      
       DimeloError will mirror the HTTP code from Dimelo backend's response in their own code property.
       You may want to handle special HTTP code responses like 429 Too many requests for example.
       
    • setUnreadCountChangedListener

      public void setUnreadCountChangedListener(Dimelo.UnreadCountChangedCallback unreadCountChangedCallback)
       Set a listener to know when the number of unread messages has changed.
      
       On changed, the number of unread messages is sent as parameter through `UnreadCountChangedCallback.onChanged`
       
    • setUserIdentifier

      public void setUserIdentifier(String userIdentifier)
       Per-user unique identifier used to link messages sent from different devices to a single person.
      
       User identifier could be an arbitrary string that makes sense in your application:
       an email, an account number or a UUID.
      
       You can initialize and use Dimelo before user is logged-in, but after he has logged in,
       set the `userIdentifier` to let Dimelo know the real identity of the user.
      
       If `userIdentifier` is not set, user will be uniquely identified on the server by the `installationIdentifier`.
       
    • getUserIdentifier

      @Nullable public String getUserIdentifier()
       Per-user unique identifier used to link messages sent from different devices to a single person.
      
       User identifier could be an arbitrary string that makes sense in your application:
       an email, an account number or a UUID.
      
       You can initialize and use Dimelo before user is logged-in, but after he has logged in,
       set the `userIdentifier` to let Dimelo know the real identity of the user.
      
       If `userIdentifier` is not set, user will be uniquely identified on the server by the `installationIdentifier`.
       
    • getStaticMapsApiKey

      public String getStaticMapsApiKey()
    • setStaticMapsApiKey

      public void setStaticMapsApiKey(String staticMapsApiKey)
    • getAuthenticationInfo

      public org.json.JSONObject getAuthenticationInfo()
       Additional fields to be added to the JWT dictionary under "extra" key.
      
       You must make sure only PropertyList-compatible items are present inside this dictionary (keys must not be empty, whitespace only or contain the characters "$" or ".").
       
    • setAuthenticationInfo

      public void setAuthenticationInfo(org.json.JSONObject authenticationInfo)
       Additional fields to be added to the JWT dictionary under "extra" key.
      
       You must make sure only PropertyList-compatible items are present inside this dictionary (keys must not be empty, whitespace only or contain the characters "$" or ".").
       
    • getApiKey

      public String getApiKey()
       Per-application public API key that identifies all requests to Dimelo.
       API Key is always represented in hex format, e.g. `@"ab12d1a2a9349797b807589e7e1635cb760d69de3a8241070b1682a1bdbd6d70"`.
       
    • setApiKey

      @Deprecated public void setApiKey(String apiKey)
      Deprecated.
    • setDebug

      public void setDebug(boolean debug)
      Activate debug logging, using "Dimelog" as a debug tag.
    • getDebug

      public boolean getDebug()
    • getJwtDictionary

      public org.json.JSONObject getJwtDictionary()
       JWT dictionary to be signed. Computed out of apiKey, installationIdentifier, userIdentifier, authenticationInfo.
      
       Send this dictionary to your app's server to sign with a shared secret corresponding to API key.
      
       If you instantiate `Dimelo` with API secret, this dictionary will be used to compute `jwt` property automatically.
       
    • setJwt

      public void setJwt(String jwt)
       Complete serialized JWT token.
      
       If you use instantiation with public API key and your server signs JWT token, set this property
       with a JWT provided by your server.
      
       If you instantiate `Dimelo` with a secret API key, this property is computed automatically.
       
    • getJwt

      @Nullable public String getJwt()
       Complete serialized JWT token.
      
       If you use instantiation with public API key and your server signs JWT token, set this property
       with a JWT provided by your server.
      
       If you instantiate `Dimelo` with a secret API key, this property is computed automatically.
       
    • setMessageContextInfo

      public void setMessageContextInfo(org.json.JSONObject messageContextInfo)
       Arbitrary contextual info attached to a message.
      
       Attached only to the first message after a new value was specified.
      
       You must make sure only PropertyList-compatible items are present inside this dictionary (keys must not be empty, whitespace only or contain the characters "$" or ".").
      
       Example: user selects a category of a problem ("Technical" or "Sales")
       and then contacts the support. First message indicates what type of the problem user is talking about.
       
    • getMessageContextInfo

      @Nullable public org.json.JSONObject getMessageContextInfo()
       Arbitrary contextual info attached to a message.
      
       Attached only to the first message after a new value was specified.
      
       You must make sure only PropertyList-compatible items are present inside this dictionary (keys must not be empty, whitespace only or contain the characters "$" or ".").
      
       Example: user selects a category of a problem ("Technical" or "Sales")
       and then contacts the support. First message indicates what type of the problem user is talking about.
       
    • consumeReceivedRemoteNotification

      public static boolean consumeReceivedRemoteNotification(@NonNull android.content.Context context, @NonNull android.os.Bundle payload, @Nullable Dimelo.NotificationDisplayer notifDisplayer, @Nullable Class<?> activity)
       A method to call when you receive a notification.
       It will check if it is a "Dimelo notification" and if yes it will process
       Takes as parameter the Activity to be launched once the notification has been clicked
       
      Returns:
      "true" if it has been processed, "false" otherwise
    • consumeReceivedRemoteNotification

      public static boolean consumeReceivedRemoteNotification(@NonNull android.content.Context context, @NonNull Map<String,String> payload, @Nullable Dimelo.NotificationDisplayer notifDisplayer, @Nullable Class<?> activity)
       A method to call when you receive a notification.
       It will check if it is a "Dimelo notification" and if yes it will process
       Takes as parameter the Activity to be launched once the notification has been clicked
       
      Returns:
      "true" if it has been processed, "false" otherwise
    • consumeReceivedRemoteNotification

      public static boolean consumeReceivedRemoteNotification(@NonNull android.content.Context context, @NonNull android.os.Bundle payload, @Nullable Dimelo.NotificationDisplayer notifDisplayer)
       A method to call when you receive a notification.
       It will check if it is a "Dimelo notification" and if yes it will process
       
      Returns:
      "true" if it has been processed, "false" otherwise
    • consumeReceivedRemoteNotification

      public static boolean consumeReceivedRemoteNotification(@NonNull android.content.Context context, @NonNull Map<String,String> payload, @Nullable Dimelo.NotificationDisplayer notifDisplayer)
       A method to call when you receive a notification.
       It will check if it is a "Dimelo notification" and if yes it will process
       
      Returns:
      "true" if it has been processed, "false" otherwise
    • openRcActivity

      public void openRcActivity(android.content.Context context)
       Creates a new instance of a chat as an Activity.
       The activity will take the whole screen and hide the host application.
       This is the easiest way to display a chat.
      
       To be able to call it you must declare it in your AndroidManifest.xml file with a name equals to "com.dimelo.dimelosdk.FullScreenChat"
      
       It will provide an actionBar with a customizable title.
       If you do want to use your very own actionBar, you can call openRcActivityCustomActionBar()
       
    • openRcActivity

      public void openRcActivity(android.content.Context context, android.content.Intent chatIntent)
       Creates a new instance of a chat as an Activity.
       The activity will take the whole screen and hide your application.
       This is the easiest way to display a chat.
      
       To be able to call it you must declare it in your AndroidManifest.xml file with a name equals to "com.dimelo.dimelosdk.FullScreenChat"
      
       It will provide an actionBar with a customizable title.
       If you do want to use your very own actionBar, you can call openRcActivityCustomActionBar()
       
    • openRcActivityNoActionBar

      public void openRcActivityNoActionBar(android.content.Context context)
       Creates a new instance of a chat as an Activity.
       The activity will take the whole screen and hide your application.
      
       To be able to call it you must declare it in your AndroidManifest.xml file with a name equals to "com.dimelo.dimelosdk.FullScreenChat"
      
       It will provide an actionBar with a customizable title.
       If you want a default actionBar to be automatically displayed, you can call openRcActivity()
       
    • newRcFragment

      @NonNull public RcFragment newRcFragment()
       Creates a new instance of a chat as a fragment if threads are disabled otherwise creates a new instance of a threads list as a fragment.
      
       Use FragmentTransaction to show/hide it.
       
      Returns:
      A Fragment containing a chat view or threads list view.
    • setOnActivitySetupAppearenceListener

      public void setOnActivitySetupAppearenceListener(@Nullable Dimelo.OnActivitySetupAppearanceListener onActivitySetupAppearanceListener)
       ChatActivity only:
       Called when the ChatActivity is creating its view.
       Allow the host application to customize the ChatActivity
       
    • notifyKeyboardOpen

      public void notifyKeyboardOpen(boolean isOpen)
    • sendReplyMessage

      public void sendReplyMessage(String message, @NonNull <any> viewUpdater)
       Called when the reply notification is called.
       
      Parameters:
      message - A message content.
      viewUpdater - A ViewUpdaterCallback.
    • sendMessage

      public void sendMessage(String message)
       Called to send a customer message
       
      Parameters:
      message - A message content.
    • sendLocationMessage

      public void sendLocationMessage(android.content.Intent data, Chat chat)
    • addMessageViewUpdaterCallback

      public <any> addMessageViewUpdaterCallback(android.app.NotificationManager manager)
    • getString

      public String getString(android.content.Context context, String identifier, int resId)
    • getThreadUuidFromNotif

      public static String getThreadUuidFromNotif()
    • openWebView

      public void openWebView(URL url, Dimelo.RC_WEB_VIEW_SIZE height)
       Called to open a webView.
       
      Parameters:
      url - A `URL` that represents the url to open in the WebView.
      height - A `RC_WEB_VIEW_SIZE` that will determine what size the WebView will take (must be one of `RC_WEB_VIEW_SIZE` possible values: `FULL_MODE` (100%), `TALL_MODE` (75%) or `COMPACT_MODE` (50%)).