即时交谈
即时交谈视图UI设置
KFChatViewController属性说明
| 属性名称 | 类型 | 说明 |
| rightButtonItem | UIBarButtonItem | 右侧的按钮 |
| isHideRightButton | BOOL | 是否隐藏右侧按钮,默认NO |
| isDisConnectWhenDelloc | BOOL | 当退出KFChatViewController时是否断开连接,默认为YES,如果设置为NO, 需在应用进入后台时调用KFChatManager的setUserOffline方法关闭与服务器的连接 |
| isShowAlertWhenNoAgent | BOOL | 当没有客服在线时是否弹出alertView,默认为YES 注:当设置为NO时,noAgentAlertShowTitle和noAgentAlertActionBlock将失效 |
| noAgentAlertShowTitle | NSString | 当没有客服在线时,弹出alertView显示的title,默认为"当前没有客服在线,请提交留言" |
| noAgentAlertActionBlock | Block | 当没有客服在线或取消排队留言时,弹出alertView,点击"确定"按钮的事件处理,默认跳转到反馈工单界面 |
| leaveMessageAlertShowTitle | NSString | 当在用户在排队时,弹出alertView显示的title,默认为"是否取消排队并留言" |
| ratingAlertTitle | NSString | 当客服请求进行满意度评价时的提示文字,默认:"感谢使用我们的服务,请为此次服务评价:" |
| ratingFinishSystemTitle | NSString | 当用户点击评价后的系统提示文字,默认:"感谢您的评价!" |
| connectingShowTitle | NSString | 正在连接服务器时nav导航栏显示的文字,默认为"正在连接..." |
| connectErrorShowTitle | NSString | 连接服务器失败时nav导航栏显示的文字,默认为"未连接" |
| queueUpShowTitle | NSString | 正在排队时nav导航栏显示的文字,默认为"排队中..." |
| noAgentShowTitle | NSString | 当分配客服失败时nav导航栏显示的文字,默认为"当前没有客服在线" |
| chatEndShowTitle | NSString | 当客服结束会话时nav导航栏显示的文字,默认为"会话已结束" |
KFBaseContentMessageViewCell属性说明
| 属性名称 | 类型 | 说明 |
| timeLabelTextColor | UIColor | systemLabel文字颜色 |
| timeLabelFont | UIFont | systemLabel字体大小 |
KFMessageImageViewCell属性说明
| 属性名称 | 类型 | 说明 |
| messageImageBtn | UIButton | 按钮图片 |
KFMessageTextViewCell属性说明
| 属性名称 | 类型 | 说明 |
| messageForLabelFont | UIFont | Label的字体 |
| messageForMeLabelColor | UIColor | 普通用户消息Label的颜色 |
| messageForMeLabelUrlColor | UIColor | 普通用户消息Label中链接的颜色 |
| messageForOtherLabelColor | UIColor | 客服消息Label的颜色 |
| messageForOtherLabelUrlColor | UIColor | 客服消息Label中链接的颜色 |
KFMessageVoiceViewCell属性说明
| 属性名称 | 类型 | 说明 |
| voiceForOtherButtonFont | UIFont | 客服语音button的字体 |
| voiceForButtonFont | UIFont | button的字体 |
| voiceForMeButtonColor | UIColor | 普通用户语音button的颜色 |
| voiceForOtherButtonColor | UIColor | 客服语音button的颜色 |
KFBaseSystemMessageViewCell属性说明
| 属性名称 | 类型 | 说明 |
| systemBackgroundColor | UIColor | systemLabel背景颜色 |
| systemLabelTextColor | UIColor | systemLabel文字颜色 |
| systemLabelFont | UIFont | systemLabel字体大小 |
即时交谈管理
KFChatManager.h
属性说明
| 属性名称 | 类型 | 说明 |
| timeout | NSTimeInterval | 请求超时时间,默认15秒 |
| currentAgent | KFAgent | 当前客服 |
| isConnectSuccess | BOOL | socket是否连接成功 |
| chatStatus | KFChatStatus | 当前对话状态 |
| customFields | NSArray | 用户自定义信息,需要在连接服务器之前定义(格式@[@{@"name":@"性别",@"value":@"男"},@{@"name":@"XXX",@"value":@"XXX"}]) |
代理说明(KFChatManagerDelegate)
接受聊天消息
- (void)chatManager:(KFChatManager *)chatManager receiveMessages:(NSArray *)chatMessages;
| 参数名称 | 类型 | 说明 |
| chatManager | KFChatManager | 聊天管理对象 |
| chatMessages | NSArray | 聊天消息数组 |
用户排队的当前位置
- (void)chatManager:(KFChatManager *)chatManager queueIndex:(NSInteger)queueIndex;
| 参数名称 | 类型 | 说明 |
| chatManager | KFChatManager | 聊天管理对象 |
| queueIndex | NSInteger | 当前排队位置 |
分配到客服/转接客服
- (void)chatManager:(KFChatManager *)chatManager currectAgent:(KFAgent *)agent;
| 参数名称 | 类型 | 说明 |
| chatManager | KFChatManager | 聊天管理对象 |
| agent | KFAgent | 客服,当客服为空时,说明会话已结束 |
客服发起满意度评价
- (void)chatManagerRating:(KFChatManager *)chatManager;
| 参数名称 | 类型 | 说明 |
| chatManager | KFChatManager | 聊天管理对象 |
录音振幅变化
-(void)chatManager:(KFChatManager *)chatManager recordingAmplitude:(double)amplitude;
| 参数名称 | 类型 | 说明 |
| chatManager | KFChatManager | 聊天管理对象 |
| amplitude | double | 录音振幅 |
录音完成的代理
- (void)chatManager:(KFChatManager *)chatManager
recordVoiceMessage:(KFMessage *)message
error:(KFError *)error;
| 参数名称 | 类型 | 说明 |
| chatManager | KFChatManager | 聊天管理对象 |
| message | KFMessage | 音频消息 |
| error | KFError | 错误信息,为nil表示为成功 |
方法说明
单例
+ (instancetype)sharedChatManager;
添加代理
- (void)addDelegate:(id<KFChatManagerDelegate>)delegate;
| 参数名称 | 类型 | 说明 |
| delegate | id<KFChatManagerDelegate> | |
删除代理
- (void)removeDelegate:(id<KFChatManagerDelegate>)delegate;
| 参数名称 | 类型 | 说明 |
| delegate | id<KFChatManagerDelegate> | |
删除所有代理
- (void)removeAllDelegates;
连接服务器
- (void)connectWithUser:(KFUser *)user completion:(void (^)(KFError *error))completion;
同步离线消息
- (void)syncMessageWithCompletion:(void (^)(KFError *error,NSArray *history))completion;
| 参数名称 | 类型 | 说明 |
| completion | Block | 成功或失败的回调 |
给机器人发送消息
- (void)sendAITextMessage:(KFMessage *)message completion:(void (^)(KFError *error,KFMessage *me_message,KFMessage *ai_message))completion;
| 参数名称 | 类型 | 说明 |
| message | KFMessage | 消息实体 |
| completion | Block | 成功或失败的回调,回调中有机器人返回的消息 |
获取机器人客服的信息
- (void)getAIAgentWithCompletion:(void (^)(KFError *error,KFAgent *agent))completion;
| 参数名称 | 类型 | 说明 |
| completion | Block | 成功或失败的回调 |
用户加入排队
- (void)queueUpWithCompletion:(void (^)(KFError *error,NSInteger queue_index))completion;
| 参数名称 | 类型 | 说明 |
| completion | Block | 成功或失败的回调 |
用户取消排队
- (void)queueCancelWithCompletion:(void (^)(KFError *error))completion;
| 参数名称 | 类型 | 说明 |
| completion | Block | 成功或失败的回调 |
发送消息
- (void)sendMessage:(KFMessage *)message completion:(void (^)(KFError *error,KFMessage *message))completion;
| 参数名称 | 类型 | 说明 |
| message | KFMessage | 消息实体 |
| completion | Block | 成功或失败的回调 |
注:
当处于排队期间:
1.允许发送一条消息,用于在排队结束,客服能看到并处理该用户的问题;
2.发送的消息不会存储到本地数据库,需开发者自行保存;
3.只能发送文本消息,否则会失败;
4.多次调用此接口,则客服在排队完成后只会接收最后一条消息.
状态通过chatStatus得到
重新发送消息
- (KFMessage *)resendMessage:(KFMessage *)message completion:(void (^)(KFError *error,KFMessage *message))completion;
| 参数名称 | 类型 | 说明 |
| message | KFMessage | 消息实体 |
| completion | Block | 成功或失败的回调 |
发送满意度
- (void)sendRating:(BOOL)rating completion:(void (^)(KFError *error))completion;
| 参数名称 | 类型 | 说明 |
| completion | Block | 成功或失败的回调 |
获取历史记录
- (void)getHistoryWithFrom_id:(NSString *)from_id
count:(int)count
completion:(void (^)(KFError *error,NSArray *history))completion;
| 参数名称 | 类型 | 说明 |
| from_id | NSString | 消息的id,从哪条消息开始 |
| count | int | 要获取的数量 |
| completion | Block | 成功或失败的回调 |
设置用户离线
- (void)setUserOffline;
注:KF5服务器回向推送url发送推送,建议在应用进入后台时调用
开始录制音频
-(void)startVoiceRecord;
注:需要在KFChatManagerDelegate中接受录音完成的消息
取消录制音频
-(void)cancleVoiveRecord;
停止录制音频
-(void)stopVoiceRecord;
注:需要在KFChatManagerDelegate中接受录音完成的消息
播放音频消息
- (void)playVoiceMessage:(KFMessage *)message completion:(void (^)(KFError *error))completion;
| 参数名称 | 类型 | 说明 |
| completion | Block | 成功或失败的回调 |
停止音频播放
-(void)stopVoicePlayingMessage;
获取音频时长
+ (double)voiceDurationWithMessage:(KFMessage *)message;
注:通过message获取音频时长,用户语音消息的显示
| 参数名称 | 类型 | 说明 |
| message | KFMessage | 音频消息 |
判断是否是正在播放的文件
- (BOOL)isPlayingWithVoiceMessage:(KFMessage *)voiceMessage;
| 参数名称 | 类型 | 说明 |
| message | KFMessage | 必须是语音消息 |
获取聊天消息未读数
- (void)getUnReadMessageCountWithCompletion:(void (^)(KFError *error,int unReadMessageCount))completion;