Skip to content

Commit

Permalink
Merge pull request #14 from NivEz/feature/edit-inline-keyboard
Browse files Browse the repository at this point in the history
added editInlineKeyboard support
  • Loading branch information
NivEz committed Jan 12, 2024
2 parents 41e7bdb + 479399f commit 55c35ab
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/inlineKeyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ bot.onButton('', callbackQuery => {
);
});

bot.onButton('edit', callbackQuery => {
inlineKeyboard.push([
{
text: 'New button - remove me',
callback_data: 'remove',
},
]);
bot.editInlineKeyboard(
callbackQuery.message.chat.id,
callbackQuery.message.message_id,
null,
inlineKeyboard,
);
});

bot.onButton('remove', callbackQuery => {
inlineKeyboard.pop();
bot.editInlineKeyboard(
callbackQuery.message.chat.id,
callbackQuery.message.message_id,
null,
inlineKeyboard,
);
});

const inlineKeyboard = [
[
{
Expand All @@ -54,4 +79,10 @@ const inlineKeyboard = [
callback_data: 'random',
},
],
[
{
text: 'Add button - edit (editMessageReplyMarkup)',
callback_data: 'edit',
},
],
];
17 changes: 17 additions & 0 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ class Telenode {
});
}

async editInlineKeyboard(chatId, messageId, inlineMessageId, inlineKeyboard) {
if (!inlineMessageId && (!chatId || !messageId)) {
throw new Error(
'inlineMessageId is required when chatId and messageId are not specified',
);
}
const url = this.#baseUrl + '/editMessageReplyMarkup';
return await axios.post(url, {
chat_id: chatId,
message_id: messageId,
inline_message_id: inlineMessageId,
reply_markup: {
inline_keyboard: inlineKeyboard,
},
});
}

async sendReplyKeyboard(chatId, text, replyKeyboard, oneTimeKeyboard) {
if (!text) {
throw Error('text parameter is required');
Expand Down

0 comments on commit 55c35ab

Please sign in to comment.