Skip to content

Commit

Permalink
Add parse option for telegram callback_query (#78)
Browse files Browse the repository at this point in the history
* add parse option for telegram callback_query

* remove string keys in test object
  • Loading branch information
alejandrogr authored and stojanovic committed Jan 9, 2017
1 parent 7a2eb92 commit 734d21b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/telegram/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ module.exports = function(messageObject) {
type: 'telegram'
};
}

if (messageObject && messageObject.callback_query && messageObject.callback_query.message.chat &&
messageObject.callback_query.message.chat.id ){
var callback_query = messageObject.callback_query;
return {
sender: callback_query.message.chat.id,
text: callback_query.data || '',
originalRequest: messageObject,
type: 'telegram'
};
}
};
4 changes: 4 additions & 0 deletions spec/telegram/telegram-parse-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ describe('Telegram parse', () => {
var msg = {message: {chat: {id: 'some123ChatId'}, text: 'ello Telegram' }};
expect(parse(msg)).toEqual({ sender: 'some123ChatId', text: 'ello Telegram', originalRequest: msg, type: 'telegram'});
});
it('returns a parsed object when messageObject contains a callback_query', () => {
var msg = {callback_query: {message: {chat: {id: 'some123ChatId'}},data: 'someCallbackData'}};
expect(parse(msg)).toEqual({ sender: 'some123ChatId', text: 'someCallbackData', originalRequest: msg, type: 'telegram'});
});
});

0 comments on commit 734d21b

Please sign in to comment.