diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 4df5d7f31..8f65a6b18 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -30,6 +30,7 @@ use App\Models\WebSocketDialogMsgTranslate; use App\Models\WebSocketDialogSession; use App\Module\Table\OnlineData; use App\Module\ZincSearch\ZincSearchDialogMsg; +use App\Tasks\BotReceiveMsgTask; use Hhxsv5\LaravelS\Swoole\Task\Task; /** @@ -2441,6 +2442,33 @@ class DialogController extends AbstractController return Base::retSuccess("success", $data); } + /** + * @api {post} api/dialog/msg/webhookmsg2ai 48. 转换为AI对话 + * + * @apiDescription 需要token身份,将webhook消息转换为适合AI对话的格式消息,用于AI对话 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName msg__webhookmsg2ai + * + * @apiParam {String} msg 消息内容 + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function msg__webhookmsg2ai() + { + User::auth(); + // + $msg = Request::input('msg'); + try { + $res = BotReceiveMsgTask::convertMentionForAI($msg); + return Base::retSuccess("success", ['msg' => $res]); + } catch (\Exception $e) { + return Base::retError($e->getMessage()); + } + } + /** * @api {get} api/dialog/group/add 48. 新增群组 * diff --git a/app/Tasks/BotReceiveMsgTask.php b/app/Tasks/BotReceiveMsgTask.php index b5beff6a9..32ec8cd9f 100644 --- a/app/Tasks/BotReceiveMsgTask.php +++ b/app/Tasks/BotReceiveMsgTask.php @@ -505,8 +505,8 @@ class BotReceiveMsgTask extends AbstractTask } $this->generateSystemPromptForAI($msg->userid, $dialog, $extras); // 转换提及格式 - $sendText = $this->convertMentionForAI($sendText); - $replyText = $this->convertMentionForAI($replyText); + $sendText = self::convertMentionForAI($sendText); + $replyText = self::convertMentionForAI($replyText); if ($replyText) { $sendText = << @@ -698,7 +698,7 @@ class BotReceiveMsgTask extends AbstractTask * @return string 转换后的消息文本,包含相关内容的标签 * @throws Exception 当提及的对象不存在或读取失败时抛出异常 */ - private function convertMentionForAI($original) + public static function convertMentionForAI($original) { $array = []; $original = preg_replace_callback('//', function ($match) use (&$array) {