fix(edited_message): new updated messages have an edited_message property instead of message.

This commit is contained in:
Mahdi Dibaiee 2016-05-27 11:56:05 +04:30
parent dd7dd633fc
commit 12ffd75527
2 changed files with 12 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "telegram-api", "name": "telegram-api",
"version": "0.7.5", "version": "0.7.6",
"description": "Control Telegram bots easily using the new Telegram API", "description": "Control Telegram bots easily using the new Telegram API",
"main": "build/index.js", "main": "build/index.js",
"scripts": { "scripts": {

View File

@ -170,7 +170,8 @@ export default class Bot extends EventEmitter {
} }
update.forEach(res => { update.forEach(res => {
let text = res.message.text; const msg = res.message || res.edited_message;
let text = msg.text;
if (!text) { if (!text) {
return; return;
} }
@ -181,39 +182,39 @@ export default class Bot extends EventEmitter {
// Commands are sent in /command@thisusername format in groups // Commands are sent in /command@thisusername format in groups
const regex = new RegExp(`(/.*)@${this.info.username}`); const regex = new RegExp(`(/.*)@${this.info.username}`);
text = text.replace(regex, '$1'); text = text.replace(regex, '$1');
res.message.text = text; msg.text = text;
} }
const ev = this._userEvents.find(({ pattern }) => pattern.test(text)); const ev = this._userEvents.find(({ pattern }) => pattern.test(text));
if (!ev) { if (!ev) {
this.emit('command-notfound', res.message); this.emit('command-notfound', msg);
return; return;
} }
if (!ev.parse) { if (!ev.parse) {
ev.listener(res.message); ev.listener(msg);
return; return;
} }
const { params, args } = ev.parse(res.message.text); const { params, args } = ev.parse(msg.text);
res.message.args = args; msg.args = args;
const requiredParams = Object.keys(params).filter(param => const requiredParams = Object.keys(params).filter(param =>
params[param] === REQUIRED && !args[param] params[param] === REQUIRED && !args[param]
); );
if (!requiredParams.length) { if (!requiredParams.length) {
ev.listener(res.message); ev.listener(msg);
return; return;
} }
const bot = this; const bot = this;
function* getAnswer() { function* getAnswer() {
for (const param of requiredParams) { 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}`); .text(`Enter value for ${param}`);
yield bot.send(msg).then(answer => { yield bot.send(ga).then(answer => {
args[param] = answer.text; args[param] = answer.text;
}); });
} }
@ -223,7 +224,7 @@ export default class Bot extends EventEmitter {
(function loop() { (function loop() {
const next = iterator.next(); const next = iterator.next();
if (next.done) { if (next.done) {
ev.listener(res.message); ev.listener(msg);
return; return;
} }