Merge pull request #47 from laurynas-karvelis/feature/prevent-event-listener-overflow
feature: add event listeners to get answers from Base.send method only when explicitly asked
This commit was merged in pull request #47.
	This commit is contained in:
		@@ -25,9 +25,10 @@ export default class Base extends EventEmitter {
 | 
				
			|||||||
   *				                 gets the Update object containing message
 | 
					   *				                 gets the Update object containing message
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * @param  {object} bot
 | 
					   * @param  {object} bot
 | 
				
			||||||
 | 
					   * @param {boolean} expectAnswer whether a sent message expects an answer from a contact(s)
 | 
				
			||||||
   * @return {Promise} returns a promise, resolved with message:answer
 | 
					   * @return {Promise} returns a promise, resolved with message:answer
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  send(bot) {
 | 
					  send(bot, expectAnswer = true) {
 | 
				
			||||||
    if (this._keyboard) {
 | 
					    if (this._keyboard) {
 | 
				
			||||||
      const replyMarkup = JSON.stringify(this._keyboard.getProperties());
 | 
					      const replyMarkup = JSON.stringify(this._keyboard.getProperties());
 | 
				
			||||||
      this.properties.reply_markup = replyMarkup;
 | 
					      this.properties.reply_markup = replyMarkup;
 | 
				
			||||||
@@ -40,6 +41,12 @@ export default class Base extends EventEmitter {
 | 
				
			|||||||
          return response.result.message_id;
 | 
					          return response.result.message_id;
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        .then(messageId => {
 | 
					        .then(messageId => {
 | 
				
			||||||
 | 
					          if (!expectAnswer) {
 | 
				
			||||||
 | 
					            // no need to add more event callbacks for the messages that don't need expect an answer
 | 
				
			||||||
 | 
					            resolve();
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          const chat = this.properties.chat_id;
 | 
					          const chat = this.properties.chat_id;
 | 
				
			||||||
          let answers = 0;
 | 
					          let answers = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user