如何通过Bale Bot发送照片信息?

时间:2018-06-19 04:43:10

标签: node.js bale-messenger

我想通过我的机器人发送PhotoMessage!但套接字重新连接,而不是记录错误!

let _pic = {
    fileId: '-8485942782244354814',
    accessHash: '1533910422',
    name: '9312002.jpg',
    fileSize: '62379',
    mimeType: 'image/jpeg',
    fileStorageVersion: 1,
    ext_width: 349,
    ext_height: 456,
    width: 349,
    height: 456,
    thumb: '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA4KCw0LCQ4NDA0QDw4RFiQXFhQUFiwgIRokNC43NjMuMjI6QVNGOj1OPjIySGJJTlZYXV5dOEVmbWVabFNbXVn/2wBDAQ8QEBYTFioXFypZOzI7WVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVlZWVn/wAARCABaAEQDASIAAhEBAxEB/8QAGwAAAgIDAQAAAAAAAAAAAAAAAAYBAgMEBQf/xAA2EAACAQMCBAIIBQMFAAAAAAABAgMABBESIQUxQVEGEyIyQmFxgZHRFCOhwfAHseEVJDNicv/EABgBAAMBAQAAAAAAAAAAAAAAAAABAgME/8QAHBEBAQACAwEBAAAAAAAAAAAAAAECEQMSMSFB/9oADAMBAAIRAxEAPwD0miiqSOI42dvVUEmgFnxd4m/0hRa2hVrtxkk7iMd/jXnFxf3d42bm6mlbfGtyarxC7kv+ITXEzZaVyxOeXYfDlVEg1sxO6LgbY+VOQLJcTW7qUdlPQqabvD/jC4tZkg4o5ltm2Ep3ZD7z1H60phItaAt8SQRj+cqgsgVxqJC4wO+38+tMPcEdZEV0YMrDIIOxFWpY8B37XnARFI2qS2cx+/TzH2+VM9SBRRRQBWK6j861miHtoV+orLUUB4RbwvNdpCAAzNp36U62nhG3kiHmzSasb6cCteDhLW3Gr+QxhmDa4yRgDVkmupY8Tu/P8ryo5ABqOkMpAzjO470rbfG2GMnoi8J2EY9MySH/ALHlS54i4IlkPNhJ8vIBHanS84g8UGqKAyvjOnNLtxPccTtpBIsTR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fileId, _pic.accessHash, _pic.name,
    _pic.size, 'image/jpeg', "title",
    _pic.width, _pic.height, _pic.thumb
);

global.bot.send(pMsg, responder.peer);
// responder.reply(pMsg);

2 个答案:

答案 0 :(得分:5)

这是因为您没有在fileSize中正确设置pMsg。尝试以下代码,经过测试:

const SDK = require("balebot");
const BaleBot = SDK.BaleBot;
const PhotoMessage=SDK.PhotoMessage;

let bot = new BaleBot('token');

let _pic = {
    fileId: '-8485942782244354814',
    accessHash: '1533910422',
    name: '9312002.jpg',
    fileSize: '62379',
    mimeType: 'image/jpeg',
    fileStorageVersion: 1,
    ext_width: 349,
    ext_height: 456,
    width: 349,
    height: 456,
    thumb:'thumbnail'
};
const pMsg = new PhotoMessage(
    _pic.fileId, _pic.accessHash, _pic.name,
    _pic.fileSize, 'image/jpeg', "title",
    _pic.width, _pic.height, _pic.thumb
);
bot.hears(["/start"], (message, responder) => {
    bot.send(pMsg, responder.peer).then((res) => {
        console.log(res)
    }).catch((err) => {
        console.log(err)
    });
});

答案 1 :(得分:0)

我发现了我的问题! 当您将文件上传到Bale服务器时,响应是accessHash和fileId的对象。 accessHash是一个数字,而必须是String! 我将accessHash转换为字符串,并且可以正常工作。

bot.UploadFile(buf, "photo").then(response => {
    response.accessHash = response.accessHash + "";
    response.size = buf.length;
    response.base64 = base64data;
    response.width = dimensions.width;
    response.height = dimensions.height;
    store.set(_pic.key, response);
    store.save();
    store.writeFile();
}).catch(err => {
    console.log(err);
});