Skip to main content
Version: 4.31.0

Configuration

Initialization

  1. In Application.onCreate(), you need to initialize the ThreadsLib.init(ConfigBuilder configBuilder) library.
class ConfigBuilder {
private val context: Context

private val pendingIntentCreator: PendingIntentCreator = { context, appMarker ->
...
}

private val unreadMessagesCountListener: UnreadMessagesCountListener? = null

private val isDebugLoggingEnabled: Boolean = false

private val historyLoadingCount: Int = 50

class ConfigBuilder(val context: Context) {
...
}
}

Initialization example:

class ThreadsDemoApplication : Application() {
override fun onCreate() {
super.onCreate()
val configBuilder = ConfigBuilder(this) // this - android context
val transportConfig = getTransportConfig(this)
configBuilder.serverBaseUrl(transportConfig.baseUrl)
.datastoreUrl(transportConfig.datastoreUrl)
.threadsGateUrl(transportConfig.threadsGateUrl)
.threadsGateProviderUid(transportConfig.threadsGateProviderUid)

ThreadsLib.init(configBuilder)
}

fun getTransportConfig(ctx: Context?): TransportConfig? {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx)
val baseUrl = sharedPreferences.getString(PREF_SERVER_BASE_URL, null)
?: return null
val datastoreUrl = sharedPreferences.getString(PREF_DATASTORE_URL, null)
?: return null
val threadsGateUrl = sharedPreferences.getString(PREF_THREADS_GATE_URL, null)
?: return null
val threadsGateProviderUid =
sharedPreferences.getString(PREF_THREADS_GATE_PROVIDER_UID, null)
?: return null

return TransportConfig(
baseUrl,
datastoreUrl,
threadsGateUrl,
threadsGateProviderUid
)
}
}

The required parameters are as the follows: context, serverBaseUrl, datastoreUrl, threadsGateUrl, threadsGateProviderUid. If you do not separate the paths for sending files and for working with the backend API, you can pass the same parameters for serverBaseUrl and for datastoreUrl. These parameters (except for context) and many others can be specified via the manifest. For example:

<meta-data  
android:name="im.threads.getDatastoreUrl"
android:value="http://datastore.yourcompany.com/"/>

Following is the full list of the parameters that can be speicifed via the manifest: "im.threads.getDatastoreUrl", "im.threads.getServerUrl", "im.threads.threadsGateUrl", "im.threads.threadsGateProviderUid", "im.threads.clientIdIgnoreEnabled", "im.threads.newChatCenterApi", "im.threads.attachmentEnabled", "im.threads.filesAndMediaMenuItemEnabled"

For the details about the required class parameters, refer to Appearance and Behavior Customization.

tip

You can see the parameter and file formats in more detail in the code of a test app. If you have any questions, contact support@edna.ru

Before you start working with the chat, you need to initialize the ThreadsLib.initUser(UserInfoBuilder userInfo) user.

    class UserInfoBuilder(var clientId: String) {
var authToken: String?
var authSchema: String?
var clientData: String?
var clientIdSignature: String
var userName: String?
var appMarker: String?
var clientIdEncrypted: Boolean = false // true if client id is encrypted
// ...
}
  • authToken - String that will be passed in the Authorization http header.
  • authSchema - String that will be passed in the X-Auth-Schema http header.
  • clientIdSignature - Authorization signature clientId. The signature must be generated on your authorization server based on clientId using the RSA private key, then encrypted in Base64. For more details, refer to the backend documentation.
  • userName - Client's name (can be empty)
  • clientData - JSON string with custom client data. The following parameters will be displayed in general client info: Example:
{
"name": "Name Surname",
"phone": "+7-999-999-99-99",
"email": "e@mail.com",
"customField":"customValue"
}
  • appMarker - App identifier. edna Android supports connecting several apps to the same server. For more details, refer to Appearance and Behavior Configuration). For that, you need to configure the identifier on the server and in the apps. Any unique string can be used as appMarkerappMarker must be the same for the corresponding Android and iOS apps.
  • clientIdEncrypted - Flag indicating that clientId is passed encrypted.
caution

The only required parameter is clientId. It must be unique and always refer to the same user. Avoid using phone numbers, email addresses, and other identifiers linked to user data as an identifier.

Chat Display

The chat can be displayed in two ways:

  • While being active - startActivity(new Intent(this, ChatActivity.class))
  • In a fragment
    • Create ChatFragment.newInstance() and display it in a required container
    • Pass the "back" button clicks and check whether that chat needs to be closed:
override fun onBackPressed() {
val needsCloseChat: Boolean = chatFragment.onBackPressed();
if (needsCloseChat) {
//hide chatfragment
}
}

To customize the chat appearance, use ThreadsLib.applyChatStyle(ChatStyle chatStyle). You can also redefine the library resources, but ChatStyle has more priority. The full list of settings is available here: Behavior and Appearance Settings

Example in ChatStyleBuilderHelper in the demo app