feature: add event listeners to get answers from Base.send method only when explicitly asked #47

Merged
laurynas-karvelis merged 3 commits from feature/prevent-event-listener-overflow into master 2018-12-24 12:00:50 +00:00
Showing only changes of commit 68eb5e5483 - Show all commits

View File

@ -28,7 +28,7 @@ export default class Base extends EventEmitter {
* @param {boolean} expectAnswer whether a sent message expects an answer from a contact(s)
* @return {Promise} returns a promise, resolved with message:answer
*/
send(bot, expectAnswer = false) {
send(bot, expectAnswer = true) {
if (this._keyboard) {
const replyMarkup = JSON.stringify(this._keyboard.getProperties());
this.properties.reply_markup = replyMarkup;
@ -43,7 +43,8 @@ export default class Base extends EventEmitter {
.then(messageId => {
if (!expectAnswer) {
// no need to add more event callbacks for the messages that don't need expect an answer
return resolve();
resolve();
return;
}
const chat = this.properties.chat_id;
@ -73,8 +74,6 @@ export default class Base extends EventEmitter {
bot.removeListener('update', listener);
}
});
return void 0;
})
.catch(reject)
.finally(() => {