/**
* METHOD: sendPhoto
* PARAMS:
* chat_id Unique identifier for the message recepient — User or GroupChat id
* photo Photo to send. You can either pass a file_id as String to resend
* a photo that is already on the Telegram servers, or upload
* a new photo using multipart/form-data.
* caption Photo caption (may also be used when resending photos by file_id)
* reply_to_message_id If the message is a reply, ID of the original message
* reply_markup Additional interface options. A JSON-serialized object for a custom
* reply keyboard, instructions to hide keyboard or to force a reply from the user.
*/
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);
};