How to add a bot to an iOS application using BliP Chat September 27, 2024 12:32 Updated Index: Prerequisites Setting up your chat Opening your conversation window Advanced features: Authentication Hide the window menu Window title Window title with type Dev authentication Specifying user data With Blip Chat, you can place your chatbot inside your Android and iOS application in a super simple way. On iOS, Blip Chat supports applications made in Swift and Objective-C. Installation is done through CocoaPod - if you don't already have CocoaPod, check out this guide teaching you how to configure it. To use Blip Chat, simply add the reference in the Podfile file: target 'MyApp' do ... use_frameworks! pod "BlipChat" ...end And finish installing the pod by running the command in your project directory: $ pod install Open * .xcworkspace with Xcode. Note: DO NOT use * .xcodeproj. You will receive an error if you open a project file instead of the workspace. Prerequisites To use Blip Chat on iOS, use iOS versions 10 or higher. On iOS, only the location permission needs to be informed. So, if your chatbot requests the user's location at any time, you should add a message to the user explaining why the location is needed. Add the Privacy - Location When In Use Usage Description key to your project's info.plist file. Setting up your chat To include your chatbot in your application, you need to get your ApiKey. If you have questions, you can check This post teaches you how to do this. You will also need to place your iOS App Id in the session Chatbot domains of the BLiP settings, to enable chat in your application. iOS App Project Id can be obtained from Signing & Capabilities of your project: Additionally, the iOS App Id must be added to your developer profile: And then added in the Bot, in Settings -> ChatBot Domains: To use location, configure the Usage Description Key to Location Service in the file info.plist. Use a chave Privacy - Location When In Use Usage Description and configure a message to ask the user for permission to use their location. Opening your conversation window Import the Blip SDK Swift: import BlipChat Objective-C: #import "BlipChat / BlipChat.h" Use the BlipClient class and call the openBlipThread method to open a new thread. Swift: BlipClient.openBlipThread (myView: self, apiKey: "SUA-API-KEY", options: BlipOptions()) Objective-C: [BlipClient openBlipThreadWithMyView: self appKey: (NSString *) @ "your-api-key" options: options error: nil]; Note: In Objective-C, the method name is openBlipThreadWithMyView. Now imagine that you want, for example, to open a conversation between the user and his chatbot as soon as the app is opened (when the ViewController is loaded). Swift: import UIKitimport WebKitimport BlipChatclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } override func viewDidAppear(_ animated: Bool) { do { try BlipClient.openBlipThread(myView: self, appKey: "your-api-key", options: BlipOptions()) } catch { print (error.localizedDescription) } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }} Objective-C: #import "ViewController.h"#import "BlipChat/BlipChat.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear: animated]; [BlipClient openBlipThreadWithMyView:self appKey:@"your-app-key" options:nil error: nil];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end Advanced features: There are also some customization possibilities for your chat that can be configured through the BlipOptions object. 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: Guest: where each user is treated as a guest and there is no information about them; Dev: where 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, take a look at this post that explains each type in detail. To define the authentication type, use the AuthTypeProvider.AuthType enum in the BlipOptions authType property. When using Swift, the possible types are: .Guest and .Dev. When using Objective-C, the possible values are: AuthTypeGuest and AuthTypeDev. Swift: let authConfig = AuthConfig(authType: .Dev, userIdentity: "user-identifier", userPassword: "user-password")options = BlipOptions(authType: authConfig, account: nil) Objective-C: AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"user-identifier" userPassword:@"user-password"];options = [[BlipOptions alloc] initWithAuthType:authConfig account: nil]; Hide the window menu The chat window with your chatbot has a menu in the upper right corner and can be hidden. To do this, just set the value for the hideMenu property inside the BlipOptions object. Swift: let options = BlipOptions()options.hideMenu = false; Objective-C: BlipOptions *options = [[BlipOptions alloc] init];options.hideMenu = NO; Window title On iOS, 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. Swift: let options = BlipOptions()options.windowTitle = "Your title"; Objective-C: BlipOptions *options = [[BlipOptions alloc] init];options.windowTitle = @"Your title"; Window title with type Dev authentication Swift: import UIKitimport WebKitimport BlipChatclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } override func viewDidAppear(_ animated: Bool) { let authConfig = AuthConfig(authType: .Dev, userIdentity: "user-identifier", userPassword: "user-password") let account = Account(fullname: "user-name", email: "user-email") let options = BlipOptions(authType: authConfig, account: account) options.windowTitle = "Seu título" do { try BlipClient.openBlipThread(myView: self, appKey: "sua-app-key", options: options) } catch { print (error.localizedDescription) } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }} Objective-C: #import "ViewController.h"#import "BlipChat/BlipChat.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear: animated]; AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"user-identifier" userPassword:@"user-password"]; Account *account = [[Account alloc] initWithFullname:@"user-name" email:@"user-email"]; BlipOptions *options = [[BlipOptions alloc] initWithAuthType:authConfig account:account]; options.windowTitle = @"Seu título"; [BlipClient openBlipThreadWithMyView:self appKey: @"your-app-key" options:options error: nil];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end Specifying user data Blip Chat allows some user data, such as fullname, email and others, to be specified when uploading. To see all possible properties, access the Lime Protocol documentation. To define the information, create an Account object and pass it as a parameter to BlipOptions. Swift: let authConfig = AuthConfig(authType: .Dev, userIdentity: "user-identifier", userPassword: "user-password")let account = Account(fullname: "user-name", email: "user-email")options = BlipOptions(authType: authConfig, account: account) Objective-C: AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"user-identifier" userPassword:@"user-password"];Account *account = [[Account alloc] initWithFullname:@"user-name" email:@"user-email"];options = [[BlipOptions alloc] initWithAuthType:authConfig account: account]; Examples After getting to know a little more about the features of Blip Chat, let's make an example a little more complete. Let's say you wanted to open a conversation between the user and your chatbot with the Dev authentication type, providing the name, email and password information, and hide the chat window menu. Swift: import BlipChatclass ViewController: UIViewController { @IBAction func openThread(_ sender: Any) { let options = BlipOptions(authType: .Dev, userIdentifier: "IDENTIFICADOR-DO-USUARIO", userPassword: "SENHA-DO-USUARIO", userName: "NOME-DO-USUARIO", userEmail: "EMAIL-DO-USUARIO") options.windowTitle = "Meu App iOS" // Define o titulo da janela options.hideMenu = true // Esconde o menu da janela do { try BlipClient.openBlipThread(myView: self, apiKey: "SUA-API-KEY", options: options) } catch { print (error.localizedDescription) } }} Objective-C: #import "ViewController.h"#import "BlipChat/BlipChat.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear: animated];}- (IBAction)openThread:(id)sender { BlipOptions *options = [BlipOptions alloc]; if ([sender tag] == 0) { options = [options init] ; } else if([sender tag] == 1) { AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"ObjcTest1" userPassword:@"123456"]; Account *account = [[Account alloc] initWithFullname:@"iosName1" email:@"iosEmail1@email.com"]; account.encryptMessageContent = TRUE; options = [options initWithAuthType:authConfig account:account]; } else if([sender tag] == 2) { AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"ObjcTest2" userPassword:@"123456"]; Account *account = [[Account alloc] initWithFullname:@"iosName2" email:@"iosEmail2@email.com"]; account.encryptMessageContent = TRUE; options = [options initWithAuthType:authConfig account:account]; } else if([sender tag] == 3) { AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"ObjcTest3" userPassword:@"123456"]; Account *account = [[Account alloc] initWithFullname:@"iosName3" email:@"iosEmail3@email.com"]; options = [options initWithAuthType:authConfig account:account]; } options.windowTitle = @"Objective C"; [BlipClient openBlipThreadWithMyView:self appKey:@"YOUR-APP-KEY" options:options error:nil];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];}@end 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 Android application using Blip Chat How to add a bot to a website using Blip Chat Features of the Blip Chat Widget How to add push notifications to BLiP Chat Android How to send WhatsApp notifications through Blip API