import { sendQQFile, sendQQImageToUser, sendQQImageToGroup } from "./index.js";
/**
* QQ Bot 文件发送示例
*
* 使用前请确保:
* 1. QQ Bot已配置并连接
* 2. 已安装qqbot扩展
* 3. 知道目标用户或群组的OpenID
*/
// ==================== 示例1:发送本地图片到私聊 ====================
async function example1() {
try {
const result = await sendQQFile({
targetId: "33558EFB7CF362DA4A894FBE2E93DFDE", // 替换为实际用户OpenID
targetType: "c2c",
fileType: "image",
filePath: "/path/to/your/image.jpg",
content: "这是发送给您的图片",
});
console.log("发送成功:", result);
} catch (error) {
console.error("发送失败:", error);
}
}
// ==================== 示例2:发送网络图片到群聊 ====================
async function example2() {
try {
const result = await sendQQFile({
targetId: "YOUR_GROUP_OPENID", // 替换为实际群组OpenID
targetType: "group",
fileType: "image",
fileUrl: "https://example.com/image.png",
content: "大家看看这个图片",
});
console.log("发送成功:", result);
} catch (error) {
console.error("发送失败:", error);
}
}
// ==================== 示例3:使用便捷函数发送图片 ====================
async function example3() {
try {
// 发送到私聊
await sendQQImageToUser(
"33558EFB7CF362DA4A894FBE2E93DFDE",
"/path/to/local/image.jpg",
"这是图片说明"
);
// 发送到群聊
await sendQQImageToGroup(
"YOUR_GROUP_OPENID",
"https://example.com/photo.jpg",
"分享一张照片"
);
console.log("所有消息发送成功");
} catch (error) {
console.error("发送失败:", error);
}
}
// ==================== 示例4:发送视频文件 ====================
async function example4() {
try {
const result = await sendQQFile({
targetId: "33558EFB7CF362DA4A894FBE2E93DFDE",
targetType: "c2c",
fileType: "video",
filePath: "/path/to/video.mp4",
content: "分享一个有趣的视频",
});
console.log("视频发送成功:", result);
} catch (error) {
console.error("视频发送失败:", error);
}
}
// ==================== 示例5:获取用户信息 ====================
import { checkFileExists, getFileSize, formatFileSize } from "./index.js";
function example5() {
const filePath = "/path/to/file.jpg";
if (checkFileExists(filePath)) {
const size = getFileSize(filePath);
if (size !== null) {
console.log(`文件存在,大小: ${formatFileSize(size)}`);
}
} else {
console.log("文件不存在");
}
}
// ==================== 运行示例 ====================
// 取消注释来运行示例
// example1();
// example2();
// example3();
// example4();
// example5();
export {
example1,
example2,
example3,
example4,
example5,
};