Created
January 11, 2021 12:03
-
-
Save rabbitix/b2b93ca35e9aaaefe0a38c79e3ca46a0 to your computer and use it in GitHub Desktop.
PTB init bot with proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from telegram.ext import (Updater, Dispatcher, ConversationHandler, CommandHandler, | |
MessageHandler, RegexHandler, Filters, | |
CallbackContext,) | |
from telegram import Update, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, ReplyMarkup | |
import requests | |
logging.basicConfig( | |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG | |
) | |
logger = logging.getLogger(__name__) | |
def error(update, errorMsg): | |
logger.warning('Update "%s" caused "%s" ', update, errorMsg) | |
class Bot: | |
def __init__(self, token): | |
REQ = { | |
'proxy_url': 'socks5h://127.0.0.1:9050', | |
'urllib3_proxy_kwargs': { | |
'username': '1', | |
'password': '1', | |
}, | |
'connect_timeout': 200, | |
} | |
self.updater = Updater( | |
token=token, use_context=True, request_kwargs=REQ) | |
self.dispatcher = self.updater.dispatcher | |
self.dispatcher.add_error_handler(error) | |
start = CommandHandler('start', self.start) | |
self.dispatcher.add_handler(start) | |
def start(self, update: Update, context: CallbackContext): | |
update.message.reply_text('hi') | |
def run(self): | |
self.updater.start_polling() | |
self.updater.idle() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment