S
S
spoT12021-10-25 15:17:29
Node.js
spoT1, 2021-10-25 15:17:29

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();


How can I make the user enter a value in radians and return it in degrees

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vovash, 2021-10-25
@V0vash

function radians_to_degrees(radians)
{
  const pi = Math.PI;
  return radians * (180/pi);
}
          
console.log(radians_to_degrees(0.7853981633974483)); //=> 45

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question