如何批量删除豆包的对话
豆包目前提供的删除只有单个删除,要批量删除只能靠自己
首先要找到豆包的删除接口
- 众所周知 删除要么是 delete 请求,要么是 delete 结尾的 post 请求
由此提炼出删除接口参数
const url = 'https://www.doubao.com/samantha/thread/delete';
const query = {
version_code: 20800,
language: zh,
device_platform: web,
aid: 497858,
real_aid: 497858,
pc_version: 2.13.2,
pkg_type: release_version,
device_id: 7480421835180705295,
web_id: 7480420898572813875,
tea_uuid: 7480420898572813875,
'use-olympus-account': 1,
region: CN,
sys_region: CN,
samantha_web: 1,
msToken: '*************************************************-******************************************************************************',
a_bogus: 'E6UDDc22Msm1Jirjdwkz9GJweVj0YW59gZEN7p8GJzqN',
}
const body = {
conversation_id: '2823097283697154'
}
接下来可以用浏览器自带的 fetch 测试删除
为了避免跨域问题,需要在豆包的控制台执行
fetch(
"https://www.doubao.com/samantha/thread/delete?version_code=20800&language=zh&device_platform=web&aid=497858&real_aid=497858&pc_version=2.13.2&pkg_type=release_version&device_id=7480421835180705295&web_id=7480420898572813875&tea_uuid=7480420898572813875&use-olympus-account=1®ion=CN&sys_region=CN&samantha_web=1&msToken=*************************************************-******************************************************************************&a_bogus=E6UDDc22Msm1Jirjdwkz9GJweVj0YW59gZEN7p8GJzqN",
{
method: "POST",
body: JSON.stringify({ conversation_id: `2823097283697154` }),
headers: {
"Content-Type": "application/json; charset=utf-8",
},
}
);
执行成功
批量查找 id
query 中的参数是身份信息,不变就行
- 通过 dom 可以看出
id
是放在对话列表中,并且内容中都有data-testid="chat_list_thread_item"
- 我们可通过
document.querySelectorAll
找到列表中的 id
document.querySelectorAll('[data-testid="chat_list_thread_item"]').forEach((e) => {
const id = e.id.split("_")[1];
});
- 调用删除接口
注意传输的 id 需要是字符串格式不然会报错
document.querySelectorAll('[data-testid="chat_list_thread_item"]').forEach((e) => {
const id = e.id.split("_")[1];
fetch(
"https://www.doubao.com/samantha/thread/delete?version_code=20800&language=zh&device_platform=web&aid=497858&real_aid=497858&pc_version=2.13.2&pkg_type=release_version&device_id=7480421835180705295&web_id=7480420898572813875&tea_uuid=7480420898572813875&use-olympus-account=1®ion=CN&sys_region=CN&samantha_web=1&msToken=*************************************************-******************************************************************************&a_bogus=E6UDDc22Msm1Jirjdwkz9GJweVj0YW59gZEN7p8GJzqN",
{
method: "POST",
body: JSON.stringify({ conversation_id: `${id}` }),
headers: {
"Content-Type": "application/json; charset=utf-8",
},
}
);
});