-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Config} from "../utils/model"; | ||
import {method, urls} from "../utils/constant"; | ||
import {cozeTemplate} from "@/entrypoints/utils/template"; | ||
|
||
async function coze(config: Config, message: any) { | ||
// 构建请求头 | ||
let headers = new Headers(); | ||
headers.append('Content-Type', 'application/json'); | ||
headers.append('Authorization', `Bearer ${config.token[config.service]}`); | ||
|
||
// 判断是否使用代理 | ||
let url: string = config.proxy[config.service] ? config.proxy[config.service] : urls[config.service]; | ||
|
||
// 发起 fetch 请求 | ||
const resp = await fetch(url, { | ||
method: method.POST, | ||
headers: headers, | ||
body: cozeTemplate(config, message.origin) | ||
}); | ||
|
||
if (resp.ok) { | ||
let result = await resp.json(); | ||
if (result.code === 0 && result.msg === "success") { | ||
console.log(result.messages[0]) | ||
return result.messages[0].content; | ||
} else { | ||
throw new Error(`请求失败: ${result.msg}`); | ||
} | ||
} else { | ||
console.log(resp); | ||
throw new Error(`请求失败: ${resp.status} ${resp.statusText} body: ${await resp.text()}`); | ||
} | ||
} | ||
|
||
export default coze; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters