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:
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.
In the "Build Settings" tab -> "Other linker flags" add "$(inherited)" flag
In the "Build Settings" tab -> "Enable bitcode" select "NO"
Chat Profile is an object which will let you know:
In order to get chat profile, do the following steps:
#import <Stringee/Stringee.h>
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:
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:
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);
}
NSString* accessToken = @"CUSTOMER_ACCESS_TOKEN";
self.stringeeClient = [[StringeeClient alloc] initWithConnectionDelegate:self];
[self.stringeeClient connectWithAccessToken:accessToken];
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:
Follow this instruction Messages
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:
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:
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: