ai_scheduler/internal/data/constants/dingtalk.go

166 lines
4.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package constants
import (
"net/url"
"strings"
"github.com/google/uuid"
)
const DingTalkBseUrl = "https://oapi.dingtalk.com"
type RequestUrl string
const (
RequestUrlGetUserGet RequestUrl = "/topapi/v2/user/get"
RequestUrlGetDeptGet RequestUrl = "/topapi/v2/department/get"
)
func GetDingTalkRequestUrl(path RequestUrl, query map[string]string) string {
u, _ := url.Parse(DingTalkBseUrl + string(path))
q := u.Query()
for key, val := range query {
q.Add(key, val)
}
u.RawQuery = q.Encode()
return u.String()
}
// IsBoss 是否是老板
type IsBoss int
const (
IsBossTrue IsBoss = 1
IsBossFalse IsBoss = 0
)
// IsSenior 是否是老板
type IsSenior int
const (
IsSeniorTrue IsSenior = 1
IsSeniorFalse IsSenior = 0
)
type ConversationType string
const (
ConversationTypeSingle = "1" // 单聊
ConversationTypeGroup = "2" //群聊
)
type BotMsgType string
const (
BotMsgTypeText BotMsgType = "text"
)
type CardTemp string
const (
CardTempDefault CardTemp = `{
"config": {
"autoLayout": true,
"enableForward": true
},
"header": {
"title": {
"type": "text",
"text": "${title}",
},
"logo": "@lALPDfJ6V_FPDmvNAfTNAfQ"
},
"contents": [
{
"type": "divider",
"id": "divider_1765952728523"
},
{
"type": "markdown",
"text": "%s",
"id": "markdown_1765970168635"
}
]
}`
)
// 交互卡片回调
const (
// 回调类型
CardActionCallbackTypeAction string = "actionCallback" // 交互卡片回调事件类型
// 回调事件类型
CardActionTypeCreateGroup string = "create_group" // 创建群聊
)
// dingtalk 卡片 OutTrackId 模板
const CardOutTrackIdTemplate string = "{space_id}:{bot_id}:{uuid}"
func BuildCardOutTrackId(spaceId string, botId string) (outTrackId string) {
uuid := uuid.New().String()
outTrackId = strings.ReplaceAll(CardOutTrackIdTemplate, "{space_id}", spaceId)
outTrackId = strings.ReplaceAll(outTrackId, "{bot_id}", botId)
outTrackId = strings.ReplaceAll(outTrackId, "{uuid}", uuid)
return
}
func ParseCardOutTrackId(outTrackId string) (spaceId string, botId string) {
parts := strings.Split(outTrackId, ":")
if len(parts) != 3 {
return
}
spaceId, botId, _ = parts[0], parts[1], parts[2]
return
}
// 问题处理群机器人 - LLM 提示词
const IssueHandlingExtractContentPrompt string = `你是一个【问题与答案生成助手】。
你的职责是:
- 分析用户输入的内容
- 识别其中隐含或明确的问题
- 基于输入内容本身,生成对应的问题与答案
当用户输入为【多条群聊聊天记录】时:
- 结合问题主题,判断聊天记录中正在讨论或试图解决的问题
- 一个群聊中可能包含多个相互独立的问题,但它们都围绕着一个主题,一般为用户提出的第一个问题,尽可能总结为一个问题
- 若确实问题很独立,需要分别识别,对每个问题,整理出清晰、可复用的“问题描述”和“对应答案”
生成答案时的原则:
- 答案必须来源于聊天内容中已经给出的信息或共识
- 不要引入外部知识,不要使用聊天记录中真实人名或敏感信息,适当总结
- 若聊天中未形成明确答案,应明确标记为“暂无明确结论”
- 若存在多种不同观点,应分别列出,不要擅自合并或裁决
【JSON 输出原则】:
- 你的最终输出必须是**合法的 JSON**
- 不得输出任何额外解释性文字
- JSON 结构必须严格符合以下约定
JSON 结构约定:
{
"items": [
{
"question": "清晰、独立、可复用的问题描述",
"answer": "基于聊天内容整理出的答案;如无结论则为“暂无明确结论”",
"confidence": "high | medium | low"
}
]
}
字段说明:
- items问题与答案列表若未识别到有效问题则返回空数组 []
- question抽象后的标准问题表述不包含具体聊天语句
- answer整理后的答案不得引入聊天之外的信息
- confidence根据聊天中信息的一致性和明确程度给出判断
如果无法从输入中识别出任何有效问题,返回:
{ "items": [] }
用户输入:
%s
`