Example #1
0
def run_bot():
    updater = Updater(bot_token)
    dispatcher = updater.dispatcher
    start_cmd_handler = CommandHandler('start', start)
    en_cmd_handler = CommandHandler('en', eng)
    hn_cmd_handler = CommandHandler('hi', hin)
    cn_cmd_handler = CommandHandler('cn', chn)
    es_cmd_handler = CommandHandler('es', esp)
    audio_handler = MessageHandler(Filters.voice, audio_msg)
    message_handler = MessageHandler(Filters.text, message)
    unknown_handler = MessageHandler(Filters.command, not_defined)

    #adding handlers in the dispatcher
    dispatcher.add_handler(start_cmd_handler)
    dispatcher.add_handler(en_cmd_handler)
    dispatcher.add_handler(hn_cmd_handler)
    dispatcher.add_handler(cn_cmd_handler)
    dispatcher.add_handler(es_cmd_handler)
    dispatcher.add_handler(unknown_handler)
    dispatcher.add_handler(message_handler)
    dispatcher.add_handler(audio_handler)
    dispatcher.add_error_handler(error_handler)
    #this command is used to start the bot
    updater.start_polling()
    #this is used to keep the bot idle
    updater.idle()
Example #2
0
def main():
    updater = Updater('YOUR_TOKEN')
    dp = updater.dispatcher
    dp.add_handler(CommandHandler('pic', pic))
    dp.add_handler(CommandHandler('hello', hello))
    updater.start_polling()
    updater.idle()
Example #3
0
def main():
    updater = Updater(token=BOT_ID, use_context=True)
    dispatcher = updater.dispatcher
    start_handler = CommandHandler('start', start)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(CommandHandler('status', check_server))
    dispatcher.add_handler(CommandHandler('refresh', refresh_library))
    dispatcher.add_handler(CommandHandler('backup', make_backup))
    updater.start_polling()
    updater.idle()
Example #4
0
def main() -> None:
    """Run the bot."""

    #updater = Updater("")
    token = os.environ['TOKEN']

    bot = telegram.Bot(token=token)

    updater = Updater(token=token, use_context=True)

    dispatcher = updater.dispatcher

    conv_handler = ConversationHandler(
        entry_points=[CommandHandler('start', start)],
        states={
            FIRST: [
                CallbackQueryHandler(mueb, pattern='^' + str(MUEB) + '$'),
                CallbackQueryHandler(carp, pattern='^' + str(CARP) + '$'),
                CallbackQueryHandler(three, pattern='^' + str(THREE) + '$'),
                CallbackQueryHandler(four, pattern='^' + str(FOUR) + '$'),
                CallbackQueryHandler(cmg, pattern='^' + str(CMG) + '$'),
                CallbackQueryHandler(sj2, pattern='^' + str(SJ2) + '$'),
                CallbackQueryHandler(sm3, pattern='^' + str(SM3) + '$'),
                CallbackQueryHandler(mcud, pattern='^' + str(MCUD) + '$'),
                CallbackQueryHandler(pc, pattern='^' + str(PC) + '$'),
                CallbackQueryHandler(pr, pattern='^' + str(PR) + '$'),
                CallbackQueryHandler(botll, pattern='^' + str(BOTLL) + '$'),
                CallbackQueryHandler(ban, pattern='^' + str(BAN) + '$'),
                CallbackQueryHandler(banq, pattern='^' + str(BANQ) + '$'),
                CallbackQueryHandler(barr, pattern='^' + str(BARR) + '$'),
                CallbackQueryHandler(bjm, pattern='^' + str(BJM) + '$'),
                CallbackQueryHandler(cam, pattern='^' + str(CAM) + '$'),
                CallbackQueryHandler(clt, pattern='^' + str(CLT) + '$'),
                CallbackQueryHandler(cun, pattern='^' + str(CUN) + '$'),
                CallbackQueryHandler(rep, pattern='^' + str(REP) + '$'),
                CallbackQueryHandler(mes, pattern='^' + str(MES) + '$'),
                CallbackQueryHandler(sill, pattern='^' + str(SILL) + '$'),
                CallbackQueryHandler(jcom, pattern='^' + str(JCOM) + '$'),
                CallbackQueryHandler(balanc, pattern='^' + str(BALANC) + '$'),
                CallbackQueryHandler(sillp, pattern='^' + str(SILLP) + '$'),
            ],
            SECOND: [
                CallbackQueryHandler(start_over,
                                     pattern='^' + str(MUEB) + '$'),
                CallbackQueryHandler(end, pattern='^' + str(CARP) + '$'),
            ],
        },
        fallbacks=[CommandHandler('start', start)],
    )

    dispatcher.add_handler(conv_handler)

    updater.start_polling()

    updater.idle()
Example #5
0
def run_bot():
    updater = Updater(bot_token)
    dispatcher = updater.dispatcher
    start_cmd_handler = CommandHandler('start', start)
    #date_handler = CommandHandler('date', current_date)
    #translation_handler = CommandHandler('movie', movie)
    audio_handler = MessageHandler(Filters.voice, audio_msg)
    message_handler = MessageHandler(Filters.text, message)
    unknown_handler = MessageHandler(Filters.command, not_defined)
    
    #adding handlers in the dispatcher
    dispatcher.add_handler(start_cmd_handler)
    #dispatcher.add_handler(translation_handler)
    #dispatcher.add_handler(date_handler)
    dispatcher.add_handler(unknown_handler)
    dispatcher.add_handler(message_handler)
    dispatcher.add_handler(audio_handler)
    dispatcher.add_error_handler(error_handler)
    #this command is used to start the bot
    updater.start_polling()
    #this is used to keep the bot idle
    updater.idle()
Example #6
0
def main():

    # Start the Bot
    updater.start_polling()
    updater.idle()
Example #7
0
# -*- coding: utf-8 -*-

import sys
print (sys.path)
#sys.path.append(", ")
sys.path.append("D:\\libs\\python-telegram-bot-master")
print ('\n')
print (sys.path)

#    ВНИМАНИЕ!!! В СТУДИИ НЕ РАБОТАЕТ ПОЧЕМУ ТО, НО КОГДА Я ПЫТАЛСЯ СДЕЛАТЬ ЧЕРЕЗ NOTEPAD И CMD ВСЕ БЫЛО ОК, А ЕЩЕ ЕСЛИ ПРОБОВАТЬ ЗАПУСТИТЬ НАДО СВОЙ API ВВЕСТИ В 11 СТРОКЕ
from telegram.ext import updater, commandhandler, messagehandler, filters
updater = updater(token='748241724:AAEVNa8haMmAhNwjV5aUiOGEQDiOQhu4VS8') # токен api к telegram, его можно взять у botFather
dispatcher = updater.dispatcher

def startCommand(bot, update):
    bot.send_message(chat_id=update.message.chat_id, text='Привет, давай пообщаемся?')
def textMessage(bot, update):
    response = 'Получил Ваше сообщение: ' + update.message.text
    bot.send_message(chat_id=update.message.chat_id, text=response)
    # Хендлеры
start_command_handler = CommandHandler('start', startCommand)
text_message_handler = MessageHandler(Filters.text, textMessage)
# Добавляем хендлеры в диспетчер
dispatcher.add_handler(start_command_handler)
dispatcher.add_handler(text_message_handler)
# Начинаем поиск обновлений
updater.start_polling(clean=True)

# Останавливаем бота, если были нажаты Ctrl + C
updater.idle()