Python telebot.TeleBot() Examples
The following are 30
code examples of telebot.TeleBot().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
telebot
, or try the search function
.
Example #1
Source File: SiteAlert.py From SiteAlert-Python with BSD 2-Clause "Simplified" License | 9 votes |
def __init__(self): self.__db = expanduser("~") + os.sep + "SiteAlert.db" if not os.path.isfile(self.__db): print("[WARNING]: No db found, creating a new one.") connection = sqlite3.connect(self.__db) connection.execute( "CREATE TABLE `SiteAlert` (`name` TEXT NOT NULL UNIQUE,`link` TEXT NOT NULL,`hash` TEXT NOT NULL,PRIMARY KEY(link));") connection.execute( "CREATE TABLE 'Registered'('name' TEXT NOT NULL,'mail' TEXT NOT NULL, PRIMARY KEY(name, mail));") connection.execute( "CREATE TABLE Users ('mail' TEXT NOT NULL, 'telegram' TEXT NOT NULL UNIQUE, 'mailnotification' BOOLEAN NOT NULL DEFAULT TRUE, 'telegramnotification' BOOLEAN NOT NULL DEFAULT TRUE, PRIMARY KEY (mail));") connection.close() self.__connection = sqlite3.connect(self.__db, check_same_thread=False) self.__header = [('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'), ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'), ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'), ('Accept-Encoding', 'none'), ('Accept-Language', 'en-US,en;q=0.8'), ('Connection', 'keep-alive')] self.__TOKEN = os.environ['SITE_ALERT_TOKEN'] self.__MAIL = os.environ['SITE_ALERT_MAIL'] self.__PSW = os.environ['SITE_ALERT_PASSWORD'] self.__tb = telebot.TeleBot(self.__TOKEN) self.saved_on_db()
Example #2
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 7 votes |
def test_default_middleware_handler(self): from telebot import apihelper apihelper.ENABLE_MIDDLEWARE = True tb = telebot.TeleBot('') update = self.create_message_update('/help') @tb.middleware_handler() def middleware(tb_instance, update): update.message.text = 'got' @tb.message_handler(func=lambda m: m.text == 'got') def command_handler(message): message.text = message.text + message.text tb.process_new_updates([update]) time.sleep(1) assert update.message.text == 'got' * 2
Example #3
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 6 votes |
def test_typed_middleware_handler(self): from telebot import apihelper apihelper.ENABLE_MIDDLEWARE = True tb = telebot.TeleBot('') update = self.create_message_update('/help') @tb.middleware_handler(update_types=['message']) def middleware(tb_instance, message): message.text = 'got' @tb.message_handler(func=lambda m: m.text == 'got') def command_handler(message): message.text = message.text + message.text tb.process_new_updates([update]) time.sleep(1) assert update.message.text == 'got' * 2
Example #4
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 6 votes |
def test_send_audio(self): file_data = open('./test_data/record.mp3', 'rb') tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram') assert ret_msg.content_type == 'audio' assert ret_msg.audio.performer == 'eternnoir' assert ret_msg.audio.title == 'pyTelegram'
Example #5
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_media_group(self): tb = telebot.TeleBot(TOKEN) img1 = 'https://i.imgur.com/CjXjcnU.png' img2 = 'https://i.imgur.com/CjXjcnU.png' medias = [types.InputMediaPhoto(img1, "View"), types.InputMediaPhoto(img2, "Dog")] result = tb.send_media_group(CHAT_ID, medias) assert len(result) == 2 assert result[0].media_group_id is not None assert result[0].media_group_id == result[1].media_group_id
Example #6
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_register_for_reply(self): text = 'CI reply_to Test Message' tb = telebot.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text, reply_markup=types.ForceReply()) reply_msg = tb.reply_to(msg, text + ' REPLY') def process_reply(message): assert msg.message_id == message.reply_to_message.message_id tb.register_for_reply(msg, process_reply) tb.process_new_messages([reply_msg])
Example #7
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_location_dis_noti(self): tb = telebot.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_location(CHAT_ID, lat, lon, disable_notification=True) assert int(ret_msg.location.longitude) == int(lon) assert int(ret_msg.location.latitude) == int(lat)
Example #8
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_venue(self): tb = telebot.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address") assert ret_msg.venue.title == "Test Venue" assert int(lat) == int(ret_msg.venue.location.latitude)
Example #9
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_venue_dis_noti(self): tb = telebot.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address", disable_notification=True) assert ret_msg.venue.title == "Test Venue"
Example #10
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_Chat(self): tb = telebot.TeleBot(TOKEN) me = tb.get_me() msg = tb.send_message(CHAT_ID, 'Test') assert me.id == msg.from_user.id assert msg.chat.id == int(CHAT_ID)
Example #11
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_edit_message_text(self): tb = telebot.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, 'Test') new_msg = tb.edit_message_text('Edit test', chat_id=CHAT_ID, message_id=msg.message_id) assert new_msg.text == 'Edit test'
Example #12
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_edit_message_media(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data_2 = open('../examples/detailed_example/rooster.jpg', 'rb') tb = telebot.TeleBot(TOKEN) msg = tb.send_photo(CHAT_ID, file_data) new_msg = tb.edit_message_media(chat_id=CHAT_ID, message_id=msg.message_id, media=types.InputMediaPhoto(file_data_2, caption='Test editMessageMedia 0')) assert type(new_msg) != bool new_msg = tb.edit_message_media(chat_id=CHAT_ID, message_id=msg.message_id, media=types.InputMediaPhoto(msg.photo[0].file_id, caption='Test editMessageMedia')) assert type(new_msg) != bool assert new_msg.caption == 'Test editMessageMedia'
Example #13
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_get_chat(self): tb = telebot.TeleBot(TOKEN) ch = tb.get_chat(GROUP_ID) assert str(ch.id) == GROUP_ID
Example #14
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_get_chat_administrators(self): tb = telebot.TeleBot(TOKEN) cas = tb.get_chat_administrators(GROUP_ID) assert len(cas) > 0
Example #15
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_get_chat_members_count(self): tb = telebot.TeleBot(TOKEN) cn = tb.get_chat_members_count(GROUP_ID) assert cn > 1
Example #16
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_edit_markup(self): text = 'CI Test Message' tb = telebot.TeleBot(TOKEN) markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True, reply_markup=markup) markup.add(types.InlineKeyboardButton("Google2", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Yahoo2", url="http://www.yahoo.com")) new_msg = tb.edit_message_reply_markup(chat_id=CHAT_ID, message_id=ret_msg.message_id, reply_markup=markup) assert new_msg.message_id
Example #17
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_forward_message_dis_noti(self): text = 'CI forward_message Test Message' tb = telebot.TeleBot(TOKEN) msg = tb.send_message(CHAT_ID, text) ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id, disable_notification=True) assert ret_msg.forward_from
Example #18
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_media_group_local_files(self): photo = open('../examples/detailed_example/kitten.jpg', 'rb') video = open('./test_data/test_video.mp4', 'rb') tb = telebot.TeleBot(TOKEN) medias = [types.InputMediaPhoto(photo, "View"), types.InputMediaVideo(video)] result = tb.send_media_group(CHAT_ID, medias) assert len(result) == 2 assert result[0].media_group_id is not None assert result[1].media_group_id is not None
Example #19
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_photo_formating_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_photo(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic'
Example #20
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_video_formatting_caption(self): file_data = open('./test_data/test_video.mp4', 'rb') tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic'
Example #21
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_audio_formatting_caption(self): file_data = open('./test_data/record.mp3', 'rb') tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_audio(CHAT_ID, file_data, caption='<b>bold</b>', parse_mode='HTML') assert ret_msg.caption_entities[0].type == 'bold'
Example #22
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_media_group_formatting_caption(self): tb = telebot.TeleBot(TOKEN) img1 = 'https://i.imgur.com/CjXjcnU.png' img2 = 'https://i.imgur.com/CjXjcnU.png' medias = [types.InputMediaPhoto(img1, "*View*", parse_mode='Markdown'), types.InputMediaPhoto(img2, "_Dog_", parse_mode='Markdown')] result = tb.send_media_group(CHAT_ID, medias) assert len(result) == 2 assert result[0].media_group_id is not None assert result[0].caption_entities[0].type == 'bold' assert result[1].caption_entities[0].type == 'italic'
Example #23
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_document_formating_caption(self): file_data = open('../examples/detailed_example/kitten.jpg', 'rb') tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_document(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') assert ret_msg.caption_entities[0].type == 'italic'
Example #24
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_chat_permissions(self): return # CHAT_ID is private chat, no permissions can be set tb = telebot.TeleBot(TOKEN) permissions = types.ChatPermissions(can_send_messages=True, can_send_polls=False) msg = tb.set_chat_permissions(CHAT_ID, permissions)
Example #25
Source File: bot.py From DeepPavlov with Apache License 2.0 | 5 votes |
def start(self) -> None: """Starts polling messages from Telegram, routes messages to handlers.""" bot = telebot.TeleBot(self._token) bot.remove_webhook() @bot.message_handler(commands=['start']) def send_start_message(message: telebot.types.Message) -> None: chat_id = message.chat.id out_message = self._conversation_config['start_message'] bot.send_message(chat_id, out_message) @bot.message_handler(commands=['help']) def send_help_message(message: telebot.types.Message) -> None: chat_id = message.chat.id out_message = self._conversation_config['help_message'] bot.send_message(chat_id, out_message) @bot.message_handler() def handle_inference(message: telebot.types.Message) -> None: chat_id = message.chat.id context = message.text if chat_id not in self._conversations: self._conversations[chat_id] = \ TelegramConversation(config=self._conversation_config, model=self._model, self_destruct_callback=self._del_conversation, conversation_id=chat_id) conversation = self._conversations[chat_id] response = conversation.handle_request(context) bot.send_message(chat_id, response) bot.polling()
Example #26
Source File: telegram.py From simple-monitor-alert with MIT License | 5 votes |
def init(self): token = self.config.get('token') self.bot = telebot.TeleBot(token) self.telegram_cache = JSONFile(create_file(os.path.join(get_var_directory(), 'telegram-cache.json'), { 'chat_ids': {}, 'version': __version__, })) # print([vars(u.message.chat) for u in updates])
Example #27
Source File: main.py From Vk-to-telegram-transfer-bot with GNU General Public License v3.0 | 5 votes |
def init_telegram(): module.bot = telebot.TeleBot( config.getCell( 'telegram_token' ) ) print( "Successfully loginned in telegram!") input_telegram()
Example #28
Source File: telegram_bot.py From TheSpaghettiDetective with GNU Affero General Public License v3.0 | 5 votes |
def telegram_bot(): bot = None if settings.TELEGRAM_BOT_TOKEN: bot = TeleBot(settings.TELEGRAM_BOT_TOKEN) return bot
Example #29
Source File: test_telebot.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def test_send_video_more_params(self): file_data = open('./test_data/test_video.mp4', 'rb') tb = telebot.TeleBot(TOKEN) ret_msg = tb.send_video(CHAT_ID, file_data, 1) assert ret_msg.message_id
Example #30
Source File: detailed_example.py From pyTelegramBotAPI with GNU General Public License v2.0 | 5 votes |
def listener(messages): """ When new messages arrive TeleBot will call this function. """ for m in messages: if m.content_type == 'text': # print the sent message to the console print(str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text)