2017-01-10 60 views
0

在电报机器人SendMessage函数之前sendphoto,用的NodeJS,我想sendphoto和之后将消息发送到用户如何的NodeJS

我用这个代码:

bot.sendPhoto(chatId, photo); 
bot.sendMessage(chatId, caption, opts); 

但我的问题是:消息前照片和内嵌按钮被示出中示出上面的照片的:( 我喜欢所示的第一相片和它消息内嵌按钮后

我使用此:

bot.sendPhoto(chatId, photo, function(){bot.sendMessage(chatId, caption, opts)}); 

但是用此代码显示照片并没有显示任何消息

请原谅我的英文不好!

回答

1

使用承诺。你可以使用q library来实现它。

确保sendPhoto函数返回一个承诺。所以你可以做到以下几点

bot.sendPhoto(chatId, photo).then(function(resultFromSendPhoto){ 
    bot.sendMessage(chatId, caption, opts); 
    //your further code goes here if you want 
}).catch(function(error){ 
    console.log(error); 
}).done();