Python telegram.InlineQueryResultArticle() Examples
The following are 10
code examples of telegram.InlineQueryResultArticle().
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: inlinequeries.py From BotListBot with MIT License | 7 votes |
def bot_article(b): txt = '{} ➡️ {}'.format(messages.rand_call_to_action(), b.detail_text) txt += '\n\n' + messages.PROMOTION_MESSAGE buttons = [ [InlineKeyboardButton(captions.ADD_TO_FAVORITES, callback_data=util.callback_for_action( const.CallbackActions.ADD_TO_FAVORITES, {'id': b.id, 'discreet': True}))]] reply_markup = InlineKeyboardMarkup(buttons) return InlineQueryResultArticle( id=uuid4(), title=b.str_no_md, input_message_content=InputTextMessageContent(message_text=txt, parse_mode=ParseMode.MARKDOWN), description=b.description if b.description else b.name if b.name else None, reply_markup=reply_markup # thumb_url='http://www.colorcombos.com/images/colors/FF0000.png' )
Example #2
Source File: inlinequeries.py From rules-bot with GNU Affero General Public License v3.0 | 5 votes |
def article(title='', description='', message_text='', key=None, reply_markup=None): return InlineQueryResultArticle( id=key or uuid4(), title=title, description=description, input_message_content=InputTextMessageContent( message_text=message_text, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True), reply_markup=reply_markup )
Example #3
Source File: inlinequeries.py From BotListBot with MIT License | 5 votes |
def query_too_short_article(): txt = '[I am a stupid, crazy fool.](https://www.youtube.com/watch?v=DLzxrzFCyOs)' return InlineQueryResultArticle( id=uuid4(), title=util.action_hint('Your search term must be at least {} characters long.'.format( SEARCH_QUERY_MIN_LENGTH)), input_message_content=InputTextMessageContent(message_text=txt, parse_mode="Markdown", disable_web_page_preview=True) )
Example #4
Source File: inlinequeries.py From BotListBot with MIT License | 5 votes |
def category_article(cat): cat_bots = Bot.of_category_without_new(cat) txt = messages.PROMOTION_MESSAGE + '\n\n' txt += "There are *{}* bots in the category *{}*:\n\n".format(len(cat_bots), str(cat)) txt += '\n'.join([str(b) for b in cat_bots]) return InlineQueryResultArticle( id=uuid4(), title=emoji.emojize(cat.emojis, use_aliases=True) + cat.name, input_message_content=InputTextMessageContent(message_text=txt, parse_mode=ParseMode.MARKDOWN), description=cat.extra, # thumb_url='https://pichoster.net/images/2017/03/13/cfa5e29e29e772373242bc177a9e5479.jpg' )
Example #5
Source File: inlinequeries.py From BotListBot with MIT License | 5 votes |
def all_bot_results_article(lst, too_many_results): txt = messages.PROMOTION_MESSAGE + '\n\n' txt += "{} one of these {} bots:\n\n".format(messages.rand_call_to_action(), len(lst)) txt += '\n'.join([str(b) for b in lst]) return InlineQueryResultArticle( id=uuid4(), title='{} {} ʙᴏᴛ ʀᴇsᴜʟᴛs'.format( mdformat.smallcaps("Send"), len(lst)), input_message_content=InputTextMessageContent(message_text=txt[:4096], parse_mode=ParseMode.MARKDOWN) # description=b.description if b.description else b.name if b.name else None, # thumb_url='http://www.colorcombos.com/images/colors/FF0000.png' )
Example #6
Source File: inlinequeries.py From BotListBot with MIT License | 5 votes |
def hint_article(msg, reply_markup, key): return InlineQueryResultArticle( id=uuid4(), title=key.replace('#', '').capitalize() + ' hint', input_message_content=InputTextMessageContent( message_text=msg, parse_mode="Markdown", disable_web_page_preview=True ), reply_markup=reply_markup )
Example #7
Source File: bot.py From sudobot with MIT License | 5 votes |
def inlinequery(bot, update): query = update.inline_query.query o = execute(query, update, direct=False) results = list() results.append(InlineQueryResultArticle(id=uuid4(), title=query, description=o, input_message_content=InputTextMessageContent( '*{0}*\n\n{1}'.format(query, o), parse_mode="Markdown"))) bot.answerInlineQuery(update.inline_query.id, results=results, cache_time=10)
Example #8
Source File: bismillah.py From BismillahBot with GNU Affero General Public License v3.0 | 5 votes |
def get_default_query_results(quran: Quran): results = [] ayat = [ (13, 28), (33, 56), (2, 62), (10, 31), (17, 36), (5, 32), (39, 9), (17, 44), (28, 88), (17, 84), (33, 6), (7, 57), (3, 7), (2, 255), (63, 9), (57, 20), (49, 12), (16, 125), (24, 35), (73, 8), (4, 103) ] for s, a in ayat: ayah = "%d:%d" % (s, a) english = quran.get_ayah(s, a) results.append(InlineQueryResultArticle( ayah + "def", title=ayah, description=english[:120], input_message_content=InputTextMessageContent(english)) ) return results
Example #9
Source File: telegrambot.py From OpenCryptoBot with GNU Affero General Public License v3.0 | 4 votes |
def _inline(self, bot, update): query = update.inline_query.query if not query or not query.startswith("/") or not query.endswith("."): return def _send(msg, description=None): if not description: description = str(msg) content = InputTextMessageContent(str(msg), parse_mode=ParseMode.MARKDOWN) inline_result = InlineQueryResultArticle( id=uuid.uuid4(), title=description, input_message_content=content) bot.answer_inline_query(update.inline_query.id, [inline_result]) args = query.split(" ") args[len(args) - 1] = args[len(args)-1].replace(".", "") cmd = args[0][1:].lower() args.pop(0) args.append(f"{Keyword.INLINE}=true") plgn = None for plugin in self.plugins: if cmd in plugin.get_cmds(): if not plugin.inline_mode(): message = "Inline mode not supported" return _send(f"{emo.INFO} {message}") plgn = plugin break if not plgn: message = "Command not found" return _send(f"{emo.INFO} {message}") v = plgn.get_action(bot, update, args=args) if not v: message = "No message returned" return _send(f"{emo.ERROR} {message}") if not isinstance(v, str): message = "No *string* returned" return _send(f"{emo.ERROR} {message}") if v.startswith(emo.ERROR) or v.startswith(emo.INFO): return _send(v) _send(v, plgn.get_description()) # Handle all telegram and telegram.ext related errors
Example #10
Source File: osmbot.py From osmbot with GNU General Public License v3.0 | 4 votes |
def answer_inline(self, message, query, user_config): """ Answers the inline queryes :param message: User inline search :param query: Dict with the full query as a dict :param user_config: User configuration as a dict :return: None """ if not message: return None nom = pynominatim.Nominatim() is_rtl = user_config['lang'] in self.get_rtl_languages() search_results = nom.query(message, acceptlanguage=user_config['lang']) temp = self._get_template('inline_article.md') inline_query_id = query['inline_query']['id'] results = [] if search_results: for index, r in enumerate(search_results[:10]): element_type = '' if r.get('osm_type', '') == 'node': element_type = 'nod' elif r.get('osm_type', '') == 'way': element_type = 'way' elif r.get('osm_type', '') == 'relation': element_type = 'rel' osm_data = getData(r['osm_id'], geom_type=element_type) params = { 'data': osm_data, 'type': element_type, 'identifier': r['osm_id'], 'user_config': user_config, 'is_rtl': is_rtl, 'nominatim_data': r } if osm_data: text = temp.render(**params) name_lang = 'name:{}'.format(user_config['lang']) if name_lang in osm_data['tag']: results.append(InlineQueryResultArticle( id=uuid4(), title=osm_data['tag'][name_lang], description=r['display_name'], input_message_content=InputTextMessageContent( text, parse_mode=ParseMode.MARKDOWN))) else: results.append(InlineQueryResultArticle( id=uuid4(), title=osm_data['tag'].get('name',r['display_name']), description=r['display_name'], input_message_content=InputTextMessageContent( text, parse_mode=ParseMode.MARKDOWN))) self.telegram_api.answerInlineQuery( inline_query_id, results, is_personal=True, cache_time=86400)