|
| 1 | +/* |
| 2 | + * Copyright 2016 salesforce.com, inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Use of this software is subject to the salesforce.com Developerforce Terms of |
| 6 | + * Use and other applicable terms that salesforce.com may make available, as may be |
| 7 | + * amended from time to time. You may not decompile, reverse engineer, disassemble, |
| 8 | + * attempt to derive the source code of, decrypt, modify, or create derivative |
| 9 | + * works of this software, updates thereto, or any part thereof. You may not use |
| 10 | + * the software to engage in any development activity that infringes the rights of |
| 11 | + * a third party, including that which interferes with, damages, or accesses in an |
| 12 | + * unauthorized manner the servers, networks, or other properties or services of |
| 13 | + * salesforce.com or any third party. |
| 14 | + * |
| 15 | + * WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS PROVIDED |
| 16 | + * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL |
| 17 | + * SALESFORCE.COM HAVE ANY LIABILITY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO, |
| 18 | + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR |
| 19 | + * DAMAGES BASED ON LOST PROFITS, DATA OR USE, IN CONNECTION WITH THE SOFTWARE, |
| 20 | + * HOWEVER CAUSED AND, WHETHER IN CONTRACT, TORT OR UNDER ANY OTHER THEORY OF |
| 21 | + * LIABILITY, WHETHER OR NOT YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 22 | + * DAMAGES. |
| 23 | + */ |
| 24 | + |
| 25 | +#import <Foundation/Foundation.h> |
| 26 | + |
| 27 | +@class SCSChat; |
| 28 | +@class SCSChatConfiguration; |
| 29 | +@class UNNotification; |
| 30 | +@protocol SCSChatSessionDelegate; |
| 31 | +@protocol SCSChatEventDelegate; |
| 32 | +@protocol SCSChatSession; |
| 33 | +@protocol SCSChatSessionInfo; |
| 34 | + |
| 35 | +/** |
| 36 | + SCSChatCompletionHandler block definition |
| 37 | +
|
| 38 | + @param error `NSError` instance describing the error. |
| 39 | + Error codes can be referenced from `SCSChatErrorCode`. |
| 40 | + |
| 41 | + @param scsc The instance of `SCSChat` the block is acting on. |
| 42 | + */ |
| 43 | +typedef void (^SCSChatCompletionHandler)(NSError *error, __weak SCSChat *scsc); |
| 44 | + |
| 45 | +/** |
| 46 | + SCSChatAvailabilityHandler block definition |
| 47 | +
|
| 48 | + @param error `NSError` instance describing the error. |
| 49 | + Error codes can be referenced from `SCSChatErrorCode`. |
| 50 | + @param available `BOOL` representing the availability of an agent to accept |
| 51 | + a chat session. |
| 52 | + @param estimatedWaitTime `NSTimeInterval` indicating the estimated wait time, if requested. |
| 53 | + */ |
| 54 | +typedef void (^SCSChatAvailabilityHandler)(NSError *error, BOOL available, NSTimeInterval estimatedWaitTime); |
| 55 | + |
| 56 | + |
| 57 | +/** |
| 58 | + |
| 59 | + The `SCSChat` class is the core interface to the chat SDK. |
| 60 | + This object manages the flow of chat sessions throughout the lifetime of the app. |
| 61 | + For UI-related chat functionality, see `SCSChatInterface`. |
| 62 | + |
| 63 | + To get an instance of this class, use the `SCServiceCloud.chatCore` property |
| 64 | + on `+[SCServiceCloud sharedInstance]`. |
| 65 | +
|
| 66 | + `SCSChat` conforms to a multicast delegate model for messaging. Any class that |
| 67 | + implements the `SCSChatSessionDelegate` protocol can be added to a list of delegates to |
| 68 | + receive session-related messages asynchronously using `-addDelegate:` Any class that |
| 69 | + implements the `SCSChatEventDelegate` protocol can be added to a list of delegates to |
| 70 | + receive general event messages asynchronously using `-addEventDelegate:` |
| 71 | + |
| 72 | + @see `SCSChatInterface` |
| 73 | + */ |
| 74 | +@interface SCSChat : NSObject |
| 75 | + |
| 76 | +///--------------------------------- |
| 77 | +/// @name Class Methods |
| 78 | +///--------------------------------- |
| 79 | + |
| 80 | +/** |
| 81 | + Notification identifier that is prepended to all push and local notifications |
| 82 | + generated by chat session. This can be used to differentiate notifications |
| 83 | + generated by chat from those generated by the host application. |
| 84 | + */ |
| 85 | ++ (NSString *)notificationIdentifier; |
| 86 | + |
| 87 | +///--------------------------------- |
| 88 | +/// @name Properties |
| 89 | +///--------------------------------- |
| 90 | + |
| 91 | +/** |
| 92 | + A reference to the `SCSChatConfiguration` object provided to the session on start. |
| 93 | + */ |
| 94 | +@property (nonatomic, readonly, strong) SCSChatConfiguration *configuration; |
| 95 | + |
| 96 | +/** |
| 97 | + A reference to a chat session, which provides realtime information about the current state of the chat session. |
| 98 | + */ |
| 99 | +@property (nonatomic, strong, readonly) NSObject<SCSChatSession, SCSChatSessionInfo> *session; |
| 100 | + |
| 101 | +///--------------------------------- |
| 102 | +/// @name Session Control |
| 103 | + |
| 104 | +///--------------------------------- |
| 105 | + |
| 106 | +/** |
| 107 | + Starts a chat session. |
| 108 | + Use this method if you intend to display your own UI. If you want to |
| 109 | + start a session with the default Snap-ins UI, see `-[SCSChatInterface showChatWithConfiguration:]`. |
| 110 | + |
| 111 | + Equivalent to invoking `-startSessionWithConfiguration:completion:` |
| 112 | + and providing a `nil` block. |
| 113 | + |
| 114 | + @param config The `SCSChatConfiguration` object which represents the session configuration. |
| 115 | + |
| 116 | + @see `-[SCSChatInterface showChatWithConfiguration:]` |
| 117 | + @see `-startSessionWithConfiguration:completion:` |
| 118 | + */ |
| 119 | +- (void)startSessionWithConfiguration:(SCSChatConfiguration *)config; |
| 120 | + |
| 121 | +/** |
| 122 | + Starts a chat session. |
| 123 | + Use this method if you intend to display your own UI. If you want to |
| 124 | + start a session with the default Snap-ins UI, see `-[SCSChatInterface showChatWithConfiguration:]`. |
| 125 | +
|
| 126 | + @note Calling `-stopSession` at any point after calling |
| 127 | + `-startSessionWithConfiguration:` will not necessarily terminate a session in |
| 128 | + progress. Once the user has moved past the pre-chat phase, this will trigger a |
| 129 | + prompt asking the user if they wish to terminate the session. |
| 130 | +
|
| 131 | + @param config The `SCSChatConfiguration` object that represents the session |
| 132 | + configuration. |
| 133 | + @param block Completion block which will be executed when the session has |
| 134 | + been fully connected to all services. When the block is executed |
| 135 | + the session is active and waiting for an agent to join. |
| 136 | + The `NSError` returned in the block is `nil` on success. |
| 137 | + |
| 138 | + @see `-[SCSChatInterface showChatWithConfiguration:]` |
| 139 | + */ |
| 140 | +- (void)startSessionWithConfiguration:(SCSChatConfiguration *)config completion:(SCSChatCompletionHandler)block; |
| 141 | + |
| 142 | +/** |
| 143 | + Stops an active or connecting session. |
| 144 | + |
| 145 | + If the user has not moved past the pre-chat phase, this will immediately |
| 146 | + terminate the session and clean up all resources. |
| 147 | + |
| 148 | + Equivalent to invoking `-stopSessionWithCompletion:` and providing a `nil` block. |
| 149 | +
|
| 150 | + @see `-stopSessionWithCompletion:` |
| 151 | + */ |
| 152 | +- (void)stopSession; |
| 153 | + |
| 154 | +/** |
| 155 | + Stops an active or connecting session. |
| 156 | +
|
| 157 | + If the user has not moved past the pre-chat phase this will immediately |
| 158 | + terminate the session and clean up all resources. |
| 159 | +
|
| 160 | + @param block Completion block which will be executed when the session has |
| 161 | + fully stopped, and all connected services have been torn down. |
| 162 | + The `NSError` returned in the block will be `nil` on success. |
| 163 | + */ |
| 164 | +- (void)stopSessionWithCompletion:(SCSChatCompletionHandler)block; |
| 165 | + |
| 166 | +/** |
| 167 | + Queries Live Agent to determine agent availability to accept a chat session. |
| 168 | + |
| 169 | + @param config The `SCSChatConfiguration` object which represents the session configuration. |
| 170 | + @param block The completion block that executes when the availability response returns. |
| 171 | + */ |
| 172 | +- (void)determineAvailabilityWithConfiguration:(SCSChatConfiguration *)config completion:(SCSChatAvailabilityHandler)block; |
| 173 | + |
| 174 | +///--------------------------------- |
| 175 | +/// @name Delegate Management |
| 176 | +///--------------------------------- |
| 177 | + |
| 178 | +/** |
| 179 | + Adds an instance of an `id` implementing the `SCSChatSessionDelegate` protocol |
| 180 | + to the list of delegates to notify. |
| 181 | +
|
| 182 | + @param delegate `id` instance to add. |
| 183 | + */ |
| 184 | +- (void)addDelegate:(id<SCSChatSessionDelegate>)delegate NS_SWIFT_NAME( add(delegate:) ); |
| 185 | + |
| 186 | +/** |
| 187 | + Adds an instance of an `id` implementing the `SCSChatSessionDelegate` protocol |
| 188 | + to the list of delegates to notify. |
| 189 | +
|
| 190 | + @param delegate `id` instance to add. |
| 191 | + @param queue `dispatch_queue_t` you wish your events to be called back on. |
| 192 | + */ |
| 193 | +- (void)addDelegate:(id<SCSChatSessionDelegate>)delegate queue:(dispatch_queue_t)queue NS_SWIFT_NAME( add(delegate:queue:) ); |
| 194 | + |
| 195 | +/** |
| 196 | + Removes an instance of an `id` implementing the `SCSChatSessionDelegate` |
| 197 | + protocol from the list of delegates to notify. |
| 198 | +
|
| 199 | + @param delegate `id` instance to remove. |
| 200 | + */ |
| 201 | +- (void)removeDelegate:(id<SCSChatSessionDelegate>)delegate NS_SWIFT_NAME( remove(delegate:) ); |
| 202 | + |
| 203 | +/** |
| 204 | + Adds an instance of an `id` implementing the `SCSChatEventDelegate` protocol |
| 205 | + to the list of delegates to notify. |
| 206 | +
|
| 207 | + @param delegate `id` instance to add. |
| 208 | + */ |
| 209 | +- (void)addEventDelegate:(id<SCSChatEventDelegate>)delegate NS_SWIFT_NAME( addEvent(delegate:) ); |
| 210 | + |
| 211 | +/** |
| 212 | + Adds an instance of an `id` implementing the `SCSChatEventDelegate` protocol |
| 213 | + to the list of delegates to notify. |
| 214 | +
|
| 215 | + @param queue `dispatch_queue_t` you wish your events to be called back on. |
| 216 | + */ |
| 217 | +- (void)addEventDelegate:(id<SCSChatEventDelegate>)delegate queue:(dispatch_queue_t)queue NS_SWIFT_NAME( addEvent(delegate:queue:) ); |
| 218 | + |
| 219 | +/** |
| 220 | + Removes an instance of an `id` implementing the `SCSChatEventDelegate` |
| 221 | + protocol from the list of delegates to notify. |
| 222 | +
|
| 223 | + @param delegate `id` instance to remove. |
| 224 | + */ |
| 225 | +- (void)removeEventDelegate:(id<SCSChatEventDelegate>)delegate NS_SWIFT_NAME( removeEvent(delegate:) ); |
| 226 | + |
| 227 | +@end |
0 commit comments