3
3
3err02019-12-18 12:08:35
Python
3err0, 2019-12-18 12:08:35

How to implement command line send support for a bot with polling support in telebot?

Hello.
Currently there is a bot that sits on one of the channels to which messages are sent via the command line:

import telebot,sys

BOT_TOKEN='00000000000'
MESSAGE=sys.argv[1]

MESSAGE = MESSAGE.replace('/n','\n')
tb = telebot.TeleBot(BOT_TOKEN)
tb.send_message("chatid" ,"SUBJECT" + '\n' + MESSAGE)

Having a ready-made bot example available, I wondered if it was possible to implement the same implementation of command line support, but for the bot to wait for a button press in each of the messages sent via the command line, by running polling only once (without restarting the bot):
import telebot
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton

TELEGRAM_TOKEN = '<TOKEN>'

bot = telebot.TeleBot(TELEGRAM_TOKEN)

def gen_markup():
    markup = InlineKeyboardMarkup()
    markup.row_width = 2
    markup.add(InlineKeyboardButton("Yes", callback_data="cb_yes"),
                               InlineKeyboardButton("No", callback_data="cb_no"))
    return markup

@bot.callback_query_handler(func=lambda call: True)
def callback_query(call):
    if call.data == "cb_yes":
        bot.answer_callback_query(call.id, "Answer is Yes")
    elif call.data == "cb_no":
        bot.answer_callback_query(call.id, "Answer is No")

@bot.message_handler(func=lambda message: True)
def message_handler(message):
    bot.send_message(message.chat.id, "Yes/no?", reply_markup=gen_markup())

bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question