Package com.dimelo.dimelosdk.main
Class Dimelo
java.lang.Object
com.dimelo.dimelosdk.main.Dimelo
`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.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 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);
**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.// 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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An abstract class which implement NotificationDisplayer This is the easiest way to display notifications.static class
The `DimeloListener` allows you to react to network activity and react to events created by the chat views.static interface
Interface which can be implemented in order to customize the notifications See BasicNotificationDisplayerstatic interface
ChatActivity only: Called when the ChatActivity is creating its view.static enum
static interface
static interface
Used with `Dimelo.fetchUnreadCount`static interface
Used with `Dimelo.setUnreadCountChangedListener` -
Field Summary
-
Method Summary
Modifier and TypeMethodDescription<any>
addMessageViewUpdaterCallback
(android.app.NotificationManager manager) static boolean
consumeReceivedRemoteNotification
(android.content.Context context, android.os.Bundle payload, Dimelo.NotificationDisplayer notifDisplayer) A method to call when you receive a notification.static boolean
consumeReceivedRemoteNotification
(android.content.Context context, android.os.Bundle payload, Dimelo.NotificationDisplayer notifDisplayer, Class<?> activity) A method to call when you receive a notification.static boolean
consumeReceivedRemoteNotification
(android.content.Context context, Map<String, String> payload, Dimelo.NotificationDisplayer notifDisplayer) A method to call when you receive a notification.static boolean
consumeReceivedRemoteNotification
(android.content.Context context, Map<String, String> payload, Dimelo.NotificationDisplayer notifDisplayer, Class<?> activity) A method to call when you receive a notification.static void
Disable the ability to pick an attachment from the Photos library Must be set at Dimelo initialization phase.static void
Disable the ability to pick an attachment from the Camera Must be set at Dimelo initialization phase.static void
Disable the ability to pick a document in the file explorer Must be set at Dimelo initialization phase.static void
Disable the ability to pick an attachment from the Photos library Must be set at Dimelo initialization phase.static void
Disable the ability to pick an attachment from the google maps services Must be set at Dimelo initialization phase.static void
Disable the ability to pick a video from the gallery Must be set at Dimelo initialization phase.void
fetchUnreadCount
(Dimelo.UnreadCountCallback unreadCountCallback) Fetch and refresh the number of unread messages.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) Per-application public API key that identifies all requests to Dimelo.org.json.JSONObject
Additional fields to be added to the JWT dictionary under "extra" key.boolean
getDebug()
Device token for remote notifications.Per-installation identifier generated when the component is instantiated for the first time within the app.static Dimelo
Get the Dimelo instance Be careful to call Dimelo.setup(Context context) firstgetJwt()
Complete serialized JWT token.org.json.JSONObject
JWT dictionary to be signed.org.json.JSONObject
Arbitrary contextual info attached to a message.return the push notification servicestatic String
int
Number of unread messages.Per-user unique identifier used to link messages sent from different devices to a single person.Optional name of the person to be sent to Dimelo.initializeWithApiKeyAndHostName
(String apiKey, String hostName, Dimelo.DimeloListener dimeloListener) Initializes API client with a public API key, domainName and a listener.initializeWithApiSecretAndHostName
(String apiSecret, String hostName, Dimelo.DimeloListener dimeloListener) Initializes API client with a secret API key, domainName and a listener.initWithApiKey
(String apiKey, String domainName, Dimelo.DimeloListener dimeloListener) Initializes API client with a public API key, domainName and a listener.initWithApiSecret
(String apiSecret, String domainName, Dimelo.DimeloListener dimeloListener) Initializes API client with a secret API key, domainName and a listener.static Boolean
isAttachmentsEnabled
(android.content.Context context) Returns whether the ability to pick an attachment is enabledstatic Boolean
isCameraAttachmentEnabled
(android.content.Context context) Returns whether the ability to pick an attachment from the Camera is enabledstatic boolean
boolean
static Boolean
Returns whether the ability to pick an attachment from the Photos library is enabledstatic Boolean
isLocationAttachmentEnabled
(android.content.Context context) Returns whether the ability to pick a location is enabledRcFragment
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.void
notifyKeyboardOpen
(boolean isOpen) void
openRcActivity
(android.content.Context context) Creates a new instance of a chat as an Activity.void
openRcActivity
(android.content.Context context, android.content.Intent chatIntent) Creates a new instance of a chat as an Activity.void
openRcActivityNoActionBar
(android.content.Context context) Creates a new instance of a chat as an Activity.void
openWebView
(URL url, Dimelo.RC_WEB_VIEW_SIZE height) Called to open a webView.void
sendLocationMessage
(android.content.Intent data, Chat chat) void
sendMessage
(String message) Called to send a customer messagevoid
sendReplyMessage
(String message, <any> viewUpdater) Called when the reply notification is called.void
Deprecated.void
setApiSecret
(String apiSecret) Deprecated.void
setAuthenticationInfo
(org.json.JSONObject authenticationInfo) Additional fields to be added to the JWT dictionary under "extra" key.void
setDebug
(boolean debug) Activate debug logging, using "Dimelog" as a debug tag.void
setDeviceToken
(String deviceToken) Device token for remote notifications.void
setDimeloListener
(Dimelo.DimeloListener listener) Set a DimeloListener allowing to be notify from couple of events.void
setInternalApiSecret
(String apiSecret) Per-application API secret key, typically specific to your app.void
setInternalInteractiveNotification
(boolean internalInteractiveNotification) void
Complete serialized JWT token.void
setMessageContextInfo
(org.json.JSONObject messageContextInfo) Arbitrary contextual info attached to a message.void
setOnActivitySetupAppearenceListener
(Dimelo.OnActivitySetupAppearanceListener onActivitySetupAppearanceListener) ChatActivity only: Called when the ChatActivity is creating its view.void
setPushNotificationService
(String pushNotificationService) set the push notification servicevoid
setStaticMapsApiKey
(String staticMapsApiKey) void
setThreadsEnabled
(Boolean threadsEnabled) void
setUnreadCountChangedListener
(Dimelo.UnreadCountChangedCallback unreadCountChangedCallback) Set a listener to know when the number of unread messages has changed.static Dimelo
setup
(android.content.Context context) Create an instance of Dimelo.void
setUserIdentifier
(String userIdentifier) Per-user unique identifier used to link messages sent from different devices to a single person.void
setUserName
(String userName) Optional name of the person to be sent to Dimelo.
-
Field Details
-
interactiveNotification
public static boolean interactiveNotification -
isCacheEnabled
public static final boolean isCacheEnabled- See Also:
-
DIMELO_DEFAULT_HOSTNAME
- See Also:
-
RC_DEFAULT_PROTOCOL
-
-
Method Details
-
setup
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
Get the Dimelo instance Be careful to call Dimelo.setup(Context context) first
-
isInstantiated
public static boolean isInstantiated() -
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
-
setThreadsEnabled
-
getPushNotificationService
return the push notification service
-
setPushNotificationService
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
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
Returns whether the ability to pick an attachment from the Photos library is enabled
-
isCameraAttachmentEnabled
Returns whether the ability to pick an attachment from the Camera is enabled
-
isLocationAttachmentEnabled
Returns whether the ability to pick a location is enabled
-
isAttachmentsEnabled
Returns whether the ability to pick an attachment is enabled
-
setDimeloListener
Set a DimeloListener allowing to be notify from couple of events.
-
getDomainName
-
getHostName
-
setInternalApiSecret
Per-application API secret key, typically specific to your app. API secret is always represented in hex format, e.g. `"ab12d1a2a9349797b807589e7e1635cb760d69de3a8241070b1682a1bdbd6d70"`.
-
setApiSecret
Deprecated. -
getApiSecret
-
setDeviceToken
Device token for remote notifications. Optional. Usually given by GoogleCloudMessaging.register()
-
getDeviceToken
Device token for remote notifications. Optional. Usually given by GoogleCloudMessaging.register()
-
setUserName
Optional name of the person to be sent to Dimelo.
-
getUserName
Optional name of the person to be sent to Dimelo.
-
getUnreadCount
public int getUnreadCount()Number of unread messages. Default value is 0.
-
fetchUnreadCount
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
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
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
-
setStaticMapsApiKey
-
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
Per-application public API key that identifies all requests to Dimelo. API Key is always represented in hex format, e.g. `@"ab12d1a2a9349797b807589e7e1635cb760d69de3a8241070b1682a1bdbd6d70"`.
-
setApiKey
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
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
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
Called when the reply notification is called.
- Parameters:
message
- A message content.viewUpdater
- A ViewUpdaterCallback.
-
sendMessage
Called to send a customer message
- Parameters:
message
- A message content.
-
sendLocationMessage
-
addMessageViewUpdaterCallback
public <any> addMessageViewUpdaterCallback(android.app.NotificationManager manager) -
getString
-
getThreadUuidFromNotif
-
openWebView
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%)).
-