我们从Python开源项目中,提取了以下30个代码示例,用于说明如何使用telegram.ReplyKeyboardRemove()。
def discab_news(bot, update, section): """Defining function that prints 5 news from discab given section""" news_to_string = "" for i, item in enumerate(utils.NEWS[section]): news_to_string += (str(i + 1) + ' - <a href="{link}">{title}</a>\n\n').format(**item) news_to_string += ('<a href="http://discab.univaq.it/index.php?id=2004">' 'Vedi le altre notizie</a> e attiva le notifiche con /newson per ' 'restare sempre aggiornato') bot.sendMessage(update.message.chat_id, parse_mode='HTML', disable_web_page_preview=True, text=news_to_string, reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def mesva_news(bot, update, section): """Defining function that prints 5 news from mesva given section""" news_to_string = "" for i, item in enumerate(utils.NEWS[section]): news_to_string += (str(i + 1) + ' - <a href="{link}">{title}</a>\n\n').format(**item) news_to_string += ('<a href="http://mesva.univaq.it/">' 'Vedi le altre notizie</a> e attiva le notifiche con /newson per ' 'restare sempre aggiornato') bot.sendMessage(update.message.chat_id, parse_mode='HTML', disable_web_page_preview=True, text=news_to_string, reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def inevidenza(bot, update): """Defining function that prints 5 news from in evidenza""" news_to_string = "" for i, item in enumerate(utils.NEWS['univaq'][0:5]): news_to_string += (str(i + 1) + ' - <a href="{link}">{title}</a>\n\n').format(**item) news_to_string += ('<a href="http://www.univaq.it">' 'Vedi le altre notizie</a> e attiva le notifiche con /newson per ' 'restare sempre aggiornato') bot.sendMessage(update.message.chat_id, parse_mode='HTML', disable_web_page_preview=True, text=news_to_string, reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def ultimissime(bot, update): """Defining function that prints 5 news from ultimissime""" news_to_string = "" for i, item in enumerate(utils.NEWS['univaq'][5:10]): news_to_string += (str(i + 1) + ' - <a href="{link}">{title}</a>\n\n').format(**item) news_to_string += ('<a href="http://www.univaq.it">' 'Vedi le altre notizie</a> e attiva le notifiche con /newson per ' 'restare sempre aggiornato') bot.sendMessage(update.message.chat_id, parse_mode='HTML', disable_web_page_preview=True, text=news_to_string, reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def send_to_developers(bot, update): """Function to send feedback to developers""" feedback_user = (('<b>{}</b>\n\n <i>{} {}, {}</i>') .format(update.message.text, update.message.from_user.first_name, update.message.from_user.last_name, update.message.chat_id)) for admin in os.environ['ADMIN'].split(' '): bot.sendMessage(admin, feedback_user, parse_mode='HTML') bot.sendMessage(update.message.chat_id, 'Grazie per la collaborazione, ' 'il messaggio è stato inviato agli sviluppatori.', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def hide_keyboard(bot, chat_id, text): reply_markup = ReplyKeyboardRemove() try: bot.sendMessage(chat_id=chat_id, text=text, reply_markup=reply_markup) except: sleep(1) bot.sendMessage(chat_id=chat_id, text=text, reply_markup=reply_markup)
def start_anketa(bot, update, user_data): update.message.reply_text("????????, ??? ??? ?????.", reply_markup=ReplyKeyboardRemove()) return "name"
def cancel(bot, update): message = update.message bot.sendMessage(chat_id=message.chat_id, text=_('Global text has been cancelled.'), reply_to_message_id=message.message_id, reply_markup=ReplyKeyboardRemove(selective=True)) return ConversationHandler.END
def new_in_state_asked_channel_access(bot, update): update.message.reply_text('??????. ????????? ????? ????????? ?? ??????', reply_markup=ReplyKeyboardRemove()) return ASKED_CHANNEL_MESSAGE_IN_NEW
def cancel_new(bot, update, users_state): update.message.reply_text('?????', reply_markup=ReplyKeyboardRemove()) update.message.reply_text('??????? /new ???????? ????? ?????') del_state(update, users_state) return ConversationHandler.END
def cancel_filter_by_hashtag(bot, update, users_state): update.message.reply_text('?????', reply_markup=ReplyKeyboardRemove()) update.message.reply_text('????????? ?????? ?? ???????? ????? ???????? /filter_by_hashtag') update.message.reply_text('??????? /new ???????? ????? ?????') del_state(update, users_state) return ConversationHandler.END
def cancel_recover(bot, update, users_state): update.message.reply_text('?????', reply_markup=ReplyKeyboardRemove()) update.message.reply_text('??????? /new ???????? ????? ?????') del_state(update, users_state) return ConversationHandler.END
def discabon(bot, update, section): """Defining the command to enable notification for discab""" if update.message.chat_id not in utils.USERS[section]: utils.subscribe_user(update.message.chat_id, section) bot.sendMessage(update.message.chat_id, text='Notifiche Abilitate!', reply_markup=telegram.ReplyKeyboardRemove()) else: bot.sendMessage(update.message.chat_id, text='Le notifiche sono già abilitate!', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def discaboff(bot, update, section): """Defining the command to disable notification for discab""" if update.message.chat_id in utils.USERS[section]: utils.unsubscribe_user(update.message.chat_id, section) bot.sendMessage(update.message.chat_id, text='Notifiche Disattivate!', reply_markup=telegram.ReplyKeyboardRemove()) else: bot.sendMessage(update.message.chat_id, text='Per disattivare le notifiche dovresti prima attivarle.', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def mesvaon(bot, update, section): """Defining the command to enable notification for mesva""" if update.message.chat_id not in utils.USERS[section]: utils.subscribe_user(update.message.chat_id, section) bot.sendMessage(update.message.chat_id, text='Notifiche Abilitate!', reply_markup=telegram.ReplyKeyboardRemove()) else: bot.sendMessage(update.message.chat_id, text='Le notifiche sono già abilitate!', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def disim(bot, update): """Defining the command to retrieve 5 news Now we store the last 10 news into the database, the comparison to send notifications is made between the last 5 pulled news from disim site and the news stored into the db. This decision was made to avoid repeated news, in fact, if some news(from first to fifth) is deleted the sixth(that now has become the fifth) news will be sent again even if it is already been sent in the past because it will appear in the pulled news and it is no more present into the database at the moment of the comparison. """ news_to_string = "" for i, item in enumerate(utils.NEWS['disim'][0:5]): suffix = '...' if len(item['description']) > 75 else '' news_to_string += (str(i + 1) + ' - <a href="{link}">{title}</a>\n' '\t<i>{description:.75}{}</i>\n\n').format(suffix, **item) news_to_string += ('<a href="http://www.disim.univaq.it/main/news.php?entrant=1">' 'Vedi le altre notizie</a> e attiva le notifiche con /newson per ' 'restare sempre aggiornato') bot.sendMessage(update.message.chat_id, parse_mode='HTML', disable_web_page_preview=True, text=news_to_string, reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def disimon(bot, update): """Defining the command to enable notification for disim""" if update.message.chat_id not in utils.USERS['disim']: utils.subscribe_user(update.message.chat_id, 'disim') bot.sendMessage(update.message.chat_id, text='Notifiche Abilitate!', reply_markup=telegram.ReplyKeyboardRemove()) else: bot.sendMessage(update.message.chat_id, text='Le notifiche sono già abilitate!', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def disimoff(bot, update): """Defining the command to disable notification for disim""" if update.message.chat_id in utils.USERS['disim']: utils.unsubscribe_user(update.message.chat_id, 'disim') bot.sendMessage(update.message.chat_id, text='Notifiche Disattivate!', reply_markup=telegram.ReplyKeyboardRemove()) else: bot.sendMessage(update.message.chat_id, text='Per disattivare le notifiche dovresti prima attivarle.', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def univaqoff(bot, update): """Defining the command to disable notification for univaq""" if update.message.chat_id in utils.USERS['univaq']: utils.unsubscribe_user(update.message.chat_id, 'univaq') bot.sendMessage(update.message.chat_id, text='Notifiche Disattivate!', reply_markup=telegram.ReplyKeyboardRemove()) else: bot.sendMessage(update.message.chat_id, text='Per disattivare le notifiche dovresti prima attivarle.', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def close(bot, update): """Defining Function for remove keyboard""" bot.sendMessage(update.message.chat_id, 'Ho chiuso le news!', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def close(bot, update): """Defining Function for remove keyboard""" bot.sendMessage(update.message.chat_id, 'Davvero non vuoi nemmeno salutarci? Che peccato...', reply_markup=telegram.ReplyKeyboardRemove()) return ConversationHandler.END
def process_asking(self, bot, update): if update.message.text == 'Yes': bot.send_message(chat_id=config.TELEGRAM_CHAT_ID, text='Starting to record notes for this meeting:', reply_markup=telegram.ReplyKeyboardRemove()) self.state = 'memo' elif update.message.text in ['No', 'Later']: bot.send_message(chat_id=config.TELEGRAM_CHAT_ID, text='Okay.', reply_markup=telegram.ReplyKeyboardRemove()) self.is_done_ = True else: # didn't understand answer, ask again self.ask_if_desired(bot)
def process(self, bot, update): if update.message.text == 'Yes': print('Trying to send a mail') print(self.email.__dict__) send_email(self.email) bot.send_message(chat_id=update.message.chat_id, text='Okay, I have sent the mail successfully.', reply_markup=telegram.ReplyKeyboardRemove()) else: bot.send_message(chat_id=update.message.chat_id, text='Okay, I will not send a mail.', reply_markup=telegram.ReplyKeyboardRemove()) self.is_done_ = True
def trade_currency(bot, update, chat_data): chat_data["currency"] = update.message.text reply_msg = "Enter price per unit" reply_mrk = ReplyKeyboardRemove() update.message.reply_text(reply_msg, reply_markup=reply_mrk) return WorkflowEnum.TRADE_PRICE # Save price per unit and choose how to enter the # trade volume (euro, volume or all available funds)
def trade_vol_type(bot, update, chat_data): chat_data["vol_type"] = update.message.text reply_msg = "Enter volume" reply_mrk = ReplyKeyboardRemove() update.message.reply_text(reply_msg, reply_markup=reply_mrk) return WorkflowEnum.TRADE_VOLUME # Volume type 'ALL' chosen - meaning that # all available EURO funds will be used
def funding_withdraw(bot, update): update.message.reply_text("Enter target wallet name", reply_markup=ReplyKeyboardRemove()) return WorkflowEnum.WITHDRAW_WALLET
def shutdown_cmd(bot, update): update.message.reply_text("Shutting down...", reply_markup=ReplyKeyboardRemove()) # See comments on the 'shutdown' function threading.Thread(target=shutdown).start() # Restart this python script
def restart_cmd(bot, update): update.message.reply_text("Bot is restarting...", reply_markup=ReplyKeyboardRemove()) time.sleep(0.2) os.execl(sys.executable, sys.executable, *sys.argv) # Get current settings
def assertBotResponse(self, mock_send, command): args, kwargs = mock_send.call_args self.assertEqual(1, mock_send.call_count) self.assertEqual(kwargs['chat_id'], self.update.message.chat.id) self.assertEqual(kwargs['parse_mode'], command['out']['parse_mode']) if not command['out']['reply_markup']: self.assertTrue(isinstance(kwargs['reply_markup'], ReplyKeyboardRemove)) else: self.assertInKeyboard(command['out']['reply_markup'], kwargs['reply_markup'].keyboard) if not PY3: kwargs['text'] = kwargs['text'].decode('utf-8') self.assertIn(command['out']['text'], kwargs['text'])
def render(self): keyboard = super(KeyboardResponse, self).render() if keyboard: keyboard = ast.literal_eval(keyboard) keyboard = ReplyKeyboardMarkup(keyboard, resize_keyboard=True) else: keyboard = ReplyKeyboardRemove() return keyboard