mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-02-16 18:31:45 +01:00
Add Markdown support for sendMessage method.
This commit is contained in:
parent
17b8bb4881
commit
53c44f14bd
4 changed files with 39 additions and 1 deletions
|
@ -189,6 +189,10 @@ To post a text message::
|
|||
|
||||
>>> bot.sendMessage(chat_id=chat_id, text="I'm sorry Dave I'm afraid I can't do that.")
|
||||
|
||||
To post a text message with markdown::
|
||||
|
||||
>>> bot.sendMessage(chat_id=chat_id, text="*bold* _italic_ [link](http://google.com).", parse_mode=telegram.ParseMode.MARKDOWN)
|
||||
|
||||
To post an Emoji (special thanks to `Tim Whitlock <http://apps.timwhitlock.info/emoji/tables/unicode>`_)::
|
||||
|
||||
>>> bot.sendMessage(chat_id=chat_id, text=telegram.Emoji.PILE_OF_POO)
|
||||
|
|
|
@ -42,6 +42,7 @@ from .error import TelegramError
|
|||
from .inputfile import InputFile
|
||||
from .nullhandler import NullHandler
|
||||
from .emoji import Emoji
|
||||
from .parsemode import ParseMode
|
||||
from .message import Message
|
||||
from .update import Update
|
||||
from .bot import Bot
|
||||
|
@ -50,5 +51,5 @@ __all__ = ['Bot', 'Emoji', 'TelegramError', 'InputFile', 'ReplyMarkup',
|
|||
'ForceReply', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup',
|
||||
'UserProfilePhotos', 'ChatAction', 'Location', 'Contact',
|
||||
'Video', 'Sticker', 'Document', 'Audio', 'PhotoSize', 'GroupChat',
|
||||
'Update', 'Message', 'User', 'TelegramObject', 'NullHandler',
|
||||
'Update', 'ParseMode', 'Message', 'User', 'TelegramObject', 'NullHandler',
|
||||
'Voice']
|
||||
|
|
|
@ -181,6 +181,7 @@ class Bot(TelegramObject):
|
|||
def sendMessage(self,
|
||||
chat_id,
|
||||
text,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None,
|
||||
**kwargs):
|
||||
"""Use this method to send text messages.
|
||||
|
@ -189,6 +190,10 @@ class Bot(TelegramObject):
|
|||
chat_id:
|
||||
Unique identifier for the message recipient - telegram.User or
|
||||
telegram.GroupChat id.
|
||||
parse_mode:
|
||||
Send Markdown, if you want Telegram apps to show bold, italic and
|
||||
inline URLs in your bot's message. For the moment, only Telegram
|
||||
for Android supports this. [Optional]
|
||||
text:
|
||||
Text of the message to be sent.
|
||||
disable_web_page_preview:
|
||||
|
@ -209,6 +214,8 @@ class Bot(TelegramObject):
|
|||
data = {'chat_id': chat_id,
|
||||
'text': text}
|
||||
|
||||
if parse_mode:
|
||||
data['parse_mode'] = parse_mode
|
||||
if disable_web_page_preview:
|
||||
data['disable_web_page_preview'] = disable_web_page_preview
|
||||
|
||||
|
|
26
telegram/parsemode.py
Normal file
26
telegram/parsemode.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python
|
||||
# pylint: disable=R0903
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram Message Parse Modes"""
|
||||
|
||||
|
||||
class ParseMode(object):
|
||||
"""This object represents a Telegram Message Parse Modes."""
|
||||
|
||||
MARKDOWN = 'Markdown'
|
Loading…
Add table
Reference in a new issue