Answer the question
In order to leave comments, you need to log in
How to pass calculation logic to TG bot?
const TelegramApi = require('node-telegram-bot-api');
const bot = new TelegramApi(token,{polling: true});
const radOptions = {
reply_markup: JSON.stringify({
inline_keyboard:[
[{text: 'Pi',callback_data: Math.PI.toFixed(2)}],[{text: '/',callback_data: '/'}],
[{text: '1',callback_data: 1}],[{text: '*',callback_data: '*'}],[{text: '+',callback_data: '+'}],
[{text: '2',callback_data: 2}],[{text: '3',callback_data: 3}],[{text: '4',callback_data: 4}],
[{text: '5',callback_data: 5}],[{text: '6',callback_data: 6}],
[{text: '7',callback_data: 7}], [{text: '8',callback_data: 8}],
[{text: '9',callback_data: 9}],
]
})
}
let x = () =>{
bot.on('message',info=>{
const text = info.text;
const chatId = info.chat.id
const user = info.chat.first_name;
bot.setMyCommands([
{command: '/start',description: 'Начало'},
{command: '/url',description: 'Логин создателя'},
{command: '/rad',description: 'Перевод из радиан в градусы'},
])
if(text === '/url'){
return bot.sendMessage(chatId,'Логин создателя: @spotzxc')
}
else if(text === '/start'){
return bot.sendMessage(chatId,`Добро пожаловать ${user}`);
}
else if(text === '/rad'){
return bot.sendMessage(chatId,'Введите число в градусах',radOptions);
};
return bot.sendMessage(chatId, `Я не понимаю вас${user}?Напишите понятно`)
});
bot.on('callback_query', info =>{
console.log(info)
const data = info.data
const chatId = info.message.chat.id
bot.sendMessage(chatId,`Ты выбрал ${data}`)
})
}
x();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question