diff --git a/app/Http/Controllers/Api/ApproveController.php b/app/Http/Controllers/Api/ApproveController.php index 0eb5c0630..6fd60b31e 100755 --- a/app/Http/Controllers/Api/ApproveController.php +++ b/app/Http/Controllers/Api/ApproveController.php @@ -992,7 +992,7 @@ class ApproveController extends AbstractController 'is_finished' => $process['is_finished'], 'data' => $data ]; - $msgData['desc'] = match ($type) { + $msgData['title'] = match ($type) { 'approve_reviewer' => '待你审批', 'approve_notifier' => '审批通知', 'approve_comment_notifier' => '审批评论通知', diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index 731a24609..7dba36040 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -1092,7 +1092,7 @@ class FileController extends AbstractController // WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [ 'type' => 'file_download', - 'desc' => '文件下载打包已完成', + 'title' => '文件下载打包已完成', 'name' => $fileName, 'size' => filesize($zipPath), 'url' => $fileUrl, diff --git a/app/Models/ProjectTask.php b/app/Models/ProjectTask.php index adfa32392..54ae933e9 100644 --- a/app/Models/ProjectTask.php +++ b/app/Models/ProjectTask.php @@ -1688,12 +1688,11 @@ class ProjectTask extends AbstractModel } $dataId = $this->parent_id ?: $this->id; - $taskHtml = "#{$this->name}"; $text = match ($type) { - 1 => "您的任务 {$taskHtml} 即将超时。", - 2 => "您的任务 {$taskHtml} 已经超时。", - 3 => "您的任务 {$taskHtml} 时间已修改。", - default => "您有一个新任务 {$taskHtml}。", + 1 => "(*)即将超时", + 2 => "(*)已经超时", + 3 => "(*)时间已修改", + default => "您有一个新任务", }; /** @var User $user */ @@ -1711,8 +1710,15 @@ class ProjectTask extends AbstractModel $dialog = WebSocketDialog::checkUserDialog($botUser, $receiver->userid); if ($dialog) { ProjectTaskPushLog::createInstance($data)->save(); - WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', [ - 'text' => str_replace("您的任务", $replace, $text) . $suffix + WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [ + 'type' => 'task_list', + 'title' => str_replace("(*)", $replace, $text) . $suffix, + 'list' => [ + [ + 'id' => $dataId, + 'name' => $this->name, + ] + ], ], in_array($type, [0, 3]) ? $userid : $botUser->userid); } } @@ -1720,11 +1726,12 @@ class ProjectTask extends AbstractModel /** * 移动任务 - * @param int $project_id - * @param int $column_id + * @param int $projectId + * @param int $columnId * @param int $flowItemId * @param array $owner * @param array $assist + * @param string $completeAt * @return bool */ public function moveTask(int $projectId, int $columnId,int $flowItemId = 0,array $owner = [], array $assist = [], string $completeAt='') diff --git a/app/Models/UserBot.php b/app/Models/UserBot.php index b0e1eaefb..2da645a66 100644 --- a/app/Models/UserBot.php +++ b/app/Models/UserBot.php @@ -250,11 +250,14 @@ class UserBot extends AbstractModel }; $sendMsg = function($type, $checkin) use ($alreadyTip, $getJokeSoup, $botUser, $nowDate) { $cacheKey = "Checkin::sendMsg-{$nowDate}-{$type}:" . $checkin['userid']; - $typeDesc = $type == "up" ? "上班" : "下班"; + $typeContent = $type == "up" ? "上班" : "下班"; if (Cache::get($cacheKey) === "yes") { if ($alreadyTip && $dialog = WebSocketDialog::checkUserDialog($botUser, $checkin['userid'])) { - $text = "
" . Doo::translate("今日已{$typeDesc}打卡,无需重复打卡。") . "
"; - WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $text], $botUser->userid, false, false, $type != "up"); + $text = "今日已{$typeContent}打卡,无需重复打卡。"; + WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [ + 'type' => 'content', + 'content' => $text, + ], $botUser->userid, false, false, $type != "up"); } return; } @@ -263,12 +266,19 @@ class UserBot extends AbstractModel if ($dialog = WebSocketDialog::checkUserDialog($botUser, $checkin['userid'])) { $hi = date("H:i"); $remark = $checkin['remark'] ? " ({$checkin['remark']})": ""; - $text = "{$typeDesc}" . Doo::translate("打卡成功,打卡时间") . ": {$hi}{$remark}
"; - $suff = $getJokeSoup($type); - if ($suff) { - $text = "{$text}----------
{$suff}
"; - } - WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $text], $botUser->userid, false, false, $type != "up"); + $subcontent = $getJokeSoup($type); + WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [ + 'type' => 'content', + 'content' => [ + [ + 'content' => "{$typeContent}打卡成功,打卡时间: {$hi}{$remark}" + ], [ + 'content' => $subcontent, + 'language' => false, + 'style' => 'padding-top:4px;opacity:0.4', + ] + ], + ], $botUser->userid, false, false, $type != "up"); } }; if ($timeAdvance <= Base::time() && Base::time() < $timeEnd) { diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index 2f574b6ef..a087e3554 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -591,7 +591,7 @@ class WebSocketDialogMsg extends AbstractModel return $data['msg']['notice']; case 'template': - return Doo::translate($data['msg']['desc'] ?: '未知消息类型'); + return $this->previewTemplateMsg($data['msg']); default: $action = Doo::translate("未知的消息"); @@ -617,6 +617,26 @@ class WebSocketDialogMsg extends AbstractModel return "[{$action}] {$msg['name']}"; } + /** + * 预览模板消息 + * @param $msg + * @return string + */ + private function previewTemplateMsg($msg) + { + if (!empty($msg['title_raw'])) { + return $msg['title_raw']; + } + if (!empty($msg['title'])) { + return Doo::translate($msg['title']); + } + if ($msg['type'] === 'content' && is_string($msg['content']) && $msg['content'] !== '') { + return Doo::translate($msg['content']); + } + return Doo::translate('未知的消息'); + + } + /** * 生成关键词 * @return string diff --git a/app/Tasks/BotReceiveMsgTask.php b/app/Tasks/BotReceiveMsgTask.php index ad92ee1c1..2ebb3ec2d 100644 --- a/app/Tasks/BotReceiveMsgTask.php +++ b/app/Tasks/BotReceiveMsgTask.php @@ -96,8 +96,8 @@ class BotReceiveMsgTask extends AbstractTask $text = UserBot::checkinBotQuickMsg($command, $msg->userid); if ($text) { WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'template', [ - 'type' => 'desc', - 'desc' => $text, + 'type' => 'content', + 'content' => $text, ], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务 } } @@ -106,8 +106,8 @@ class BotReceiveMsgTask extends AbstractTask $text = UserBot::anonBotQuickMsg($command); if ($text) { WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'template', [ - 'type' => 'desc', - 'desc' => $text, + 'type' => 'content', + 'content' => $text, ], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务 } } @@ -120,8 +120,8 @@ class BotReceiveMsgTask extends AbstractTask } else { $text = "非常抱歉,我不是你的机器人,无法完成你的指令。"; WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'template', [ - 'type' => 'desc', - 'desc' => $text, + 'type' => 'content', + 'content' => $text, ], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务 return; } @@ -129,7 +129,7 @@ class BotReceiveMsgTask extends AbstractTask $array = Base::newTrim(explode(" ", "{$command} ")); $type = $array[0]; $data = []; - $desc = ""; + $content = ""; if (!$isManager && in_array($type, ['/list', '/newbot'])) { return; // 这些操作仅支持【机器人管理】机器人 } @@ -152,7 +152,7 @@ class BotReceiveMsgTask extends AbstractTask ->orderByDesc('id') ->get(); if ($data->isEmpty()) { - $desc = "您没有创建机器人。"; + $content = "您没有创建机器人。"; } break; @@ -164,7 +164,7 @@ class BotReceiveMsgTask extends AbstractTask $botId = $isManager ? $array[1] : $botUser->userid; $data = $this->botManagerOne($botId, $msg->userid); if (!$data) { - $desc = "机器人不存在。"; + $content = "机器人不存在。"; } break; @@ -177,25 +177,25 @@ class BotReceiveMsgTask extends AbstractTask ->where('users.bot', 1) ->where('user_bots.userid', $msg->userid) ->count() >= 50) { - $desc = "超过最大创建数量。"; + $content = "超过最大创建数量。"; break; } if (strlen($array[1]) < 2 || strlen($array[1]) > 20) { - $desc = "机器人名称由2-20个字符组成。"; + $content = "机器人名称由2-20个字符组成。"; break; } $data = User::botGetOrCreate("user-" . Base::generatePassword(), [ 'nickname' => $array[1] ], $msg->userid); if (empty($data)) { - $desc = "创建失败。"; + $content = "创建失败。"; break; } $dialog = WebSocketDialog::checkUserDialog($data, $msg->userid); if ($dialog) { WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [ 'type' => '/hello', - 'desc' => '创建成功。', + 'title' => '创建成功。', 'data' => $data, ], $data->userid); // todo 未能在任务end事件来发送任务 } @@ -208,7 +208,7 @@ class BotReceiveMsgTask extends AbstractTask $botId = $isManager ? $array[1] : $botUser->userid; $nameString = $isManager ? $array[2] : $array[1]; if (strlen($nameString) < 2 || strlen($nameString) > 20) { - $desc = "机器人名称由2-20个字符组成。"; + $content = "机器人名称由2-20个字符组成。"; break; } $data = $this->botManagerOne($botId, $msg->userid); @@ -218,7 +218,7 @@ class BotReceiveMsgTask extends AbstractTask $data->pinyin = Base::cn2pinyin($nameString); $data->save(); } else { - $desc = "机器人不存在。"; + $content = "机器人不存在。"; } break; @@ -232,7 +232,7 @@ class BotReceiveMsgTask extends AbstractTask if ($data) { $data->deleteUser('delete bot'); } else { - $desc = "机器人不存在。"; + $content = "机器人不存在。"; } break; @@ -245,7 +245,7 @@ class BotReceiveMsgTask extends AbstractTask if ($data) { User::generateToken($data); } else { - $desc = "机器人不存在。"; + $content = "机器人不存在。"; } break; @@ -260,7 +260,7 @@ class BotReceiveMsgTask extends AbstractTask $data->password = Doo::md5s(Base::generatePassword(32), $data->encrypt); $data->save(); } else { - $desc = "机器人不存在。"; + $content = "机器人不存在。"; } break; @@ -281,7 +281,7 @@ class BotReceiveMsgTask extends AbstractTask $data->clear_day = $userBot->clear_day; $data->clear_at = $userBot->clear_at; // 这两个参数只是作为输出,所以不保存 } else { - $desc = "机器人不存在。"; + $content = "机器人不存在。"; } break; @@ -293,7 +293,7 @@ class BotReceiveMsgTask extends AbstractTask $webhookUrl = $isManager ? $array[2] : $array[1]; $data = $this->botManagerOne($botId, $msg->userid); if (strlen($webhookUrl) > 255) { - $desc = "webhook地址最长仅支持255个字符。"; + $content = "webhook地址最长仅支持255个字符。"; } elseif ($data) { $userBot = UserBot::whereBotId($botId)->whereUserid($msg->userid)->first(); if ($userBot) { @@ -304,7 +304,7 @@ class BotReceiveMsgTask extends AbstractTask $data->webhook_url = $userBot->webhook_url ?: '-'; $data->webhook_num = $userBot->webhook_num; // 这两个参数只是作为输出,所以不保存 } else { - $desc = "机器人不存在。"; + $content = "机器人不存在。"; } break; @@ -325,7 +325,7 @@ class BotReceiveMsgTask extends AbstractTask ->take(20) ->get(); if ($list->isEmpty()) { - $desc = "没有搜索到相关会话。"; + $content = "没有搜索到相关会话。"; } else { $list->transform(function (WebSocketDialog $item) use ($data) { return $item->formatData($data->userid); @@ -333,23 +333,23 @@ class BotReceiveMsgTask extends AbstractTask $data->list = $list; // 这个参数只是作为输出,所以不保存 } } else { - $desc = "机器人不存在。"; + $content = "机器人不存在。"; } break; } // - if ($desc) { + if ($content) { $msgData = [ - 'type' => 'desc', - 'desc' => $desc, + 'type' => 'content', + 'content' => $content, ]; } else { $msgData = [ 'type' => $type, 'data' => $data, ]; - $msgData['desc'] = match ($type) { + $msgData['title'] = match ($type) { '/hello' => '您好', '/help' => '帮助指令', '/list' => '我的机器人', @@ -388,7 +388,7 @@ class BotReceiveMsgTask extends AbstractTask $serverUrl = 'http://' . env('APP_IPPR') . '.3'; $userBot = null; $extras = []; - $errorDesc = null; + $errorContent = null; switch ($botUser->email) { // ChatGPT 机器人 case 'ai-openai@bot.system': @@ -402,10 +402,10 @@ class BotReceiveMsgTask extends AbstractTask 'chunk_size' => 7, ]; if (empty($extras['openai_key'])) { - $errorDesc = '机器人未启用。'; + $errorContent = '机器人未启用。'; } elseif (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.29.11", $this->client['version'])) { - $errorDesc = '当前客户端版本低(所需版本≥v0.29.11)。'; + $errorContent = '当前客户端版本低(所需版本≥v0.29.11)。'; } break; // Claude 机器人 @@ -418,10 +418,10 @@ class BotReceiveMsgTask extends AbstractTask 'server_url' => $serverUrl, ]; if (empty($extras['claude_token'])) { - $errorDesc = '机器人未启用。'; + $errorContent = '机器人未启用。'; } elseif (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.29.11", $this->client['version'])) { - $errorDesc = '当前客户端版本低(所需版本≥v0.29.11)。'; + $errorContent = '当前客户端版本低(所需版本≥v0.29.11)。'; } break; // Wenxin 机器人 @@ -435,10 +435,10 @@ class BotReceiveMsgTask extends AbstractTask 'server_url' => $serverUrl, ]; if (empty($extras['wenxin_key'])) { - $errorDesc = '机器人未启用。'; + $errorContent = '机器人未启用。'; } elseif (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.29.11", $this->client['version'])) { - $errorDesc = '当前客户端版本低(所需版本≥v0.29.12)。'; + $errorContent = '当前客户端版本低(所需版本≥v0.29.12)。'; } break; // QianWen 机器人 @@ -451,10 +451,10 @@ class BotReceiveMsgTask extends AbstractTask 'server_url' => $serverUrl, ]; if (empty($extras['qianwen_key'])) { - $errorDesc = '机器人未启用。'; + $errorContent = '机器人未启用。'; } elseif (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.29.11", $this->client['version'])) { - $errorDesc = '当前客户端版本低(所需版本≥v0.29.12)。'; + $errorContent = '当前客户端版本低(所需版本≥v0.29.12)。'; } break; // Gemini 机器人 @@ -469,10 +469,10 @@ class BotReceiveMsgTask extends AbstractTask 'server_url' => $serverUrl, ]; if (empty($extras['gemini_key'])) { - $errorDesc = '机器人未启用。'; + $errorContent = '机器人未启用。'; } elseif (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.29.11", $this->client['version'])) { - $errorDesc = '当前客户端版本低(所需版本≥v0.29.12)。'; + $errorContent = '当前客户端版本低(所需版本≥v0.29.12)。'; } break; // 智谱清言 机器人 @@ -485,10 +485,10 @@ class BotReceiveMsgTask extends AbstractTask 'server_url' => $serverUrl, ]; if (empty($extras['zhipu_key'])) { - $errorDesc = '机器人未启用。'; + $errorContent = '机器人未启用。'; } elseif (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.29.11", $this->client['version'])) { - $errorDesc = '当前客户端版本低(所需版本≥v0.29.12)。'; + $errorContent = '当前客户端版本低(所需版本≥v0.29.12)。'; } break; // 其他机器人 @@ -497,10 +497,10 @@ class BotReceiveMsgTask extends AbstractTask $webhookUrl = $userBot?->webhook_url; break; } - if ($errorDesc) { + if ($errorContent) { WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'template', [ - 'type' => 'desc', - 'desc' => $errorDesc, + 'type' => 'content', + 'content' => $errorContent, ], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务 return; } diff --git a/app/Tasks/CheckinRemindTask.php b/app/Tasks/CheckinRemindTask.php index 95f8a43cf..0090ab718 100644 --- a/app/Tasks/CheckinRemindTask.php +++ b/app/Tasks/CheckinRemindTask.php @@ -84,11 +84,28 @@ class CheckinRemindTask extends AbstractTask $dialog = WebSocketDialog::checkUserDialog($botUser, $user->userid); if ($dialog) { if ($type === 'exceed') { - $text = "" . Doo::translate("缺卡提醒") . ":" . Doo::translate("上班时间到了,你还没有打卡哦~") . "
"; + $title = '缺卡提醒'; + $style = 'color:#f55;'; + $content = '上班时间到了,你还没有打卡哦~'; } else { - $text = "" . Doo::translate("打卡提醒") . ":" . Doo::translate("快到上班时间了,别忘了打卡哦~") . "
"; + $title = '打卡提醒'; + $style = ''; + $content = '快到上班时间了,别忘了打卡哦~'; } - WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $text], $botUser->userid); + WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [ + 'type' => 'content', + 'title' => $title, + 'content' => [ + [ + 'content' => $title, + 'style' => $style . 'font-weight:bold', + ], + [ + 'content' => $content, + 'style' => 'padding-top:4px;opacity:0.4', + ], + ], + ], $botUser->userid); } } }); diff --git a/app/Tasks/UnclaimedTaskRemindTask.php b/app/Tasks/UnclaimedTaskRemindTask.php index 3c8d7088f..846a9626c 100644 --- a/app/Tasks/UnclaimedTaskRemindTask.php +++ b/app/Tasks/UnclaimedTaskRemindTask.php @@ -6,7 +6,6 @@ use App\Models\User; use App\Module\Base; use App\Models\Project; use App\Models\ProjectTask; -use App\Models\ProjectUser; use Carbon\Carbon; use App\Models\WebSocketDialogMsg; use Illuminate\Support\Facades\Cache; @@ -64,8 +63,8 @@ class UnclaimedTaskRemindTask extends AbstractTask return; } WebSocketDialogMsg::sendMsg(null, $project->dialog_id, 'template', [ - 'type' => 'task_unclaimed', - 'desc' => '任务待领取', + 'type' => 'task_list', + 'title' => '任务待领取', 'list' => $projectTasks->map(function ($item) { return [ 'id' => $item->id, diff --git a/resources/assets/js/functions/web.js b/resources/assets/js/functions/web.js index ac1e9345e..b144614bb 100755 --- a/resources/assets/js/functions/web.js +++ b/resources/assets/js/functions/web.js @@ -411,7 +411,7 @@ import {MarkdownPreview} from "../store/markdown"; case 'notice': return data.msg.notice case 'template': - return $A.L(data.msg.desc || '未知消息类型') + return $A.templateMsgSimpleDesc(data.msg) default: return `[${$A.L('未知的消息')}]` } @@ -440,6 +440,24 @@ import {MarkdownPreview} from "../store/markdown"; return `[${$A.L('文件')}] ${msg.name}` }, + /** + * 模板消息简单描述 + * @param msg + * @returns {string|*} + */ + templateMsgSimpleDesc(msg) { + if (msg.title_raw) { + return msg.title_raw + } + if (msg.title) { + return $A.L(msg.title) + } + if (msg.type === 'content' && typeof msg.content === 'string' && msg.content !== '') { + return $A.L(msg.content) + } + return $A.L('未知的消息') + }, + /** * 获取文件标题 * @param file diff --git a/resources/assets/js/pages/manage/components/DialogView/template/content.vue b/resources/assets/js/pages/manage/components/DialogView/template/content.vue new file mode 100644 index 000000000..c324ebba6 --- /dev/null +++ b/resources/assets/js/pages/manage/components/DialogView/template/content.vue @@ -0,0 +1,39 @@ + +{{ item.content }}
+{{$L("任务待领取")}}
+{{$L(msg.desc)}}
diff --git a/resources/assets/js/pages/manage/components/DialogView/unknown.vue b/resources/assets/js/pages/manage/components/DialogView/unknown.vue
index b3c29ae10..6ebc46baf 100644
--- a/resources/assets/js/pages/manage/components/DialogView/unknown.vue
+++ b/resources/assets/js/pages/manage/components/DialogView/unknown.vue
@@ -1,5 +1,5 @@
-