Python telegram.ReplyKeyboardMarkup() Examples
The following are 30
code examples of telegram.ReplyKeyboardMarkup().
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
telegram
, or try the search function
.
Example #1
Source File: DisAtBot.py From DisAtBot with BSD 2-Clause "Simplified" License | 8 votes |
def start(bot, update): """ Start function. Displayed whenever the /start command is called. This function sets the language of the bot. """ # Create buttons to slect language: keyboard = [['ES', 'EN']] # Create initial message: message = "Hey, I'm DisAtBot! / ¡Hey, soy DisAtBot! \n\n\ Please select a language to start. / Por favor selecciona un idioma \ para comenzar." reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) update.message.reply_text(message, reply_markup=reply_markup) return SET_LANG
Example #2
Source File: telegram.py From lightnovel-crawler with Apache License 2.0 | 7 votes |
def show_crawlers_to_search(self, bot, update, user_data): app = user_data.get('app') buttons = [] def make_button(i, url): return '%d - %s' % (i + 1, urlparse(url).hostname) # end def for i in range(1, len(app.crawler_links) + 1, 2): buttons += [[ make_button(i - 1, app.crawler_links[i - 1]), make_button(i, app.crawler_links[i]) if i < len( app.crawler_links) else '', ]] # end for update.message.reply_text( 'Choose where to search for your novel, \n' 'or send /skip to search everywhere.', reply_markup=ReplyKeyboardMarkup(buttons, one_time_keyboard=True), ) return 'handle_crawler_to_search' # end def
Example #3
Source File: DisAtBot.py From DisAtBot with BSD 2-Clause "Simplified" License | 7 votes |
def menu(bot, update): """ Main menu function. This will display the options from the main menu. """ # Create buttons to slect language: keyboard = [[send_report[LANG], view_map[LANG]], [view_faq[LANG], view_about[LANG]]] reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) user = update.message.from_user logger.info("Menu command requested by {}.".format(user.first_name)) update.message.reply_text(main_menu[LANG], reply_markup=reply_markup) return SET_STAT
Example #4
Source File: worker.py From greed with GNU Affero General Public License v3.0 | 6 votes |
def __user_select(self) -> Union[db.User, CancelSignal]: """Select an user from the ones in the database.""" log.debug("Waiting for a user selection...") # Find all the users in the database users = self.session.query(db.User).order_by(db.User.user_id).all() # Create a list containing all the keyboard button strings keyboard_buttons = [[self.loc.get("menu_cancel")]] # Add to the list all the users for user in users: keyboard_buttons.append([user.identifiable_str()]) # Create the keyboard keyboard = telegram.ReplyKeyboardMarkup(keyboard_buttons, one_time_keyboard=True) # Keep asking until a result is returned while True: # Send the keyboard self.bot.send_message(self.chat.id, self.loc.get("conversation_admin_select_user"), reply_markup=keyboard) # Wait for a reply reply = self.__wait_for_regex("user_([0-9]+)", cancellable=True) # Propagate CancelSignals if isinstance(reply, CancelSignal): return reply # Find the user in the database user = self.session.query(db.User).filter_by(user_id=int(reply)).one_or_none() # Ensure the user exists if not user: self.bot.send_message(self.chat.id, self.loc.get("error_user_does_not_exist")) continue return user
Example #5
Source File: osmbot.py From osmbot with GNU General Public License v3.0 | 6 votes |
def settings_command(self, message, user_id, chat_id, u): """ Answers the settings command :param message: User message :param user_id: User identifier :param chat_id: Chat id :param u: Uers object :param group: Boolen to indicate if it's on a group :return: None """ if self.get_group(): text = self._get_template('question_only_mention.md').render() k = ReplyKeyboardMarkup([['Language'], [text]], one_time_keyboard=True) else: k = ReplyKeyboardMarkup([['Language']], one_time_keyboard=True) text = self._get_template('configure_question.md').render() self.telegram_api.sendMessage(chat_id, text, reply_markup=k) if self.get_group(): identifier = chat_id else: identifier = user_id u.set_field(identifier, 'mode', 'settings', group=self.get_group())
Example #6
Source File: osmbot.py From osmbot with GNU General Public License v3.0 | 6 votes |
def language_command(self, message, user_id, chat_id, user): """ Handles the Language command and sends the lis of languages :param message: the message sent by the user :param user_id: User id :param chat_id: Chat id :param user: Dict with user configuration :return: None """ languages = [[lang] for lang in sorted(self.get_languages().keys())] keyboard = ReplyKeyboardMarkup(languages, one_time_keyboard=True) text = self._get_template('language_answer.md').render() self.telegram_api.sendMessage(chat_id, text, reply_markup=keyboard) if self.get_group(): user.set_field(chat_id, 'mode', 'setlanguage', group=self.get_group()) else: user.set_field(user_id, 'mode', 'setlanguage', group=self.get_group())
Example #7
Source File: bismillah.py From BismillahBot with GNU Affero General Public License v3.0 | 6 votes |
def main(): global update_id bot = telegram.Bot(token=TOKEN) try: update_id = bot.get_updates()[0].update_id except IndexError: update_id = None interface = telegram.ReplyKeyboardMarkup( [["Arabic", "Audio", "English", "Tafsir"], ["Previous", "Random", "Next"]], resize_keyboard=True) data = { "english": Quran("translation"), "tafsir": Quran("tafsir"), "index": make_index(), "interface": interface } data["default_query_results"] = get_default_query_results(data["english"]) while True: try: serve(bot, data) except NetworkError: sleep(1) except Unauthorized: # user has removed or blocked the bot update_id += 1 except TelegramError as e: if "Invalid server response" in str(e): sleep(3) else: raise e
Example #8
Source File: worker.py From greed with GNU Affero General Public License v3.0 | 6 votes |
def __delete_product_menu(self): log.debug("Displaying __delete_product_menu") # Get the products list from the db products = self.session.query(db.Product).filter_by(deleted=False).all() # Create a list of product names product_names = [product.name for product in products] # Insert at the start of the list the Cancel button product_names.insert(0, self.loc.get("menu_cancel")) # Create a keyboard using the product names keyboard = [[telegram.KeyboardButton(product_name)] for product_name in product_names] # Send the previously created keyboard to the user (ensuring it can be clicked only 1 time) self.bot.send_message(self.chat.id, self.loc.get("conversation_admin_select_product_to_delete"), reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True)) # Wait for a reply from the user selection = self.__wait_for_specific_message(product_names, cancellable=True) if isinstance(selection, CancelSignal): # Exit the menu return else: # Find the selected product product = self.session.query(db.Product).filter_by(name=selection, deleted=False).one() # "Delete" the product by setting the deleted flag to true product.deleted = True self.session.commit() # Notify the user self.bot.send_message(self.chat.id, self.loc.get("success_product_deleted"))
Example #9
Source File: worker.py From greed with GNU Affero General Public License v3.0 | 6 votes |
def __add_credit_cc(self): """Add money to the wallet through a credit card payment.""" log.debug("Displaying __add_credit_cc") # Create a keyboard to be sent later presets = list(map(lambda s: s.strip(" "), configloader.config["Credit Card"]["payment_presets"].split('|'))) keyboard = [[telegram.KeyboardButton(str(utils.Price(preset, self.loc)))] for preset in presets] keyboard.append([telegram.KeyboardButton(self.loc.get("menu_cancel"))]) # Boolean variable to check if the user has cancelled the action cancelled = False # Loop used to continue asking if there's an error during the input while not cancelled: # Send the message and the keyboard self.bot.send_message(self.chat.id, self.loc.get("payment_cc_amount"), reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True)) # Wait until a valid amount is sent selection = self.__wait_for_regex(r"([0-9]+(?:[.,][0-9]+)?|" + self.loc.get("menu_cancel") + r")", cancellable=True) # If the user cancelled the action if isinstance(selection, CancelSignal): # Exit the loop cancelled = True continue # Convert the amount to an integer value = utils.Price(selection, self.loc) # Ensure the amount is within the range if value > utils.Price(int(configloader.config["Credit Card"]["max_amount"]), self.loc): self.bot.send_message(self.chat.id, self.loc.get("error_payment_amount_over_max", max_amount=utils.Price(configloader.config["Credit Card"]["max_amount"], self.loc))) continue elif value < utils.Price(int(configloader.config["Credit Card"]["min_amount"]), self.loc): self.bot.send_message(self.chat.id, self.loc.get("error_payment_amount_under_min", min_amount=utils.Price(configloader.config["Credit Card"]["min_amount"], self.loc))) continue break # If the user cancelled the action... else: # Exit the function return # Issue the payment invoice self.__make_payment(amount=value)
Example #10
Source File: telegram.py From lightnovel-crawler with Apache License 2.0 | 6 votes |
def range_selection_done(self, bot, update, user_data): app = user_data.get('app') update.message.reply_text( 'You have selected %d chapters to download' % len(app.chapters) ) if len(app.chapters) == 0: return self.display_range_selection_help(bot, update) # end if update.message.reply_text( 'Do you want to generate a single file or split the books into volumes?', reply_markup=ReplyKeyboardMarkup([ ['Single file', 'Split by volumes'] ], one_time_keyboard=True), ) return 'handle_pack_by_volume' # end def
Example #11
Source File: telegram.py From lightnovel-crawler with Apache License 2.0 | 6 votes |
def show_source_selection(self, bot, update, user_data): app = user_data.get('app') selected = user_data.get('selected') if len(selected['novels']) == 1: app.init_crawler(selected['novels'][0]['url']) return self.get_novel_info(bot, update, user_data) # end if update.message.reply_text( ('Choose a source to download "%s", ' % selected['title']) + 'or send /cancel to stop this session.', reply_markup=ReplyKeyboardMarkup([ [ '%d. %s %s' % ( index + 1, novel['url'], novel['info'] if 'info' in novel else '' ) ] for index, novel in enumerate(selected['novels']) ], one_time_keyboard=True), ) return 'handle_select_source' # end def
Example #12
Source File: compiler.py From superCodingBot with MIT License | 6 votes |
def filer(bot, update, user_data): file_id = update.message.document.file_id if ComHandler.check_file_size(update): return ConversationHandler.END newFile = bot.get_file(file_id) newFile.download('abcd.txt') with open('abcd.txt', 'r') as f: source = f.read() user_data['code'] = source custom_keyboard = [['#no test case', '#send a .txt file']] reply_markup = ReplyKeyboardMarkup(custom_keyboard, one_time_keyboard=True, resize_keybord=True) update.message.reply_text( 'Please send test cases together as you would do in online ide\nIf you dont want to provide test cases select #no test case\n I you want to send test cases as .txt file select #send a .txt file', reply_markup=reply_markup) # REMOVING THE FILE AFTER PROCESS IS COMPLETE os.remove('abcd.txt') return TESTCASES # FUNCTION TO GET THE SOURCE CODE SENT BY USER
Example #13
Source File: eastereggs.py From BotListBot with MIT License | 6 votes |
def send_next(bot, update, job_queue: JobQueue, args=None): uid = util.uid_from_update(update) num_rows = None if args: try: num_rows = int(args[0]) except: num_rows = None reply_markup = ReplyKeyboardMarkup( _crapPy_Tr0ll_kbmarkup(num_rows), one_time_keyboard=False, per_user=True ) text = "ɹoʇɐɹǝuǝb ǝɯɐuɹǝsn ɯɐɹbǝןǝʇ" util.send_md_message(bot, uid, text, reply_markup=reply_markup) if util.is_group_message(update): del_msg = bot.formatter.send_message( update.effective_chat.id, "Have fun in private ;)\n/easteregg" ) update.effective_message.delete() job_queue.run_once( lambda *_: del_msg.delete(safe=True), 4, name="delete easteregg hint" )
Example #14
Source File: favorites.py From BotListBot with MIT License | 6 votes |
def add_custom(bot, update, username): uid = util.uid_from_update(update) user = User.from_update(update) mid = util.mid_from_update(update) from components.basic import main_menu_buttons main_menu_markup = ReplyKeyboardMarkup(main_menu_buttons(uid in settings.MODERATORS)) try: fav = Favorite.get(custom_bot=username) util.send_or_edit_md_message( bot, uid, mdformat.none_action( "{} is already a favorite of yours. /favorites".format(fav.custom_bot)), to_edit=mid, reply_markup=main_menu_markup) except Favorite.DoesNotExist: fav = Favorite(user=user, custom_bot=username, date_added=datetime.date.today()) fav.save() msg = bot.formatter.send_or_edit(uid, mdformat.love("{} added to your /favorites.".format(fav.custom_bot)), to_edit=mid) mid = msg.message_id util.wait(bot, update) send_favorites_list(bot, update, to_edit=mid) return ConversationHandler.END
Example #15
Source File: addarr.py From Addarr with MIT License | 5 votes |
def choiceSerieMovie(update, context): if not checkId(update): if ( authentication(update, context) == "added" ): # To also stop the beginning command return ConversationHandler.END else: text = update.message.text context.user_data["title"] = text reply_keyboard = [[transcript["Movie"], transcript["Serie"]]] markup = ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True) update.message.reply_text(transcript["What is this?"], reply_markup=markup) return READ_CHOICE
Example #16
Source File: news_commands.py From UnivaqBot with MIT License | 5 votes |
def section_keyboard(bot, update): """ Command that shows keyboard of departments for: news, newson and newsoff """ keys = [['Univaq'], ['Disim'], ['Mesva'], ['Discab'], ['Chiudi']] bot.sendMessage(update.message.chat_id, 'Scegli il dipartimento:', reply_markup=telegram.ReplyKeyboardMarkup( keys, one_time_keyboard=True)) return "department"
Example #17
Source File: addarr.py From Addarr with MIT License | 5 votes |
def searchSerieMovie(update, context): title = context.user_data["title"] del context.user_data["title"] choice = update.message.text context.user_data["choice"] = choice context.user_data["position"] = 0 global service if choice == transcript["Serie"]: service = sonarr elif choice == transcript["Movie"]: service = radarr global output position = context.user_data["position"] output = service.giveTitles(service.search(title)) reply_keyboard = [ [transcript[choice.lower()]["Add"], transcript["Next result"]], [transcript["New"], transcript["Stop"]], ] markup = ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True) context.bot.send_message( chat_id=update.effective_message.chat_id, text=transcript[choice.lower()]["This"], ) context.bot.sendPhoto( chat_id=update.effective_message.chat_id, photo=output[position]["poster"] ) text = output[position]["title"] + " (" + str(output[position]["year"]) + ")" context.bot.send_message( chat_id=update.effective_message.chat_id, text=text, reply_markup=markup ) return GIVE_OPTION
Example #18
Source File: addarr.py From Addarr with MIT License | 5 votes |
def nextOption(update, context): position = context.user_data["position"] + 1 context.user_data["position"] = position choice = context.user_data["choice"] if position < len(output): reply_keyboard = [ [transcript[choice.lower()]["Add"], transcript["Next result"]], [transcript["New"], transcript["Stop"]], ] markup = ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True) context.bot.send_message( chat_id=update.effective_message.chat_id, text=transcript[choice.lower()]["This"], ) context.bot.sendPhoto( chat_id=update.effective_message.chat_id, photo=output[position]["poster"] ) text = output[position]["title"] + " (" + str(output[position]["year"]) + ")" context.bot.send_message( chat_id=update.effective_message.chat_id, text=text, reply_markup=markup ) return GIVE_OPTION else: context.bot.send_message( chat_id=update.effective_message.chat_id, text=transcript["No results"], reply_markup=markup, ) return stop()
Example #19
Source File: discab.py From UnivaqBot with MIT License | 5 votes |
def discab_keyboard(bot, update): """ Command that shows keyboard of sections for: discab_news, discabon and discaboff """ keys = [['News del Dipartimento'], ['Area Biotecnologie'], ['Area Medica'], ['Area Scienze Motorie'], ['Area Psicologia'], ['Chiudi']] bot.sendMessage(update.message.chat_id, 'Scegli la sezione:', reply_markup=telegram.ReplyKeyboardMarkup( keys, one_time_keyboard=True)) return "discab"
Example #20
Source File: dungeon_bot.py From dungeon_bot with GNU General Public License v2.0 | 5 votes |
def get_reply_markup(self, user): action = "show" ply = persistence_controller.get_ply(user) if user and str(user.id): if ply.event: if str(user.id) in ply.event.custom_keyboard_status.keys(): if ply.event.custom_keyboard_status[str(user.id)] == "close" or ply.event.custom_keyboard_status[str(user.id)] == "never show": action = "close" else: if str(user.id) in DungeonBot.custom_keyboard_status.keys(): if DungeonBot.custom_keyboard_status[str(user.id)] == "close" or DungeonBot.custom_keyboard_status[str(user.id)] == "never show": action = "close" markup = None keyboard = None if action == "show": if ply.event: keyboard = ply.event.get_keyboard(user) else: keyboard = self.get_keyboard(user) if keyboard: markup = ReplyKeyboardMarkup(keyboard) else: markup = ReplyKeyboardHide(True) return markup
Example #21
Source File: main.py From helpdeskbot with MIT License | 5 votes |
def start(bot, update): """ Shows an welcome message and help info about the available commands. """ me = bot.get_me() # Welcome message msg = _("Hello!\n") msg += _("I'm {0} and I came here to help you.\n").format(me.first_name) msg += _("What would you like to do?\n\n") msg += _("/support - Opens a new support ticket\n") msg += _("/settings - Settings of your account\n\n") # Commands menu main_menu_keyboard = [[telegram.KeyboardButton('/support')], [telegram.KeyboardButton('/settings')]] reply_kb_markup = telegram.ReplyKeyboardMarkup(main_menu_keyboard, resize_keyboard=True, one_time_keyboard=True) # Send the message with menu bot.send_message(chat_id=update.message.chat_id, text=msg, reply_markup=reply_kb_markup)
Example #22
Source File: main.py From helpdeskbot with MIT License | 5 votes |
def settings(bot, update): """ Configure the messages language using a custom keyboard. """ # Languages message msg = _("Please, choose a language:\n") msg += "en_US - English (US)\n" msg += "pt_BR - Português (Brasil)\n" # Languages menu languages_keyboard = [ [telegram.KeyboardButton('en_US - English (US)')], [telegram.KeyboardButton('pt_BR - Português (Brasil)')] ] reply_kb_markup = telegram.ReplyKeyboardMarkup(languages_keyboard, resize_keyboard=True, one_time_keyboard=True) # Sends message with languages menu bot.send_message(chat_id=update.message.chat_id, text=msg, reply_markup=reply_kb_markup)
Example #23
Source File: telegram_bot_demo.py From Lifeline_SilentNight with GNU General Public License v2.0 | 5 votes |
def createCustomKeyboards(bot, update): custom_keyboard = [[ telegram.Emoji.THUMBS_UP_SIGN, telegram.Emoji.THUMBS_DOWN_SIGN ]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) bot.sendMessage(chat_id=update.message.chat_id, text="Stay here, I'll be back.", reply_markup=reply_markup)
Example #24
Source File: lifeline_on_telegram.py From Lifeline_SilentNight with GNU General Public License v2.0 | 5 votes |
def sendChoice(self, ques, choice1, choice2): custom_keyboard = [[ choice1 ], [ choice2 ]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) self.bot.sendMessage(chat_id=self.update.message.chat_id, text=ques, parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=reply_markup) # ====================================================================
Example #25
Source File: lifeline_on_telegram.py From Lifeline_SilentNight with GNU General Public License v2.0 | 5 votes |
def setLang(bot, update): custom_keyboard = [[ "English", "Deutsch", "Français"], ["Русский", "日本語", "中文" ]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) bot.sendMessage(chat_id=update.message.chat_id, text="Language:", reply_markup=reply_markup)
Example #26
Source File: lifeline_on_telegram.py From Lifeline_SilentNight with GNU General Public License v2.0 | 5 votes |
def setAppleWatch(bot, update, lang): custom_keyboard = [[ STRINGS[lang]['dialog_notification_option_1'] ], [ STRINGS[lang]['dialog_notification_option_2'] ]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) bot.sendMessage(chat_id=update.message.chat_id, text=STRINGS[lang]['dialog_notification_settings'], reply_markup=reply_markup)
Example #27
Source File: lifeline_on_telegram.py From Lifeline_SilentNight with GNU General Public License v2.0 | 5 votes |
def setFastMode(bot, update, lang): custom_keyboard = [[ STRINGS[lang]['dialog_yes'] , STRINGS[lang]['dialog_no'] ]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) bot.sendMessage(chat_id=update.message.chat_id, text=STRINGS[lang]['dialog_fast_confirmation'], reply_markup=reply_markup)
Example #28
Source File: osmbot.py From osmbot with GNU General Public License v3.0 | 5 votes |
def answer_command(self, chat_id, user): """ Answers the only answer command :param message: User message :param user_id: User identifier :param chat_id: Chat id :param user: User object :return: """ keyboard = ReplyKeyboardMarkup([['Yes'], ['No']], one_time_keyboard=True) text = self._get_template('question_mention.md').render() self.telegram_api.sendMessage(chat_id, text, reply_markup=keyboard) user.set_field(chat_id, 'mode', 'setonlymention', group=True)
Example #29
Source File: univaq.py From UnivaqBot with MIT License | 5 votes |
def univaq(bot, update): """ Command that shows keyboard of sections for: inevidenza, ultimissime, univaqon, univaqoff """ keys = [['In Evidenza'], ['Ultimissime'], ['Chiudi']] bot.sendMessage(update.message.chat_id, 'Scegli la sezione:', reply_markup=telegram.ReplyKeyboardMarkup( keys, one_time_keyboard=True)) return "univaq"
Example #30
Source File: compiler.py From superCodingBot with MIT License | 5 votes |
def decode(bot, update, user_data): user_data['code'] = update.message.text custom_keyboard = [['#no test case', '#send a .txt file']] reply_markup = ReplyKeyboardMarkup(custom_keyboard, one_time_keyboard=True, resize_keybord=True) update.message.reply_text( 'Please send test cases together as you would do in online ide\nIf you dont want to provide test cases select #no test case\n I you want to send test cases as .txt file select #send a .txt file', reply_markup=reply_markup) return TESTCASES # FUNCTION TO GET THE TEST CASES FROM THE USER