initializeForEvent($data); // 调用addon的createConversation方法 $response = $kefu_api->createConversation(); // 返回响应数据 return json_decode($response->getContent(), true); } catch (\Exception $e) { return [ 'code' => -1, 'message' => '创建会话失败:' . $e->getMessage(), 'data' => [] ]; } } /** * 处理智能客服获取历史消息事件 * @param array $data 事件数据 * @return array */ public function handleKefuGetHistory($data) { try { // 创建addon的KefuApi实例 $kefu_api = new KefuApi(); // 调用初始化方法设置属性 $kefu_api->initializeForEvent($data); // 调用addon的getHistory方法 $response = $kefu_api->getHistory(); // 返回响应数据 return json_decode($response->getContent(), true); } catch (\Exception $e) { return [ 'code' => -1, 'message' => '获取历史消息失败:' . $e->getMessage(), 'data' => [] ]; } } /** * 事件监听映射 * @return array */ public function subscribe() { return [ 'KefuChat' => 'handleKefuChat', 'KefuCreateConversation' => 'handleKefuCreateConversation', 'KefuGetHistory' => 'handleKefuGetHistory', ]; } }