mast / telegram-bot-api

First Telegram Bot API node.js library
http://mast.github.io/telegram-bot-api/
MIT License
246 stars 64 forks source link

sendPhoto parse_mode #64

Closed salimbene closed 4 years ago

salimbene commented 5 years ago

Hello! sendPhoto does not support parse_mode correct? It doesnt seem to do anything with either 'html' or 'parse_node'

const response = await api.sendPhoto({
    chat_id,
    photo,
    caption,
    parse_mode: 'Markdown'
  });
  return response;

Great API by the way. Cheers!

realtebo commented 4 years ago

I have the same problem

  await api.sendPhoto({
    chat_id,
    caption: "*" + title + "* \n" + caption + "",
    parse_mode: "MarkdownV2",
    photo: image_name,
  })

The result is a caption with litteral "*" . Why ?

pedroaf0 commented 4 years ago

Hi! the sendPhoto method supports parse_mode look: bnbn

This is because the parse_mode is not included in the args. look:

  this.sendPhoto = function (params, cb)
    {
        return new Promise(function(resolve, reject)
        {
            // Act different depending on value params.photo
            fs.exists(params.photo, function (exists)
            {
                var photo = null;
                if (exists)
                {
                    // params.photo is path to file
                    photo = fs.createReadStream(params.photo);
                }
                else
                {
                    // params.photo is not a file, simply pass it to POST
                    photo = params.photo;
                }

                var args = {
                    chat_id: params.chat_id,
                    photo: photo
                };

                if (params.caption !== undefined)
                {
                    args.caption = params.caption;
                }

                if (params.reply_to_message_id !== undefined)
                {
                    args.reply_to_message_id = params.reply_to_message_id;
                }

                if (params.reply_markup !== undefined)
                {
                    args.reply_markup = params.reply_markup;
                }

                _rest({
                    method: 'POST',
                    json: true,
                    formData: args,
                    uri: _baseurl + 'sendPhoto'
                })
                .then(function(body)
                {
                    return commonResponseHandler(body);
                })
                .then(function(data)
                {
                    resolve(data);
                })
                .catch(function(err)
                {
                    reject(err);
                });
            });
        }).nodeify(cb);
    };

I will launch a PR with the correction soon!

mast commented 4 years ago

Fixed in 2.0