no message

This commit is contained in:
kuaifan 2025-07-29 16:58:33 +08:00
parent f5847a57c1
commit c26f73a5a8
2 changed files with 31 additions and 3 deletions

View File

@ -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. 新增群组
*

View File

@ -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 = <<<EOF
<quoted_content>
@ -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) {