Giter Site home page Giter Site logo

Comments (6)

abbasaryanpour avatar abbasaryanpour commented on August 23, 2024 1

بنده هم دقیقا همین مشکل رو در ارسال فایل دارم

`FileUploadLinkResponse {
_id: '2',
_body:
{ fileId: '2857076566730342913',
url: 'https://fileserver-002-c002.bale.ai/774094140/2857076566730342913',
dup: false,
userId: 774094140 },
_fileId: '2857076566730342913',
_url: 'https://fileserver-002-c002.bale.ai/774094140/2857076566730342913',
_dup: false,
_userId: 774094140 }
{ connection: 'close', crc32: '2537338385' }

err upload>>`

from bale-bot-samples.

masoodbayati avatar masoodbayati commented on August 23, 2024

این مشکل زمانی به وجود می آید که قصد چک کردن
crc32
را داریم.
برای حل سریع مشکل بهتر است که این چک را انجام ندهید و کد چک
crc32
را از کد کتابخانه حذف کنید
در ورژن بعدی کتابخانه حتما این مورد حل خواهد شد

from bale-bot-samples.

ebarkhordar avatar ebarkhordar commented on August 23, 2024

این مشکل در نسخه 2.0.3 مرتفع گردید

from bale-bot-samples.

azizkhani avatar azizkhani commented on August 23, 2024

پیغام ارسال عکس نشان داده میشود ولی عکس دلیور نمی شود ؟
مشکل چیست ؟
این هم لاگ عکس ارسالی

{ reply_markup: { inline_keyboard: [ [Array] ] },
  caption: 'Apple-MacBook-Pro قیمت10000' }
FileUploadLinkResponse {
  _id: '4',
  _body:
   { fileId: '3016162705129145345',
     url: 'https://fileserver-004-c002.bale.ai/145694799/3016162705129145345',
     dup: false,
     userId: 145694799 },
  _fileId: '3016162705129145345',
  _url: 'https://fileserver-004-c002.bale.ai/145694799/3016162705129145345',
  _dup: false,
  _userId: 145694799 }
FileUploadLinkResponse {
  _id: '5',
  _body:
   { fileId: '-7927091808171916031',
     url: 'https://fileserver-005-c002.bale.ai/145694799/-7927091808171916031',
     dup: false,
     userId: 145694799 },
  _fileId: '-7927091808171916031',
  _url: 'https://fileserver-005-c002.bale.ai/145694799/-7927091808171916031',
  _dup: false,
  _userId: 145694799 }
{ server: 'nginx/1.13.12',
  date: 'Sun, 27 May 2018 16:51:50 GMT',
  'transfer-encoding': 'chunked',
  connection: 'close',
  crc32: '2793226675' }
PhotoMessage {
  _fileId: '3016162705129145345',
  _accessHash: 145694799,
  _name: 'name.jpg',
  _fileSize: 90258,
  _mimeType: 'image/jpeg',
  _captionText: 'caption',
  _width: 1,
  _height: null,
  _ext_width: 80,
  _ext_height: 80,
  _thumb: undefined }
{ server: 'nginx/1.13.12',
  date: 'Sun, 27 May 2018 16:51:50 GMT',
  'transfer-encoding': 'chunked',
  connection: 'close',
  crc32: '841143119' }
PhotoMessage {
  _fileId: '-7927091808171916031',
  _accessHash: 145694799,
  _name: 'name.jpg',
  _fileSize: 90258,
  _mimeType: 'image/jpeg',
  _captionText: 'caption',
  _width: 1,
  _height: null,
  _ext_width: 80,
  _ext_height: 80,
  _thumb: undefined }

from bale-bot-samples.

azizkhani avatar azizkhani commented on August 23, 2024

this is my code

const SDK = require('balebot');
const Promise = require('bluebird');
var request = require('request').defaults({ encoding: null });

import incoming from './incoming';
const _ = require('lodash');

class Bale {
  constructor(bp, config) {
    if (!bp || !config) {
      throw new Error('You need to specify botpress and config');
    }
    this.bot = null;
    this.connected = false;
    this.bot = new SDK.BaleBot(config.botToken);
    bp.logger.info('bale bot created');
  }

  setConfig(config) {
    this.config = Object.assign({}, this.config, config);
  }

  validateConnection() {
    if (!this.connected) {
      throw new Error('You are not connected...');
    }
  }

  static validateText(text) {
    const type = typeof (text);
    if (type !== 'string') {
      throw new Error(
        'Text format is not valid (actual: ' + type + ', required: string)');
    }
  }

  static validateChat(chat) {
    const type = typeof (chat);
    if (type !== 'number') {
      throw new Error('Chat id format is not valid (actual: ' + type +
        ', required: number)');
    }
  }


  static validateOptions(options) {
    const type = typeof (options);
    if (type !== 'object') {
      throw new Error('Options format is not valid (actual: ' + type +
        ', required: object)');
    }
  }

  static validateBeforeReaction(options) {
    if (!(options.file || options.file_comment || options.chat ||
      options.timestamp)) {
      throw new Error(
        'You need to set at least a destination options (file, file_comment, chat, timestamp)...');
    }
  }

  static resolveMessage(text, options) {
    var msg = new SDK.TextMessage(text);
    console.log(options);
    console.log(typeof options);
    if (typeof options === 'undefined' ||
      typeof options.reply_markup === 'undefined' ||
      typeof options.reply_markup.keyboard === 'undefined') {
      return msg;
    }
    var simpletemplate = new SDK.SimpleTemplate(msg, [], 'Text');
    _.forEach(options.reply_markup.keyboard, items => {
      _.forEach(items, item => {
        var text = item.text ? item.text : item;
        var button = new SDK.ButtonElement(text, text, 1);
        simpletemplate.addElement(button);
      });
    });
    return new SDK.TemplateMessage(simpletemplate);

  }

  validateBeforeSending(chat, options) {
    this.validateConnection();
    //Bale.validateChat(chat);
    //Bale.validateOptions(options);
  }

  sendText(chat, text, options) {
    this.validateBeforeSending(chat, options);
    Bale.validateText(text);
    //let msg = new SDK.TextMessage(text);
    let msg = Bale.resolveMessage(text, options);
    let receiver = new SDK.User(chat.id /*user id*/, chat.accessHash /*user access hash*/);
    return Promise.fromCallback(() => {
      this.bot.send(msg, receiver);
    });
  }

  sendAttachment(chat, url, options) {
    return Promise.fromCallback(() => {
      request(url, (err, response, buffer) => {
        this.bot.UploadFile(buffer, 'file').then(response => {
          let fileId = response.fileId;
          let fileAccessHash = response.accessHash;
         
          var photoMsg = new SDK.PhotoMessage(fileId, fileAccessHash, 'name.jpg', 90258, 'image/jpeg', 'caption',1,null);
          console.log(photoMsg);
          let receiver = new SDK.User(chat.id, chat.accessHash);
          this.bot.send(photoMsg, receiver);

        }).catch((err) => {
        });
      });
    });
  }

  startPolling(bp) {
    incoming(bp, this);
    bp.logger.info('bale loaded handler');
    this.bot.setOnMessage();
    bp.logger.info('bale started polling');
    this.connected = true;
  }
}

module.exports = Bale;

from bale-bot-samples.

ebarkhordar avatar ebarkhordar commented on August 23, 2024

It's corrected part related to photoMessage, try it

bot.hears(["start"], (message, responder) => {
    fs.readFile('/home/ehsan/Pictures/index.jpeg', function (err, imageBuffer) {
        bot.UploadFile(imageBuffer, 'file').then(response => {
            var thumbBuffer = new Buffer(imageBuffer).toString('base64');
            let fileId = response.fileId;
            let fileAccessHash = response.accessHash;
            var photoMsg = new SDK.PhotoMessage(fileId, fileAccessHash.toString(), 'name.jpg', 10000, 'image/jpeg', 'caption', 300, 200, thumbBuffer);
            console.log(photoMsg);
            responder.reply(photoMsg).then((res) => {
                console.log(res)
            }).catch((err) => {
                console.log(err)
            });
        });
    });
});

from bale-bot-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.