Telegram Bot : Button Text Is Not Readable
I have developed telegram bot which responds to users input.But when bot send buttons to user, text of the button is not readable.
Below is the screenshot of chat:
I think telegram does not resize button when number of buttons are more or button text length is more.
I am using below code to send buttons:
buttonoptions.forEach(buttonElement => {
var buttonText = buttonElement;
if (buttonText.length > 30) {
buttonText = buttonText.substring(0, 27);
buttonText = buttonText + "...";
}
var buttonItem = {
text: buttonText,
callback_data: JSON.stringify({
'type': 'button',
'text': buttonText
})
}
buttons.push(buttonItem);
});
var message = {
parse_mode: 'Markdown',
reply_markup: JSON.stringify({
inline_keyboard: [buttons]
})
};
//send message code
So is there any way to force telegram bot to show complete text of button?
Answer
Telegram Bot API takes an array of arrays of buttons as a value of inline_keyboard
field. Every array represents a row of buttons in inline keyboard.
So, you have many buttons on the same row, the text looks truncated. To avoid this you can place buttons on several rows.
E.g.:
const options = {
reply_markup: JSON.stringify({
inline_keyboard: [
[{ text: 'Button 1', callback_data: '1' }],
[{ text: 'Button 2', callback_data: 'data 2' }],
[{ text: 'Button 3', callback_data: 'text 3' }]
]
})
};
This results in three rows with single button on each. I believe the text will not be truncated.
Cheers!
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error