Code Monkey home page Code Monkey logo

Comments (4)

kosmodrey avatar kosmodrey commented on September 25, 2024

Привет,

В папке examples есть множество примеров, в том числе и пример с клавиатурой и всеми видами кнопок. Его можно посмотреть тут: https://github.com/kosmodrey/telebot/blob/master/examples/keyboard.js

Если есть какие-то конкретные вопросы или непонимания, с радостью помогу разобраться.

from telebot.

Galy4a avatar Galy4a commented on September 25, 2024

Есть ли возможность создать кнопку команды с произвольным текстом?

from telebot.

kosmodrey avatar kosmodrey commented on September 25, 2024

К сожалению, сейчас Telegram не представляет такой возможности, но всегда можно что-нибудь придумать.

Я написал небольшой модуль, который вызывает команду если в callback кнопки будет прописан текст начинающейся с /.

Вот пример:

// Используем наш маленький модуль
bot.use(require('./cmdbutton.js'));

// При команде /start
bot.on('/start', msg => {

  // Создаём схему кнопок
  let markup = bot.inlineKeyboard([
    [
      // В первом ряду создаём встроенную кнопку с данными "/hello"
      bot.inlineButton('Моя команда', { callback: '/hello' }),
    ],
    [
      // Во втором ряду обычная кнопка с данными
      bot.inlineButton('Обычная кнопка', { callback: 'hello' })
    ]
  ]);

  // Отсылаем сообщение с встроенными кнопками
  return bot.sendMessage(msg.from.id, 'Пример команнрой кнопки.', { markup });

});

// При команде /hello
bot.on('/hello', msg => {
  return bot.sendMessage(msg.from.id, 'Привет!');
});

Теперь при нажатии на командную кнопку, будет вызываться команда /hello, ей можно придать любой текст.

from telebot.

Galy4a avatar Galy4a commented on September 25, 2024

Спасибо.

from telebot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.