Skip to content

Commit

Permalink
Align props names with Telegram bot api names
Browse files Browse the repository at this point in the history
  • Loading branch information
mullwar committed May 19, 2017
1 parent 9d6c664 commit 924b79a
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 59 deletions.
34 changes: 17 additions & 17 deletions README.md
Expand Up @@ -115,7 +115,7 @@ Command with arguments `/say <your message>`:
```js
bot.on(/^\/say (.+)$/, (msg, props) => {
const text = props.match[1];
return bot.sendMessage(msg.from.id, text, { reply: msg.message_id });
return bot.sendMessage(msg.from.id, text, { replyToMessage: msg.message_id });
});
```

Expand Down Expand Up @@ -284,7 +284,7 @@ Use module function.

##### `keyboard([array of arrays], {resize, once, selective})`

Creates `ReplyKeyboardMarkup` keyboard `markup` object.
Creates `ReplyKeyboardMarkup` keyboard `replyMarkup` object.

##### `button(<location | contact>, <text>)`

Expand Down Expand Up @@ -330,63 +330,63 @@ Use this method to send `answerList` to an inline query.

Use this method to get basic info about a file and prepare it for downloading.

##### `sendMessage(<chat_id>, <text>, {parse, reply, markup, notify, preview})`
##### `sendMessage(<chat_id>, <text>, {parseMode, replyToMessage, replyMarkup, notification, webPreview})`

Use this method to send text messages.

##### `forwardMessage(<chat_id>, <from_chat_id>, <message_id>, {notify})`
##### `forwardMessage(<chat_id>, <from_chat_id>, <message_id>, {notification})`

Use this method to forward messages of any kind.

##### `deleteMessage(<chat_id>, <from_message_id>)`

Use this method to delete a message. A message can only be deleted if it was sent less than 48 hours ago. Any such sent outgoing message may be deleted. Additionally, if the bot is an administrator in a group chat, it can delete any message. If the bot is an administrator of a supergroup or channel, it can delete ordinary messages from any other user, including service messages about people added or removed from the chat. Returns *True* on success.

##### `sendPhoto(<chat_id>, <file_id | path | url | buffer | stream>, {caption, fileName, serverDownload, reply, markup, notify})`
##### `sendPhoto(<chat_id>, <file_id | path | url | buffer | stream>, {caption, fileName, serverDownload, replyToMessage, replyMarkup, notification})`

Use this method to send photos.

##### `sendAudio(<chat_id>, <file_id | path | url | buffer | stream>, {title, performer, duration, caption, fileName, serverDownload, reply, markup, notify})`
##### `sendAudio(<chat_id>, <file_id | path | url | buffer | stream>, {title, performer, duration, caption, fileName, serverDownload, replyToMessage, replyMarkup, notification})`

Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.

##### `sendDocument(<chat_id>, <file_id | path | url | buffer | stream>, {caption, fileName, serverDownload, reply, markup, notify})`
##### `sendDocument(<chat_id>, <file_id | path | url | buffer | stream>, {caption, fileName, serverDownload, replyToMessage, replyMarkup, notification})`

Use this method to send general files.

##### `sendSticker(<chat_id>, <file_id | path | url | buffer | stream>, {fileName, serverDownload, reply, markup, notify})`
##### `sendSticker(<chat_id>, <file_id | path | url | buffer | stream>, {fileName, serverDownload, replyToMessage, replyMarkup, notification})`

Use this method to send `.webp` stickers.

##### `sendVideo(<chat_id>, <file_id | path | url | buffer | stream>, {duration, width, height, caption, fileName, serverDownload, reply, markup, notify})`
##### `sendVideo(<chat_id>, <file_id | path | url | buffer | stream>, {duration, width, height, caption, fileName, serverDownload, replyToMessage, replyMarkup, notification})`

Use this method to send video files, Telegram clients support `mp4` videos (other formats may be sent as `Document`).

##### `sendVideoNote(<chat_id>, <file_id | path | url | buffer | stream>, {duration, length, fileName, serverDownload, reply, markup, notify})`
##### `sendVideoNote(<chat_id>, <file_id | path | url | buffer | stream>, {duration, length, fileName, serverDownload, replyToMessage, replyMarkup, notification})`

Use this method to send video messages.

##### `sendVoice(<chat_id>, <file_id | path | url | buffer | stream>, {duration, caption, fileName, serverDownload, reply, markup, notify})`
##### `sendVoice(<chat_id>, <file_id | path | url | buffer | stream>, {duration, caption, fileName, serverDownload, replyToMessage, replyMarkup, notification})`

Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.

##### `sendLocation(<chat_id>, [<latitude>, <longitude>], {reply, markup, notify})`
##### `sendLocation(<chat_id>, [<latitude>, <longitude>], {replyToMessage, replyMarkup, notification})`

Use this method to send point on the map.

##### `sendVenue(<chat_id>, [<latitude>, <longitude>], <title>, <address>, {foursquareId, reply, markup, notify})`
##### `sendVenue(<chat_id>, [<latitude>, <longitude>], <title>, <address>, {foursquareId, replyToMessage, replyMarkup, notification})`

Use this method to send information about a venue.

##### `sendContact(<chat_id>, <number>, <firstName>, <lastName>, { reply, markup, notify})`
##### `sendContact(<chat_id>, <number>, <firstName>, <lastName>, { replyToMessage, replyMarkup, notification})`

Use this method to send phone contacts.

##### `sendAction(<chat_id>, <action>)`

Use this method when you need to tell the user that something is happening on the bot's side. Choose one, depending on what the user is about to receive: *typing* for text messages, *upload_photo* for photos, *record_video* or *upload_video* for videos, *record_audio* or *upload_audio* for audio files, *upload_document* for general files, *find_location* for location data, *record_video_note* or *upload_video_note* for video notes.

##### `sendGame(<chat_id>, <game_short_name>, {notify, reply, markup})`
##### `sendGame(<chat_id>, <game_short_name>, {notification, replyToMessage, replyMarkup})`

Use this method to send a game.

Expand All @@ -406,7 +406,7 @@ Use this method to get a list of profile pictures for a user.

Use this method to get basic info about a file and prepare it for downloading.

##### `sendInvoice(<chat_id>, {title, description, payload, providerToken, startParameter, currency, prices, photo: {url, width, height}, need: {name, phoneNumber, email, shippingAddress}, isFlexible, notify, reply, markup})`
##### `sendInvoice(<chat_id>, {title, description, payload, providerToken, startParameter, currency, prices, photo: {url, width, height}, need: {name, phoneNumber, email, shippingAddress}, isFlexible, notification, replyToMessage, replyMarkup})`

Use this method to send invoices.

Expand Down Expand Up @@ -446,7 +446,7 @@ Use this method to edit text messages sent by the bot or via the bot (for inline

Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).

##### `editMessageReplyMarkup` as `editMarkup({chatId & messageId | inlineMsgId}, <markup>)`
##### `editMessageReplyMarkup` as `editMarkup({chatId & messageId | inlineMsgId}, <replyMarkup>)`

Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).

Expand Down
4 changes: 2 additions & 2 deletions examples/KittyBot.js
Expand Up @@ -10,7 +10,7 @@ const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
const API = 'https://thecatapi.com/api/images/get?format=src&type=';

// Command keyboard
const markup = bot.keyboard([
const replyMarkup = bot.keyboard([
['/kitty', '/kittygif']
], {resize: true, once: false});

Expand All @@ -23,7 +23,7 @@ bot.on('text', function (msg) {
bot.on(['/start', '/help'], function (msg) {

return bot.sendMessage(msg.chat.id,
'😺 Use commands: /kitty, /kittygif and /about', {markup}
'😺 Use commands: /kitty, /kittygif and /about', {replyMarkup}
);

});
Expand Down
4 changes: 2 additions & 2 deletions examples/edit-markup.js
Expand Up @@ -26,10 +26,10 @@ bot.on('callbackQuery', msg => {

const data = msg.data;
const [chatId, messageId] = lastMessage;
const markup = updateKeyboard(data);
const replyMarkup = updateKeyboard(data);

// Edit message markup
return bot.editMarkup({chatId, messageId}, {markup});
return bot.editMarkup({chatId, messageId}, {replyMarkup});

});

Expand Down
2 changes: 1 addition & 1 deletion examples/edit-text.js
Expand Up @@ -16,7 +16,7 @@ function updateTime(chatId, messageId) {
setInterval(() => {
bot.editText(
{chatId, messageId}, `<b>Current time:</b> ${ time() }`,
{parse: 'html'}
{parseMode: 'html'}
).catch(error => console.log('Error:', error));
}, 1000);

Expand Down
14 changes: 7 additions & 7 deletions examples/keyboard.js
Expand Up @@ -4,31 +4,31 @@ const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
// On commands
bot.on(['/start', '/back'], msg => {

let markup = bot.keyboard([
let replyMarkup = bot.keyboard([
['/buttons', '/inlineKeyboard'],
['/start', '/hide']
], {resize: true});

return bot.sendMessage(msg.from.id, 'Keyboard example.', {markup});
return bot.sendMessage(msg.from.id, 'Keyboard example.', {replyMarkup});

});

// Buttons
bot.on('/buttons', msg => {

let markup = bot.keyboard([
let replyMarkup = bot.keyboard([
[bot.button('contact', 'Your contact'), bot.button('location', 'Your location')],
['/back', '/hide']
], {resize: true});

return bot.sendMessage(msg.from.id, 'Button example.', {markup});
return bot.sendMessage(msg.from.id, 'Button example.', {replyMarkup});

});

// Hide keyboard
bot.on('/hide', msg => {
return bot.sendMessage(
msg.from.id, 'Hide keyboard example. Type /back to show.', {markup: 'hide'}
msg.from.id, 'Hide keyboard example. Type /back to show.', {replyMarkup: 'hide'}
);
});

Expand All @@ -40,7 +40,7 @@ bot.on(['location', 'contact'], (msg, self) => {
// Inline buttons
bot.on('/inlineKeyboard', msg => {

let markup = bot.inlineKeyboard([
let replyMarkup = bot.inlineKeyboard([
[
bot.inlineButton('callback', {callback: 'this_is_data'}),
bot.inlineButton('inline', {inline: 'some query'})
Expand All @@ -49,7 +49,7 @@ bot.on('/inlineKeyboard', msg => {
]
]);

return bot.sendMessage(msg.from.id, 'Inline keyboard example.', {markup});
return bot.sendMessage(msg.from.id, 'Inline keyboard example.', {replyMarkup});

});

Expand Down
6 changes: 3 additions & 3 deletions examples/message-types.js
Expand Up @@ -4,11 +4,11 @@ const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
// On every type of message (& command)
bot.on(['*', '/*'], (msg, self) => {
let id = msg.from.id;
let reply = msg.message_id;
let replyToMessage = msg.message_id;
let type = self.type;
let parse = 'html';
let parseMode = 'html';
return bot.sendMessage(
id, `This is a <b>${ type }</b> message.`, {reply, parse}
id, `This is a <b>${ type }</b> message.`, {replyToMessage, parseMode}
);
});

Expand Down
2 changes: 1 addition & 1 deletion examples/payment.js
Expand Up @@ -21,7 +21,7 @@ bot.on('/start', (msg) => {
{label: 'For testing!', amount: 1250},
{label: 'Discount', amount: -120}
],
markup: inlineKeyboard
replyMarkup: inlineKeyboard
}).then(data => {
console.log('OK', data);
}).catch(error => {
Expand Down
4 changes: 2 additions & 2 deletions examples/plugin-commandButton.js
Expand Up @@ -9,7 +9,7 @@ const bot = new TeleBot({
bot.on('/start', msg => {

// Inline keyboard markup
const markup = bot.inlineKeyboard([
const replyMarkup = bot.inlineKeyboard([
[
// First row with command callback button
bot.inlineButton('Command button', {callback: '/hello'})
Expand All @@ -21,7 +21,7 @@ bot.on('/start', msg => {
]);

// Send message with keyboard markup
return bot.sendMessage(msg.from.id, 'Example of command button.', {markup});
return bot.sendMessage(msg.from.id, 'Example of command button.', {replyMarkup});

});

Expand Down
6 changes: 3 additions & 3 deletions examples/plugin-namedButtons.js
Expand Up @@ -28,16 +28,16 @@ const bot = new TeleBot({

bot.on('/hello', (msg) => msg.reply.text('Hello command!'));
bot.on('/world', (msg) => msg.reply.text('World command!'));
bot.on('/hide', (msg) => msg.reply.text('Type /start to show keyboard again.', {markup: 'hide'}));
bot.on('/hide', (msg) => msg.reply.text('Type /start to show keyboard again.', {replyMarkup: 'hide'}));

bot.on('/start', (msg) => {

let markup = bot.keyboard([
let replyMarkup = bot.keyboard([
[BUTTONS.hello.label, BUTTONS.world.label],
[BUTTONS.hide.label]
], {resize: true});

return bot.sendMessage(msg.from.id, 'See keyboard below.', {markup});
return bot.sendMessage(msg.from.id, 'See keyboard below.', {replyMarkup});

});

Expand Down
27 changes: 13 additions & 14 deletions lib/telebot.js
Expand Up @@ -478,29 +478,28 @@ class TeleBot {

properties(form = {}, opt = {}) {

// Reply to message
if (opt.reply) form.reply_to_message_id = opt.reply;
const parseMode = opt.parseMode || opt.parse;
const replyToMessage = opt.replyToMessage || opt.reply;
const replyMarkup = opt.replyMarkup || opt.markup;
const notification = opt.notification === false || opt.notify === false;
const webPreview = opt.webPreview === false || opt.preview === false;

// Markdown/HTML support for message
if (opt.parse) form.parse_mode = opt.parse;

// User notification
if (opt.notify === false) form.disable_notification = true;

// Web preview
if (opt.preview === false) form.disable_web_page_preview = true;
if (replyToMessage) form.reply_to_message_id = replyToMessage;
if (parseMode) form.parse_mode = parseMode;
if (notification) form.disable_notification = true;
if (webPreview) form.disable_web_page_preview = true;

// Markup object
if (opt.markup !== undefined) {
if (opt.markup == 'hide' || opt.markup === false) {
if (replyMarkup !== undefined) {
if (replyMarkup == 'hide' || replyMarkup === false) {
// Hide keyboard
form.reply_markup = JSON.stringify({hide_keyboard: true});
} else if (opt.markup == 'reply') {
} else if (replyMarkup == 'reply') {
// Fore reply
form.reply_markup = JSON.stringify({force_reply: true});
} else {
// JSON keyboard
form.reply_markup = JSON.stringify(opt.markup);
form.reply_markup = JSON.stringify(replyMarkup);
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/reporter.js
Expand Up @@ -63,7 +63,7 @@ module.exports = {
`${ error.stack ? `🚧 <b>Stack:</b>\n${ s(error.stack) }\n` : '' }` +
`⏰ <b>Event:</b> ${ type }\n` +
`💾 <b>Data:</b> ${ jsonData }`,
{parse: 'html', skipReport: true}
{parseMode: 'html', skipReport: true}
);

} else {
Expand All @@ -72,7 +72,7 @@ module.exports = {
bot.sendMessage(userId,
`⏰ <b>Event:</b> ${ type }\n` +
(jsonData && jsonData != '{}' ? `💾 <b>Data:</b> ${ jsonData }` : ''),
{parse: 'html', skipReport: true}
{parseMode: 'html', skipReport: true}
);

}
Expand Down
2 changes: 1 addition & 1 deletion plugins/shortReply.js
Expand Up @@ -37,7 +37,7 @@ module.exports = {

function propertyProcessor(msg, props) {
if (replyMode || props.asReply === true) {
props.reply = msg.message_id;
props.replyToMessage = msg.message_id;
}
return props;
}
Expand Down
8 changes: 4 additions & 4 deletions test/index.js
Expand Up @@ -254,14 +254,14 @@ test('bot.editCaption', t => {
});

test('bot.editMarkup', t => {
let markup = bot.inlineKeyboard([
let replyMarkup = bot.inlineKeyboard([
[bot.inlineButton('test', {callback: 1})]
]);
return bot.sendMessage(USER, 'markup', {markup}).then(re => {
return bot.sendMessage(USER, 'markup', {replyMarkup}).then(re => {
const chatId = USER;
const messageId = re.result.message_id;
markup = bot.inlineKeyboard([[bot.inlineButton('OK', {callback: 2})]]);
return bot.editMarkup({chatId, messageId}, markup);
replyMarkup = bot.inlineKeyboard([[bot.inlineButton('OK', {callback: 2})]]);
return bot.editMarkup({chatId, messageId}, replyMarkup);
}).then(re => t.true(re.ok));
});

Expand Down

0 comments on commit 924b79a

Please sign in to comment.