Suggestions

close search

Getting started with Stringee Live-chat API using iOS SDK

Step 1: Prepare

In order to use Stringee live-chat API you need to have a widget key which will be used to identify your portal. You can get that key by doing the following steps:

  1. Login to your StringeeX account as admin
  2. In the Setting -> Chat Management -> Chat Widget -> Embed web widget, get the key in the url

Step 2: Add SDK to Project

The simplest way to import the SDK into an iOS project is with CocoaPods. Open your project's Podfile and add this line to your app's target:

pod 'StringeeChat'

Then from the command line run:

pod install --repo-update

If you're new to CocoaPods, see their official documentation for info on how to create and use Podfiles.

  1. In the "Build Settings" tab -> "Other linker flags" add "$(inherited)" flag

  2. In the "Build Settings" tab -> "Enable bitcode" select "NO"

Step 3: Get chat profile

Chat Profile is an object which will let you know:

In order to get chat profile, do the following steps:

  1. Add a line to import the Stringee library:
    #import <Stringee/Stringee.h>
  2. Using the following function to get Chat Profile information.
    self.stringeeClient = [[StringeeClient alloc] init];
    [self.stringeeClient getChatProfileWithKey:@"YOUR_WIDGET_KEY" completion:^(BOOL status, int code, NSString *message, SXChatProfile *chatProfile) {
        NSLog(@"getChatProfile callback %@", message);
    }];

In which:

Step 4: Generate access token for customers

In order to chat with your agents, your customers have to connect to Stringee server first. But they are not user in your system, they can be anybody, so you need to generate tokens for them. In order to do that, call the following function:

    [stringeeClient generateTokenForCustomerWithKey:@"YOUR_WIDGET_KEY" username:@"YOUR_CUSTOMER_NAME" email:@"YOUR_CUSTOMER_EMAIL" completion:^(BOOL status, int code, NSString *message, NSString *token) {
        NSLog(@"===== TOKEN %@", token);
    }];

In which:

Step 5: Connect to Stringee Server

  1. Implements the StringeeConnectionDelegate protocol

In .h file

@interface ViewController : UIViewController <StringeeConnectionDelegate>

@property(strong, nonatomic) StringeeClient * stringeeClient;

@end

In .m file

- (void)requestAccessToken:(StringeeClient *)stringeeClient {
    NSLog(@"requestAccessToken");
}

- (void)didConnect:(StringeeClient *)stringeeClient isReconnecting:(BOOL)isReconnecting {
    NSLog(@"Successfully connected to Stringee Server, user ID: %@", stringeeClient.userId);
}

- (void)didDisConnect:(StringeeClient *)stringeeClient isReconnecting:(BOOL)isReconnecting {
    NSLog(@"didDisConnect");
}

- (void)didFailWithError:(StringeeClient *)stringeeClient code:(int)code message:(NSString *)message {
    NSLog(@"Failed connection to Stringee Server with error: %@", message);
}
  1. Start connecting
NSString* accessToken = @"CUSTOMER_ACCESS_TOKEN";
self.stringeeClient = [[StringeeClient alloc] initWithConnectionDelegate:self];
[self.stringeeClient connectWithAccessToken:accessToken];

Step 6: Create a conversation

Before creating conversation for your customer and your agent, you can update customer information to Stringee server, so your agent can know more about your customer (where is the customer from? what type of cell phone is the customer using?...). In order to do that, call the following function:

    // Get customer info
    [stringeeClient getCustomerInfo:^(BOOL status, int code, NSString *message, SXCustomerInfo *customerInfo) {
        NSLog(@"getCustomerInfo callback %@", message);
    }];

    // Update to Stringee server
    [stringeeClient updateUserInfo:customerInfo username:@"YOUR_CUSTOMER_NAME" email:@"YOUR_CUSTOMER_EMAIL" avatar:@"YOUR_CUSTOMER_AVATAR_URL" completion:^(BOOL status, int code, NSString *message) {
        NSLog(@"updateCustomerInfo callback %@", message);
    }];

Then call the following function to create conversation:

    [stringeeClient createLiveChatConversationWithQueueId:@"QUEUE_ID" completion:^(BOOL status, int code, NSString *message, StringeeConversation *conversation) {
        NSLog(@"createChat callback %@", message);
    }];

In which:

Step 7: Messages

Follow this instruction Messages

Step 8: Chat Transcript

If you wanna send chat's content to an email at any time, you can use the following function:

    [stringeeClient sendChatTranscriptTo:@"[email protected]" convId:@"convId" domain:@"" completion:^(BOOL status, int code, NSString *message) {
        NSLog(@"sendTranscript callback %@", message);
    }];

In which:

Step 9: End chat

In order to end the chat, you can call the following function:

    [stringeeClient endChatSupportWithConvId:@"convId" completion:^(BOOL status, int code, NSString *message) {
        NSLog(@"EndChat callback %@", message);
    }];

In which:

Step 10: Create ticket for miss chat

Case without agent to support customer's chat You can address this situation by following the steps in creating miss chat ticket:

    [stringeeClient createTicketForMissChatWithKey:@"WIDGET_KEY" userId: username:@"username" email:@"[email protected]" note:@"" completion:^(BOOL status, int code, NSString *message) {
        NSLog(@"createTicket callback %@", message);
    }];

In which: