From 12ffd755276ab2286fc01bd6fe57f4feaf384205 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Fri, 27 May 2016 11:56:05 +0430 Subject: [PATCH] fix(edited_message): new updated messages have an edited_message property instead of message. --- package.json | 2 +- src/index.js | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 107dcc7..bb37d36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telegram-api", - "version": "0.7.5", + "version": "0.7.6", "description": "Control Telegram bots easily using the new Telegram API", "main": "build/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index f705a7f..8c91e7c 100644 --- a/src/index.js +++ b/src/index.js @@ -170,7 +170,8 @@ export default class Bot extends EventEmitter { } update.forEach(res => { - let text = res.message.text; + const msg = res.message || res.edited_message; + let text = msg.text; if (!text) { return; } @@ -181,39 +182,39 @@ export default class Bot extends EventEmitter { // Commands are sent in /command@thisusername format in groups const regex = new RegExp(`(/.*)@${this.info.username}`); text = text.replace(regex, '$1'); - res.message.text = text; + msg.text = text; } const ev = this._userEvents.find(({ pattern }) => pattern.test(text)); if (!ev) { - this.emit('command-notfound', res.message); + this.emit('command-notfound', msg); return; } if (!ev.parse) { - ev.listener(res.message); + ev.listener(msg); return; } - const { params, args } = ev.parse(res.message.text); - res.message.args = args; + const { params, args } = ev.parse(msg.text); + msg.args = args; const requiredParams = Object.keys(params).filter(param => params[param] === REQUIRED && !args[param] ); if (!requiredParams.length) { - ev.listener(res.message); + ev.listener(msg); return; } const bot = this; function* getAnswer() { for (const param of requiredParams) { - const msg = new Message().to(res.message.chat.id) + const ga = new Message().to(msg.chat.id) .text(`Enter value for ${param}`); - yield bot.send(msg).then(answer => { + yield bot.send(ga).then(answer => { args[param] = answer.text; }); } @@ -223,7 +224,7 @@ export default class Bot extends EventEmitter { (function loop() { const next = iterator.next(); if (next.done) { - ev.listener(res.message); + ev.listener(msg); return; }