How to add a bot to an Android application using Blip Chat January 23, 2023 14:45 Updated Index: Adding reference Prerequisites Opening your conversation window (Optional) Customizing the chat interface on Android Authentication Hide the window menu Window title With Blip Chat, it is possible to place your bot inside your Android application very simply. To do this, add the repository reference in your project's build.gradle file: 1. Adding reference Add the reference to the Maven jcenter repository. For questions about this step, consult the official documentation: https://bintray.com/bintray/jcenter allprojects { repositories { //others repository dependencies jcenter() }} And import the module via gradle: implementation 'net.take:blip-chat:2.1.24' Or via Maven: <dependency> <groupId>net.take</groupId> <artifactId>blip-chat</artifactId> <version>2.1.24</version> <type>pom</type></dependency> Or download the latest JAR version and import it into your app. 2. Prerequisites To be able to use Blip Chat, your app must have access to the internet. Such permission must be requested within your project's AndroidManifest.xml file. If at any time your chatbot requests the user's location, you must also add the location permission. To upload files, you will also need to grant permissions. To do so, add the information below to your project's manifest file: <manifest xlmns:android...> ... <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CAMERA" /> ...</manifest> You will also need to add the GSON dependency to your application, as Blip Chat uses this library. implementation 'com.google.code.gson:gson:2.8.5' 3. Opening your conversation window To open the chat window with the bot inside your application, use the BlipClient class and call the openBlipThread method, passing its current context and its API-KEY. BlipClient.openBlipThread(context, "YOUR-BLiP-CHAT-API-KEY", null); To find your bot's Blip Chat API-KEY, go to the portal and choose the corresponding bot. Click on the Channels module and choose the Blip Chat channel. Click on the Installation tab and copy your API-KEY, as shown in the image below: To find your bot's Blip Chat API-KEY, go to the portal and choose the corresponding bot. Click on the Channels module and choose the Blip Chat channel. Click on the Installation tab and copy your API-KEY. Note: The openBlipThread method can return an exception, as it checks if it has all the information needed to open the chat. Then, you must place it within a try catch. You can also pass a BlipOptions object, which has some optional settings that will be covered later. Example Imagine that you want to open a conversation between the user and your chatbot as soon as the app is opened. public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { BlipClient.openBlipThread(context, "YOUR-API-KEY", null); } catch (IllegalArgumentException e) { e.printStackTrace(); } }} 4. (Optional) Customizing the chat interface on Android There are some possibilities for customizing your chat that can be configured through the BlipOptions object. Are they: Authentication It is possible to define the type of authentication of the user who will chat with your chatbot. There are two types of authentications possible: Not logged in: in which each user is treated as a guest and there is no information about him. Logged in: in which the app developer is responsible for passing user information to Blip Chat. In this mode, the conversation history is available whenever the user logs in. To better understand the possible authentication modes, check out this post. Example: import net.take.blipchat.AuthType;import net.take.blipchat.BlipClient;import net.take.blipchat.models.AuthConfig;import net.take.blipchat.models.BlipOptions;import org.limeprotocol.messaging.resources.Account;...AuthConfig authConfig = new AuthConfig(AuthType.Dev, "userId123PS","pass123PS");Account account = new Account();account.setFullName("User Name Android123");account.setEmail("test@android.com");BlipOptions blipOptions = new BlipOptions();blipOptions.setAuthConfig(authConfig);blipOptions.setAccount(account);BlipClient.openBlipThread(context, APP_KEY, blipOptions); Hide the window menu The chat window with your chatbot has a menu in the upper right corner that can be hidden. To do this, just set the value for the hideMenu property inside the BlipOptions object. By default, this property is false. BlipOptions blipOptions = new BlipOptions();blipOptions.setHideMenu(true); Window title On Android, the Blip Chat window has a title that can be customized. To do this, set the windowTitle property value to the appropriate title. By default, this title is Blip Chat. let options = BlipOptions()options.windowTitle = "Seu Título"; Example import net.take.blipchat.*;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { BlipOptions blipOptions = new BlipOptions(); blipOptions.setAuthType(AuthType.DEV); blipOptions.setUserIdentifier("USER-IDENTIFIER"); blipOptions.setUserPassword("USER-PASSWORD"); blipOptions.setUserName("USER-NAME"); blipOptions.setUserEmail("USER-MAIL"); blipOptions.setHideMenu(true); // Hide the window menu BlipClient.openBlipThread(MainActivity.this, "YOUR-API-KEY", blipOptions); } catch (IllegalArgumentException e) { e.printStackTrace(); } }} For more information, access the discussion on the subject in our community or the videos on our channel. 😃 Related articles How to add a bot to an iOS application using BliP Chat How to add push notifications to BLiP Chat Android Features of the Blip Chat Widget How to add a bot to a website using Blip Chat Sending WhatsApp Active Messages on Blip Desk