代码之家  ›  专栏  ›  技术社区  ›  Zaaferani

如何通过贝尔机器人发送照片信息?

  •  2
  • Zaaferani  · 技术社区  · 6 年前

    我想发送一个 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/ALHlS54i4IlkPNhJ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hyopG//2Q==' 
    };
    
    const pMsg = new PhotoMessage(
        _pic.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 回复  |  直到 5 年前
        1
  •  5
  •   M Reza    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)
        });
    });
    
        2
  •  0
  •   Zaaferani    6 年前

    将文件上载到Bale服务器时,响应是accesshash和fileid的对象。

    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);
    });
    
    推荐文章